20

We have a set of web services implemented in JAX-WS and a SOAPHandler that adds control attributes in the SOAP headers. Today, we need to add the @HandlerChain annotation in every new service we create.

The idea is that new services implementors do not need to know that a @HandlerChain exists.

Is there a way to configure a global Handler that intercepts all services running in my WAR?

Joaquim Oliveira
  • 1,208
  • 2
  • 16
  • 29
  • 1
    Started a bounty maybe some answers will appear. – lpinto.eu Oct 17 '11 at 09:50
  • Do you have a handler within your WAR? or do you want this across WARs or? I'm just wondering your functionality. My thoughts though are why not put the handler on an interface that your web service interface extends (or on an abstract class that your service extends)? – Chris Aldrich Oct 21 '11 at 19:59
  • Chris, the idea is to share the handler functionality across WARs, to avoid code duplication. So, the main goal (but we don't know if it's possible) is to distribute this handler in a JAR, that should be added to each WAR's WEB-INF/lib dir or maybe to the final EAR. – Joaquim Oliveira Oct 24 '11 at 12:02
  • If you use something like Spring JAX-WS support (`JaxWsPortProxyFactoryBean`) then you can try to [inject `@HandlerChain` annotation programatically](http://stackoverflow.com/questions/7957195/how-to-use-jaxb-annotations-at-runtime/7958207#7958207) before passing the SEI interface to `javax.xml.ws.Service#getPort()`. – dma_k Nov 14 '11 at 19:15
  • when using Metro, try tube... https://stackoverflow.com/a/45005485/1005652 – comeGetSome Jul 10 '17 at 06:56
  • Wouldn't it be easier just to use filters in the web.xml? A bit like [urlrewiter](http://tuckey.org/urlrewrite/) does. – Nik Corthaut Sep 20 '12 at 13:15

4 Answers4

1

One option that might work is aspectj. With bytecode weaving (or in conjunction with spring if you'd like) you can create a single handler as an aspect and weave into all classes (and WAR files as well) through maven plugin perhaps. I haven't tried this myself I guess the only challenge would be getting a handle on the SOAP header from the aspect.

ramsinb
  • 1,985
  • 12
  • 17
0

At least with JBoss AS and Wildfly you can configure pre- and post- handler chains in endpoint config. E.g. Wildfly 8.1.0.Final's standalone.xml has the following configured by default:

<subsystem xmlns="urn:jboss:domain:webservices:1.2">
    <wsdl-host>${jboss.bind.address:127.0.0.1}</wsdl-host>
    <endpoint-config name="Standard-Endpoint-Config"/>
    <endpoint-config name="Recording-Endpoint-Config">
        <pre-handler-chain name="recording-handlers" protocol-bindings="##SOAP11_HTTP ##SOAP11_HTTP_MTOM ##SOAP12_HTTP ##SOAP12_HTTP_MTOM">
            <handler name="RecordingHandler" class="org.jboss.ws.common.invocation.RecordingServerHandler"/>
        </pre-handler-chain>
    </endpoint-config>
    <client-config name="Standard-Client-Config"/>
</subsystem>

Predefined client and endpoint configurations

Vsevolod Golovanov
  • 4,068
  • 3
  • 31
  • 65
0

I think that there's no strait forward way to do that. But joining the previews comments, maybe you can create a jar with all your handlers, and then in each war project, define one abstract class with the chain that you want, and inherit it in your services. OR Instead of including the WAR, try look at JNDI to make the include in runtime.

  • João, defining an abstract class annotated only with `@HandlerChain` does not work. The handler is not called. If I annotate the abstract class with both `@HandlerChain` and `@Webservice`, a deploy error occurs, saying that my `FooService` class that extends the abstract one cannot be cast to `javax.servlet.Servlet`. – Joaquim Oliveira Oct 26 '11 at 20:33
  • I cannot see how including at runtime is more flexible or less coupled than annotating each webservice class with `@HandlerChain`. – Joaquim Oliveira Oct 26 '11 at 20:35
  • Hi, sorry for the delay to answer. About the abstract classes, you are right they don't work, at the moment I answer the question it made sense that work and I don't test it, so for that sorry. – João Pires Nov 07 '11 at 20:22
  • About the second part, well I misunderstood your comment, and I think you wanted to share one JAR across multiple WARs. @JoaquimOliveira – João Pires Nov 07 '11 at 20:36
0

I use Spring as Web Service Factory Bean and defined parent bean following:

 <bean id="parentWebService" abstract="true" class="org.jvnet.jax_ws_commons.spring.SpringService">
        <property name="handlers">
            <list>
                <bean class="com.tosan.sipa.framework.webservice.handler.AuthenticationHandler"/>
            </list>
        </property>
   </bean>

and in define new service we only set parent of new service to "parentWebService"

Sam
  • 6,770
  • 7
  • 50
  • 91