How to display a SOAP handler in a JAX-WS client

I am trying to implement a SOAP handler for a client. I am using Wildfly8.2 java8 and JAX-WS and Maven

I created a client interface class with eclipse from the WSDL endpoint

The handler-chain.xml file is placed in the same package as the client interface.

When I call the web service, it runs fine, but the handler is not called. If I put the brake point in the handler, it is never called

The client interface is as follows:

@WebService(targetNamespace = "********************", name = "WorkflowEditor")
@XmlSeeAlso({ ObjectFactory.class })
@HandlerChain(file = "handler-chain.xml")
public interface WorkflowEditor {

I also tried putting xml in resources and calling it in annotations with a url that I checked works, for example:

    @WebService(targetNamespace = "**************", name = "WorkflowEditor")
@XmlSeeAlso({ ObjectFactory.class })
@SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE)
@HandlerChain(file = "http://cloudflow-backend-local.arctur.net:8080/resources/handler-chain.xml")
public interface WorkflowEditor {

the handler looks like this:

package si.arctur.services.handlers;

import java.util.Set;

import javax.xml.namespace.QName;
import javax.xml.soap.SOAPMessage;
import javax.xml.ws.handler.MessageContext;
import javax.xml.ws.handler.soap.SOAPMessageContext;

public class PrintEnvelopeHandler implements javax.xml.ws.handler.soap.SOAPHandler<SOAPMessageContext> {

    @Override
    public boolean handleMessage(SOAPMessageContext context) {
        System.out.println("Client : handleMessage()......");
        SOAPMessage soapMessage = context.getMessage();
        return true;
    }

    @Override
    public boolean handleFault(SOAPMessageContext context) {
        System.out.println("Client : handleFault()......");
        return true;
    }

    @Override
    public void close(MessageContext context) {
        System.out.println("Client : close()......");
    }

    @Override
    public Set<QName> getHeaders() {
        // TODO Auto-generated method stub
        return null;
    }

}

and the handler-chain.xml file looks like this:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<javaee:handler-chains 
 xmlns:javaee="http://java.sun.com/xml/ns/javaee" 
 xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<javaee:handler-chain>
<javaee:handler>
  <javaee:handler-class>si.arctur.services.handlers.PrintEnvelopeHandler</javaee:handler-class>
</javaee:handler>
 </javaee:handler-chain>
+4
3

@HandlerChain ( @WebServiceClient), .

+4

( : , , . . .)

( ) -, . , API JAX-WS:

// 'sei' is assumed to be the service endpoint interface
BindingProvider bp = (BindingProvider) sei;

// Get the handler chain
List<Handler> handlerChain = bp.getBinding().getHandlerChain();

// Add your handler
handlerChain.add(myHandler);

// Re-set the handler chain (needed because getHandlerChain() returns
// a copy of the handlers' list.
bp.getBinding().setHandlerChain(handlerChain);
+2

, . , handler-chain.xml .

  • handler-chain.xml main/resources maven.

  • Alternatively, try specifying the full path to the file location folder in the annotation file attribute @HandlerChain.

0
source

All Articles