D A V I D M A D D I S O N
Using the Workshop Webservice Context

Introduction

By default when you create a Workshop Webservice (JWS file) it doesn't automatically expose a Context object, which is a shame because the WebService Context contains a lot of useful methods and callbacks. Here I show you how to add and use the JwsContext to add more power to your Workshop Webservices

Adding the Context Anotation

In order to get Workshop to populate a variable with the context object we need to use the @common:context anotation. The code below creates a context object called jwsCtx in the WebService. Be ware that you can only add one of these context objects to a WebService. Anymore and Workshop will give you it's green wiggly line warning!

    /**
     * @common:context
     */
    JwsContext jwsCtx;

Note:When you press ALT+ENTER to auto import this JwsContext class, it's important to choose com.bea.control.JwsContext. The weblogic.jws.control.JwsContext class has been deprecated.

Using the Context Methods

Once you've specified the context object, you can use it as you would any standard Java object. The Workshop runtime will populate it with context information regarding the current WebService invocation.

There are far to many methods included in this Context class to explain them all here, but some of the more useful ones are :

  • getLogger(): Returns a logger to which you can write straight to the disk log file
  • isCallerInRole(String roleName): Returns true if the authenticated principal is within specified role
  • getService(): Returns a ServiceHandle object which can be use to get extra information regarding the current WebService
  • getInputHeaders(): Returns an Array of Elements representing the SOAP headers which arrived with the current request
  • finishedConversation(): In conversational services, this method explicitly finishes the conversation. You can use this methods rather than set the @conversation phase="finish" on a particular method.

For a complete set of avaliable methods, please see http://e-docs.bea.com/workshop/docs81/doc/en/workshop/java-class/com/bea/control/JwsContext.html

Using the Context Callbacks

One of the special features of this context object is the ability to have it call your WebService implementation during it's lifetime. Implementations for callbacks are created using the special method naming convention of <CONTEXT_VARIABLE_NAME>_<CALLBACK_METHOD_NAME>. As an example, the following code shows how to execute code when the WebService object is first created:

    /**
     * @common:context
     */
    JwsContext jwsCtx;

    // This method will be called when the WebService is first created
    public void jwsCtx_onCreate() {
        
        // Just a test message but could possibly setup WebService state         
        System.out.println("Webservice Object has been Created!");
    }

There are many more context callbacks, all of which are described here: http://e-docs.bea.com/workshop/docs81/doc/en/workshop/java-class/com/bea/control/JwsContext.Callback.html

Deprecated Context Methods

The BEA documentaion is rather confusing with regards to context methods such as getCallbackURL. For these methods in JwsContext it states that they are deprecated and that you should use the ServiceControl, but of course it doesn't say how you can get an instance of this ServiceControl interface.

What the documentation is trying to say is that the Callback object in your WebService is now an instance of a ServiceControl, of course the callback object is only available if you have a callback method defined. Once you have a callback method defined you can access methods such as getEndPoint() using callback.getEndPoint().

This makes sense as a CallbackURL is only really valid should you have any callback methods defined. Futher information on the avaliable methods of the ServiceControl interface are available here http://e-docs.bea.com/workshop/docs81/doc/en/workshop/java-class/com/bea/control/ServiceControl.html


Comments:

Post a comment:
Name: *
email: *
url:
Comment
 
 
- BEA Weblogic Workshop
- ColdFusion
- Flex
- Other Stuff
 
- BEA Workshop
- FREE Workshop Licenses

- Macromedia Flex
- Macromedia ColdFusion

- UK CFUG Blog Aggregator