Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to imlement a SOAP handler in JAX-WS client

I'm triing to implement a SOAP Handler to a client. I'm using Wildfly8.2 java8 and JAX-WS and Maven

I have generated the client interface class with eclipse from the endpoint WSDL

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

When I call the web service it executes ok but the handler is not invoked. If I put a brake point in the handler it is never invoked

the client interface is like this:

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

I have tried also to put the xml in resources and call it in the annotation with the url I verified is working 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 is 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 is 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>
like image 544
simonC Avatar asked Aug 27 '15 17:08

simonC


1 Answers

(NOTE: The guide specified by other answers here is flawed. It asks you to edit an automatically-generated file. This never ends well.)

There is (currently) no standard way to attach a handler chain to a Web Service client using annotations only. To add handlers, you'll need to use the JAX-WS API:

// '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);
like image 106
Isaac Avatar answered Sep 28 '22 18:09

Isaac