Package wt.httpgw

Class WTContextBean

java.lang.Object
wt.httpgw.WTContextBean
All Implemented Interfaces:
Serializable

public final class WTContextBean extends Object implements Serializable
A JavaBean for use in Java Server Pages or Servlets that wish to use Windchill Java client or server APIs. Each instance of the bean corresponds to a unique WTContext. Windchill APIs use WTContext to maintain implicit contextual information about a client, such as authentication credentials or locale. Windchill APIs have access to this state implicitly based on thread group mappings maintained by the WTcontext class. This bean is a convienience wrapper to encapsulate management of multiple contexts within a single JVM.

When used in JSPs and servlets, this bean should be instantiated with request scope. Instantiation of a WTContextBean should be unnecessary within JSPs and servlets within the Windchill web application, however, as WTContextBeanFilter is already applied to all requests there (except a few where this is known to be unnecessary).

Although an explicit destroy method exists, contexts associated with unreferenced beans will automatically be destroyed as a result of garbage collection.

To be effective, some property of the bean must be set within a thread prior to calling Windchill APIs that should execute under the bean's implicit context. Setting a property allows the bean instance to activate its context in the current thread. Typically, this will be the "request" property. The calling thread's association to the bean's context remains in effect until explicitly undone through calls to the WTContext class or by constructing or setting properties on a different WTContextBean instance.

NOTE: Including or forwarding requests to Windchill gateway URLs will disassociate the bean's context from the calling thread. It can be reactivated upon return from an include by setting the "active" property.

Example request scope usage:

 <jsp:useBean id="wtcontext" class="wt.httpgw.WTContextBean" scope="request"/>
 <jsp:setProperty name="wtcontext" property="request" value="<%=request%>"/>
 
When the containing JVM also hosts Windchill services, the server-side execution context, a MethodContext, is also established for the current thread. Therefore, this bean can be used in the same servlet JVM that hosts both HTTPGatewayServlet and WTServlet.

NOTE: When a page is invoked via forwarding through the HTTPGatewayServlet or WTServlet servlets, it is not necessary for to use WTContextBean objects. These servlets establish the necessary execution environment before dispatching forwarded requests.

Example forwarding Windchill URL:

 http://windchill.acme.com/WindchillAuthGW/forward/mypage.jsp
 

Supported API: true
Extendable: true
See Also:
  • Constructor Details

    • WTContextBean

      public WTContextBean()
      Construct a Windchill client execution context (WTContext) bean. A unique WTContext object will be associated to this bean and the current thread, but the execution context is not fully initialized until one of the beans properties is set (e.g. request or active).

      The new WTContext defaults certain characteristics to those appropriate for contexts running in a shared middle-tier (multi-user) server. These include private authentication and server affinity, and disallowing user interaction to perform authentication with remote Windchill servers.

      Supported API: true

  • Method Details

    • initClientContext

      protected void initClientContext()
      Perform default initialization when running remote from Windchill services. This implementation sets private authentication and server affinity and disallows user interaction to perform Windchill authentication.

      Supported API: true
    • initServerContext

      protected void initServerContext()
      Perform default initialization when running within a Windchill server. This implementation does nothing.

      Supported API: true
    • destroy

      public void destroy()
      Destroy this bean and the corresonding WTContext. This method is used to explicitly free resources associated with this context. If not destroyed, the resources may not be freed until some time after the bean is garbage collected.

      Supported API: true
    • setRequest

      public void setRequest(javax.servlet.http.HttpServletRequest request)
      Set the HTTP request property of this bean. The context associated with this bean will become the active context for the current thread and be initialized based on HTTP request properties. This property must be set on beans used in Java Server Pages (JSP) or Servlets to establish Windchill user authentication based on the current request's HTTP authentication. Other initialization includes setting the locale of the corresponding WTContext based on the Accept-Language HTTP header of this request.

      Supported API: true
      Parameters:
      request - HTTP servlet request
    • setExceptionIfUnset

      public void setExceptionIfUnset(Throwable throwable)
      If this is a server-side context and the argument is non-null, this will associate it with the underlying method context (via MethodContext.setExceptionIfUnset(java.lang.Throwable)), thus causing the method context's logic to log the given exception upon the context's termination.

      Supported API: true
      Parameters:
      throwable - Throwable to associate with underlying context
    • setActive

      public void setActive(boolean active)
      Activate the context associated with this bean. The context associated with this bean will become the active context for the current thread. This property can be set in order to re-activate an existing bean.

      Supported API: true
      Parameters:
      active - true to activate, false to deactivate
    • setAuthentication

      public void setAuthentication(MethodAuthenticator auth)
      Set method authenticator for this bean. The context associated with this bean will become the active context for the current thread and the given authenticator will be used for subsequent user authentication. When the bean is in a client, this authenticator will be used as-is to endorse outgoing calls to the default Windchill method server. When the bean is in a Windchill server, this authenticator will be bootstrapped through a call to wt.auth.AuthenticationServer.init.

      Supported API: true
      Parameters:
      auth - method authenticator
    • getAuthentication

      public MethodAuthenticator getAuthentication()
      Get the method authenticator currently in effect for this bean.

      Supported API: true
      Parameters:
      auth - method authenticator
    • setSession

      public void setSession(boolean session)
      Set whether or not calls originating from this context are associated with a persistent Windchill session. By default, calls are associated with transient sessions that exist only for the duration of each call. If this property is set to true, then the next authenticator set for this context via setRequest or setAuthentication will be initialized via its init method to bootstrap a persistent session. Once a session is established, subsequent calls to setRequest will be ignored.

      Supported API: true
      Parameters:
      auth - method authenticator
    • isBeanContext

      public static boolean isBeanContext(WTContext context)
      Test if a WTContext corresponds to a WTContextBean.

      Supported API: true
      Parameters:
      context - the WTContext to check
    • activateClientContext

      protected void activateClientContext()
      Perform context activation when running remote from Windchill services. This implementation makes this bean's method authenticator the current authenticator for calls originating from this context to the default method server.

      Supported API: true
    • deactivateClientContext

      protected void deactivateClientContext()
      Perform context deactivation when running remote from Windchill services. This implementation does nothing.

      Supported API: true
    • activateServerContext

      protected void activateServerContext()
      Perform context activation when running within a Windchill server. This implementation registers a MethodContext for the current thread and bootstraps the beans method authenticator.

      Supported API: true