JAX-WS handleMessage in SOAPHandler not called

I am trying to access SOAP request and responses from the client side so that I can calculate the execution time for each call. For this I have implemented SOAPHandler

, but the method is handleMessage

not called (no breakpoint is hit or no log is logged). I am using wsimport to create client side classes / stubs and also pass the binding file as a parameter to the wsimport command.

This is what I have done so far:

My binding file is handler-chain.xml

<jaxws:bindings
    xmlns:jaxws="http://java.sun.com/xml/ns/jaxws"
    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:jxb="http://java.sun.com/xml/ns/jaxb">
    <handler-chains xmlns="http://java.sun.com/xml/ns/javaee">
        <handler-chain>
            <handler>
                <handler-name>LoggingSOAPHandler</handler-name>
                <handler-class>com.handler.LoggingSOAPHandler</handler-class>
            </handler>
        </handler-chain>
    </handler-chains>    
</jaxws:bindings>

      

Wsimport command:

  <property name="package"       value="com.ws"/>
  <property name="src"           value="docroot/WEB-INF/src"/>
  <property name="classes"       value="docroot/WEB-INF/classes"/>
  <property name="bindingfile"   value="docroot/WEB-INF/src/com/handler/handler-chain.xml"/>
    <target name="wsimport">
        <exec executable="${jdk.home}/bin/wsimport">
          <arg line="-keep -s ${src} -p ${package} -d ${classes} -b ${bindingfile} ${wsdl}"/>
        </exec>
      </target>

      

When I run over the wsimport command, all stubs are created and the annotation is @HandlerChain

added to the stub service class as follows:

@WebServiceClient(name = "TestService", targetNamespace = "http://webservice.com/", wsdlLocation = "http://test:8290/TEST/services/test?wsdl")
@HandlerChain(file = "TestService_Service_handler.xml")
public class TestService_Service
    extends Service
{
    ...
}

      

Here is the generated TestService_Service_handler.xml:

<?xml version="1.0" encoding="UTF-8"?><handler-chains xmlns="http://java.sun.com/xml/ns/javaee">
  <handler-chain>
    <handler>
      <handler-name>LoggingSOAPHandler</handler-name>
      <handler-class>com.handler.LoggingSOAPHandler</handler-class>
    </handler>
  </handler-chain>
</handler-chains>

      

Here is mine SOAPHandler

:

public class LoggingSOAPHandler implements SOAPHandler<SOAPMessageContext> {

    private static Logger _logger = LoggerFactory.getLogger(LoggingSOAPHandler.class);

    @Override
    public boolean handleMessage(SOAPMessageContext messageContext) {

        Boolean outboundProperty = (Boolean) messageContext.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);

        if (outboundProperty.booleanValue()) {
            _logger.info("\nOutbound message:");
        } else {
            _logger.info("\nInbound message:");
        }
        return true;
    }

    @Override
    public boolean handleFault(SOAPMessageContext context) {
        _logger.info("Client : handleFault()......");
        return false;
    }

    @Override
    public void close(MessageContext context) {
        _logger.info("Client : close()......");

    }

    @Override
    public Set<QName> getHeaders() {
        _logger.info("Client : getHeaders()......");
        return null;
    }
}

      

When the web service is called, the handleMessage method is not called at all. Any idea?
I am using JAX-WS RI 2.2.4-b01 to create stubs.

+3


source to share


1 answer


A solution was found for this question, but in order to answer the question I have to provide more information about this project.

This project uses Spring MVC with JaxWsPortProxyFactoryBean to implement the JAX WS service interface.

Since the goal is for all SOAP calls to use the "LoggingSOAPHandler", then the "LoggingSOAPHandler" must be injected into the JaxWsPortProxyFactoryBean via the HandlerResolver. I created an implementation of HandlerResolver ....

CustomHandlerResolver:



public class CustomHandlerResolver implements HandlerResolver {


    /**
     * Overrode in order to load custom handlers.
     * @see javax.xml.ws.handler.HandlerResolver#getHandlerChain(javax.xml.ws.handler.PortInfo)
     */
    public List<Handler> getHandlerChain(PortInfo portInfo) {
        List<Handler> handlerChain = new ArrayList<Handler>();
        LoggingSOAPHandler hh = new LoggingSOAPHandler();
        handlerChain.add(hh);
        return handlerChain;
    }
}

      

I added the hanlderResolver bean and injected into the service xml config file:

        <beans xmlns="http://www.springframework.org/schema/beans"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xmlns:context="http://www.springframework.org/schema/context"
               xmlns:mvc="http://www.springframework.org/schema/mvc"
               xmlns:aop="http://www.springframework.org/schema/aop"       
               xmlns:tx="http://www.springframework.org/schema/tx" 
               xmlns:util="http://www.springframework.org/schema/util"   
               xsi:schemaLocation="http://www.springframework.org/schema/beans
               http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
               http://www.springframework.org/schema/context
               http://www.springframework.org/schema/context/spring-context-3.0.xsd
               http://www.springframework.org/schema/mvc
               http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
               http://www.springframework.org/schema/aop
               http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
               http://www.springframework.org/schema/tx
               http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
               http://www.springframework.org/schema/util 
               http://www.springframework.org/schema/util/spring-util-3.0.xsd">

              <!-- Use custom HandlerResolver that loads a list of custom SOAP handlers --> 
              <bean id="CustomHandlerResolver" class="com.ws.handler.CustomHandlerResolver"/>   

              <bean id="registrationService" class="org.springframework.remoting.jaxws.JaxWsPortProxyFactoryBean">
                 <property name="lookupServiceOnStartup" value="false" />  
                 <property name="serviceName"            value="TestService" />
                 <property name="serviceInterface"       value="com.ws.registration.TestService" />
                 <property name="wsdlDocumentUrl"        value="${registration.service}?wsdl" />
                 <property name="namespaceUri"           value="${registration.namespace}" />
                 <property name="endpointAddress"        value="${registration.service}" />
                 <property name="username"               value="${registration.username}"/>
                 <property name="password"               value="${registration.password}"/>
                 <property name="customProperties"       ref="jaxwsCustomProperties" />
                 <property name="handlerResolver"        ref="CustomHandlerResolver"/>
              </bean>

      .......    
    </beans>

      

So, since the handler handler is injected into the JaxWsPortProxyFactoryBean, the handlers specified in the CustomHandlerResolver class are injected at runtime.

+2


source







All Articles