[8.5.5.4 or later]
This topic applies to WebSphere Application Server Liberty V8.5.5.9 and earlier. For the latest Liberty topics, see the WebSphere Application Server Liberty documentation.

Adding web services global handlers

Components that need to register web services handlers to all the web services end points must implement the Handler interface and register that implementation in the service registry.

Before you begin

The global handler service is provided either by jaxws-2.2, jaxrs-1.1, Liberty Repository[8.5.5.6 or later]jaxrs-2.0, or jaxrs-2.0 client, so you must specify the following feature or feature combinations in your server.xml file:
  • jaxws-2.2
  • jaxrs-1.1
  • Liberty Repository[8.5.5.6 or later]jaxrs-2.0
  • Liberty Repository[8.5.5.6 or later]jaxrs-2.0 client
  • jaxws-2.2 and jaxrs-1.1
  • Liberty Repository[8.5.5.6 or later]jaxws-2.2 and jaxrs-2.0
  • Liberty Repository[8.5.5.6 or later]jaxws-2.2 and jaxrs-2.0 client

About this task

The Handler SPI provides different properties to specify the ENGINE_TYPE, the FLOW_TYPE, and the client side (IS_CLIENT_SIDE) or the server side (IS_SERVER_SIDE) where handlers take effect.

You must implement the Handler interface and register the implementation class into the service registry.

The Java API documentation for each Liberty SPI is available in a separate compressed file in one of the Javadoc subdirectories of the ${wlp.install.dir}/dev directory.

Deploying the handler bundle

You can deploy the handler bundle by using the WebSphere® Application Server Developer Tools for Eclipse .

Procedure

  1. Click File > New > Other and then expand OSGi.
  2. Click OSGi Bundle Project and click Next. The New OSGi Bundle Project window opens.
  3. Enter MyHandler as the Project name. In the Target runtime list, select WebSphere Application Server Liberty. If no runtime exists, click New Runtime to create a WebSphere(r) Application Server Liberty runtime.
  4. Clear the Add bundle to application ratio.
  5. Click Next twice and go to the OSGi Bundle page.
  6. On the  OSGi Bundle page, check Generate an activator, a Java class that controls the life cycle of the bundle. Leave the Activator name as myhandler.Activator and click Finish.
  7. Click Window > Preferences > Plug-in Development > Target Platform and select WebSphere Application Server Liberty with SPI.
    Note: Ensure that you have added WebSphere Application Server Liberty runtime in 3.
  8. Click Apply and click OK.
  9. Expand MyHandler > BundleContent > META-INF and open the MANIFEST.MF file by using the Plug-in Manifest Editor.
  10. Create the MyHander and MyActivitor classes:
    ...
    import com.ibm.wsspi.webservices.handler.Handler;
    ...
    
    public class MyHandler implements Handler {
        ...
        public void handleFault(GlobalHandlerMessageContext arg0) {
            ...
        }
        public void handleMessage(GlobalHandlerMessageContext msgctxt) throws Exception {
    
            if (msgctxt.getFlowType().equalsIgnoreCase(HandlerConstants.FLOW_TYPE_OUT)) {
                }
            ...
         }
         ....
    }
    public class MyActivator implements BundleActivator {
        ...
        public void start(BundleContext context) throws Exception {
    
              final Hashtable<String, Object> handlerProps = new Hashtable<String, Object>();
               handlerProps.put(HandlerConstants.ENGINE_TYPE, HandlerConstants.ENGINE_TYPE_JAXWS);
               handlerProps.put(HandlerConstants.FLOW_TYPE, HandlerConstants.FLOW_TYPE_IN);
               handlerProps.put(HandlerConstants.IS_CLIENT_SIDE, true);
               handlerProps.put(HandlerConstants.IS_SERVER_SIDE, true);
               handlerProps.put(org.osgi.framework.Constants.SERVICE_RANKING, 3);
               MyHandler myHandler = new MyHandler();
               context.registerService(Handler.class, myHandler, handlerProps);
               ...
            }
            ...
       }
  11. Click File > New > Other and then expand OSGi.
  12. Click Liberty Feature Project and then click Next. The Liberty Feature Project window opens.
  13. Specify MyHandlerFeature as the Project name.
  14. In the Target runtime list, select WebSphere Application Server Liberty and click Next. The OSGi Bundles Selection Page opens.
  15. On OSGi Bundles Selection Page, select MyHandler 1.0.0 as the Contained Bundles and click Finish.
  16. Modify Manifest:MyHandler in MyHandler project. Click the MANIFEST.MF tab and add com.ibm.wsspi.webservices.handler to the Import-pacakge element.
  17. Right-click the MyHandlerFeature project, click Install Feature to install the feature to Liberty runtime.
  18. Edit the server.xml file to enable the MyHandlerFeature:
    <featureManager> ......
    <feature>jsp-2.2</feature>
    <feature>jaxws-2.2</feature> // you can also use one of the following feature or feature combinations: jaxrs-1.1, jaxrs-2.0, jaxrsClient-2.0, 
    jaxws-2.2 and jaxrs-1.1, jaxws-2.2 and jaxrs-2.0, jaxws-2.2 and jaxrsClient-2.0
    <feature>usr:MyHandlerFeature</feature> ......
    </featureManager>

Icon that indicates the type of topic Task topic



Timestamp icon Last updated: Tuesday, 12 December 2017
http://www14.software.ibm.com/webapp/wsbroker/redirect?version=phil&product=was-libcore-mp&topic=twlp_web_services_global_handlers
File name: twlp_web_services_global_handlers.html