How to define a global JAX-WS MessageHandler that intercepts all services in a transparent way?
Asked Answered
L

4

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?

Leucocytosis answered 14/10, 2011 at 12:17 Comment(6)
Started a bounty maybe some answers will appear.Tachymetry
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)?Kostman
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.Leucocytosis
If you use something like Spring JAX-WS support (JaxWsPortProxyFactoryBean) then you can try to inject @HandlerChain annotation programatically before passing the SEI interface to javax.xml.ws.Service#getPort().Dividivi
Wouldn't it be easier just to use filters in the web.xml? A bit like urlrewiter does.Halftone
when using Metro, try tube... https://mcmap.net/q/664878/-what-are-jax-ws-interceptors-also-known-as-handlersConoscenti
Y
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.

Yurikoyursa answered 20/9, 2012 at 13:24 Comment(0)
M
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.

Mikiso answered 24/10, 2011 at 13:41 Comment(4)
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.Leucocytosis
I cannot see how including at runtime is more flexible or less coupled than annotating each webservice class with @HandlerChain.Leucocytosis
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.Impressible
About the second part, well I misunderstood your comment, and I think you wanted to share one JAR across multiple WARs. @JoaquimOliveiraImpressible
L
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"

Laccolith answered 25/1, 2012 at 11:51 Comment(0)
A
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

Aqueous answered 25/11, 2014 at 14:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.