wt.httpgw
Class WTContextBean

java.lang.Object
  extended bywt.httpgw.WTContextBean

public class WTContextBean
extends Object

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, this bean should be instantiated with page, request, or session scope depending on the desired lifespan of the client context. Request scope will allow sharing between pages nested using actions. When using session scope, setting the "active" property to false at page completion is recommended to guarantee timely freeing of any resources that may remain assigned while it is the active context.

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:
WTContext

Nested Class Summary
(package private) static class WTContextBean.Finalizer
           
(package private) static class WTContextBean.ServerContextHelper
           
 
Field Summary
(package private)  MethodAuthenticator auth
           
private static Object BEAN_MARKER_KEY
           
private static int count
           
(package private)  WTContextBean.Finalizer finalizer
           
private static Vector livingBeans
           
private  boolean sessionEnabled
           
private  boolean sessionInitialized
           
(package private)  ThreadGroup threadGroup
           
private static boolean verbose
           
 
Constructor Summary
WTContextBean()
          Construct a Windchill client execution context (WTContext) bean.
 
Method Summary
private  void activate()
           
protected  void activateClientContext()
          Perform context activation when running remote from Windchill services.
protected  void activateServerContext()
          Perform context activation when running within a Windchill server.
private  void deactivate()
           
protected  void deactivateClientContext()
          Perform context deactivation when running remote from Windchill services.
private  void deactivateServerContext()
          Perform context deactivation when running within a Windchill server.
 void destroy()
          Destroy this bean and the corresonding WTContext.
private static void destroyDeadContexts()
           
protected  void finalize()
           
 MethodAuthenticator getAuthentication()
          Get the method authenticator currently in effect for this bean.
protected  void initClientContext()
          Perform default initialization when running remote from Windchill services.
protected  void initServerContext()
          Perform default initialization when running within a Windchill server.
static boolean isBeanContext(WTContext context)
          Test if a WTContext corresponds to a WTContextBean.
private static ThreadGroup nextThreadGroup()
           
 void setActive(boolean active)
          Activate the context associated with this bean.
 void setAuthentication(MethodAuthenticator auth)
          Set method authenticator for this bean.
 void setRequest(javax.servlet.http.HttpServletRequest request)
          Set the HTTP request property of this bean.
 void setSession(boolean session)
          Set whether or not calls originating from this context are associated with a persistent Windchill session.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BEAN_MARKER_KEY

private static final Object BEAN_MARKER_KEY

livingBeans

private static Vector livingBeans

count

private static int count

threadGroup

ThreadGroup threadGroup

finalizer

WTContextBean.Finalizer finalizer

auth

MethodAuthenticator auth

sessionEnabled

private boolean sessionEnabled

sessionInitialized

private boolean sessionInitialized

verbose

private static boolean verbose
Constructor Detail

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 Detail

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

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


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


isBeanContext

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

Supported API: true

Parameters:
context - the WTContext to check

nextThreadGroup

private static ThreadGroup nextThreadGroup()

activate

private void activate()

deactivate

private void deactivate()

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


deactivateServerContext

private void deactivateServerContext()
Perform context deactivation when running within a Windchill server. This implementation unregisters a MethodContext for the current thread if one is still registered.

Supported API: true


finalize

protected void finalize()

destroyDeadContexts

private static void destroyDeadContexts()