SOAP Message Handlers Quick Reference for Java EE 6 Web Services Certification Exam 1z0-897

SOAP message handlers enable Web Services and clients to perform additional processing on the SOAP message request or response, by intercepting the SOAP message in both the request and response of the Web Service. 

 

SOAP handlers and logical handlers

  • JAX-WS supports two types of SOAP message handlers:

    • SOAP handlers

      • SOAP handlers can access the entire SOAP message, including the message headers and body.

    • Logical handlers

      • Logical handlers can access the payload of the message only, and cannot change any protocol-specific information (like headers) in a message.

  • SOAPHandlers in the order specified in configuration are executed first and then the LogicalHandlers specified in the order get executed.

 

Configuring SOAP Handlers

  • Java EE container does not automatically processes the handlers packaged in the application and configures it on the applicable endpoint, you will need to configure using one of the available ways.

  • Handlers can be configured for:

    • endpoints configured with @WebService

    • endpoints configured with @WebServiceProvider

    • endpoints in the deployment descriptor (webservices.xml)

  • In bottom up web service development, Handlers can be configured using @HandlerChain annotation on endpoints configured with @WebService or wit.h @WebServiceProvider.

    • E.g. @HandlerChain(file="handler-chain.xml")

    • The file attribute is used to specify an external file that contains the configuration of the handler chain.

      • The external handler chain configuration file contains configuration information for the handler chain such as the list of handlers in the handler chain, the order in which they execute, the initialization parameters, and so on.

    • It is an error to specify more than one @HandlerChain annotation in a single Java file.

  • In top down web service development, handler chain configuration can be done through WSDL customizations.

    • A <handlerChains> element is added to the customization file.

    • Multiple handler-chain elements may exist within the handler-chains element.

      • These may optionally use a service name, port name, or protocol pattern in their description to apply some chains to certain ports and protocols only, through the use of <service-name-pattern> element.

 

Configuring handlers on a Web Service client

We can configuring handlers on a Web Service client in one of the following ways:

  • Create a handlerchain as list of handlers and call setHandlerChain() with that list on the Binding object.

  • Programmatically configure the handlers by setting a custom HandlerResolver on the service instance and create proxies from that service.

  • Specify handlers in handler chain configuration XML file and add @HandlerChain referencing handler configuration file to the Web Service references for clients running in JavaEE Container.

 

Examples

Example (part)  - configuring handlers as annotations (provider-side)

@WebService(name = "Handler", targetNamespace = "http://javajee.com")

@HandlerChain(file="handler-chain.xml")

 

Example (part)  - configuring handlers as wsdl customization bindings (provider-side)

<bindings xmlns="http://java.sun.com/xml/ns/jaxws">
  <handler-chains xmlns="http://java.sun.com/xml/ns/javaee">
    <handler-chain>
      <handler>
        <handler-class>com.javajee.ws.TestHandler</handler-class>
      </handler>
    </handler-chain>
  </handler-chains>
</bindings>

 

Example (part) - <service-name-pattern> element (provider-side)

<handler-chains xmlns="http://java.sun.com/xml/ns/javaee">
    <handler-chain>
      <service-name-pattern xmlns:ns1="http://javajee.com/handlers">ns1:Hello*</service-name-pattern>
      <handler>...</handler>
    </handler-chain>
...
</handler-chains>

Here, the <service-name-pattern> element applies the handlers in the specified in the <handler-chain> element to the service whose name begins with Hello and targetNamespace is http://javajee.com/handlers.

Search the Web

Custom Search

Searches whole web. Use the search in the right sidebar to search only within javajee.com!!!