Package wt.httpgw

Class WTContextBeanHandler

java.lang.Object
wt.httpgw.WTContextBeanHandler

public final class WTContextBeanHandler extends Object
This class sets up a WTContext and/or MethodContext in its constructors if these are not already available for the given thread and then undoes any setup it did in its destroy() method. This is intended to ensure an appropriate environment for calling Windchill APIs from any server-side process with minimal bother and without possible side-effects when a WTContext and/or MethodContext already exist for the given thread. Note that a WTContext and MethodContext are already made available within servlet request threads, within RMI calls to MethodServer.invoke(wt.method.MethodArgs), and within Windchill queue entry execution so this is only necessary when calling Windchill APIs from other threads.

WTContextBean is used wherever possible and direct use of WTContext and MethodContext is used for other cases.

Simple sample usage:

    final WTContextBeanHandler  handler = new WTContextBeanHandler();
    try
    {
      // call Windchill APIs
    }
    finally
    {
      handler.destroy();
    }
  

To associate any error or exception that arises within the try block with the underlying MethodContext and its logging the following usage pattern should be used instead.

    Throwable  throwable = null;
    final WTContextBeanHandler  handler = new WTContextBeanHandler();
    try
    {
      // call Windchill APIs
    }
    catch ( Throwable t )
    {
      throwable = t;
      throw t;  // rethrow whatever we caught
    }
    finally
    {
      handler.destroy( throwable );
    }
  


Supported API: true

Extendable: false
  • Constructor Summary

    Constructors
    Constructor
    Description
    Construct a WTContextBeanHandler without explicitly providing a servlet request.
    WTContextBeanHandler(javax.servlet.http.HttpServletRequest httpServletRequest)
    Construct a WTContextBeanHandler explicitly providing a servlet request.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Deprecated.
    void
    destroy(Throwable throwable)
    Destroy any contexts that we created locally.
    Note that this method can return null if we already had an associated WTContext and did not already have an associated WTContextBean.
    static <T> T
    runOperation(javax.servlet.http.HttpServletRequest httpServletRequest, Callable<T> operation)
    Utility to simply and properly wrap a Callable with a WTContextBeanHandler.
    static <T> T
    runOperation(javax.servlet.http.HttpServletRequest httpServletRequest, Callable<T> operation, boolean associateExceptionWithContext)
    Utility to simply and properly wrap a Callable with a WTContextBeanHandler.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • WTContextBeanHandler

      public WTContextBeanHandler()
      Construct a WTContextBeanHandler without explicitly providing a servlet request. If a servlet request has been associated with this thread via ServletState, then this will be used otherwise it is assumed there is no associated servlet request.

      Supported API: true
    • WTContextBeanHandler

      public WTContextBeanHandler(javax.servlet.http.HttpServletRequest httpServletRequest)
      Construct a WTContextBeanHandler explicitly providing a servlet request. If null is passed, then if a servlet request has been associated with this thread via ServletState it will be used -- otherwise it is assumed there is no associated servlet request.

      Supported API: true
  • Method Details

    • getWTContextBean

      public WTContextBean getWTContextBean()
      Note that this method can return null if we already had an associated WTContext and did not already have an associated WTContextBean.

      Supported API: true
    • destroy

      @Deprecated public void destroy()
      Deprecated.
      Destroy any contexts that we created locally.

      Supported API: true
      See Also:
    • destroy

      public void destroy(Throwable throwable)
      Destroy any contexts that we created locally. If there is an underlying MethodContext and it was created by this WTContextBeanHandler, then that Throwable will be set on the MethodContext via setException() so as to indicate that an exception arose during this context. If the underlying MethodContext was not created by this WTContextBeanHandler, then it is assumed that the creator of the MethodContext will capture and apply the appropriate Throwable.

      Supported API: true
      Parameters:
      throwable - Throwable generated by thread since WTContextBeanHandler construction; null if no Throwable was encountered
    • runOperation

      public static <T> T runOperation(javax.servlet.http.HttpServletRequest httpServletRequest, Callable<T> operation) throws Exception
      Utility to simply and properly wrap a Callable with a WTContextBeanHandler. Calls runOperation(javax.servlet.http.HttpServletRequest, java.util.concurrent.Callable, boolean) with a last argument of true.

      Supported API: true
      Throws:
      Exception
    • runOperation

      public static <T> T runOperation(javax.servlet.http.HttpServletRequest httpServletRequest, Callable<T> operation, boolean associateExceptionWithContext) throws Exception
      Utility to simply and properly wrap a Callable with a WTContextBeanHandler.

      Supported API: true
      Throws:
      Exception