cxf-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Freeman Fang <freeman.f...@gmail.com>
Subject Re: CXF Spring client: getting the message´s XML payload
Date Wed, 16 Apr 2008 12:47:38 GMT
Hi Juanjo,

I think you have several options
option1. You can write an Interceptor which should be invoked after 
receive xml stream from the underlying transport, take a look at 
LoggingInInterceptor,  your interceptor could be very similar with it.
the key part in the interceptor looks like

public YourInterceptor() {
        super(Phase.RECEIVE);
}
public void handleMessage(Message message) throws Fault {
    InputStream is = message.getContent(InputStream.class);
        if (is != null) {
            CachedOutputStream bos = new CachedOutputStream();
            try {
                IOUtils.copy(is, bos);

                bos.flush();// you get the soap xml now
                is.close();

                message.setContent(InputStream.class, 
bos.getInputStream());// don't forget to write inputstream back, the 
inputstream is still needed for next invoked interceptors
     }
}

and add
<jaxws:inInterceptors>
      <bean class="package.YourInterceptor"/>
</jaxws:inInterceptors>
to your spring configuration

option2.
add a jaxws soap protocol handler for your client to process the 
incoming soap messge, so that you can get the raw xml
In your code, you can get the injected client proxy, so you can add 
handler programmatically
        YourHandler sh = new YourHandler();
        List<Handler> newHandlerChain = new ArrayList<Handler>();
        newHandlerChain.add(sh);
        
((BindingProvider)dummyServiceClient).getBinding().setHandlerChain(newHandlerChain);
And key part of YourHandler looks like
public class YourHandler implements SOAPHandler<SOAPMessageContext> {

    public boolean handleMessage(SOAPMessageContext smc) {
        if ((Boolean)smc.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY)) {
               //igore client outgoing message
               return true;
        }
        System.out.println("YourHandler : handleMessage Called....");

        try {
            // get soap message
            SOAPMessageContext soapContext = (SOAPMessageContext)smc;
            SOAPMessage soapMessage = soapContext.getMessage();// now 
you get the soapMessage so you can dump the soap payload from saaj api

Option 3.
You can use jaxws disptach client to work with raw xml directly, but 
this way need no client proxy so it seems big difference with your 
current code base. more details please see the jaxws_dispatch_provider 
sample in kit

Regards

Freeman

Juan José Vázquez Delgado wrote:
> Hi all,
>
> I have a CXF Spring client with the next application-context configuration
> file:
>
> <?xml version="1.0" encoding="UTF-8"?>
>
> <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:jaxws="http://cxf.apache.org/jaxws"
>     xsi:schemaLocation="http://www.springframework.org/schema/beans
> http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
>                         http://www.springframework.org/schema/context
> http://www.springframework.org/schema/context/spring-context-2.5.xsd
>                            http://cxf.apache.org/jaxws
> http://cxf.apache.org/schemas/jaxws.xsd">
>
>     <context:annotation-config />
>
>     <jaxws:client id="dummyServiceClient"
>         serviceClass="services.DummyService"
>         address="http://localhost:9090/DummyService"
>         serviceName="s:DummyService" endpointName="e:DummyServicePort"
>         xmlns:s="http://services.es/" xmlns:e="http://services.es/">
>         <jaxws:features>
>             <bean class="org.apache.cxf.feature.LoggingFeature" />
>         </jaxws:features>
>     </jaxws:client>
>
> </beans>
>
> This bean is injected in other beans as usual:
>
> public class DummyServiceTest extends
> AbstractDependencyInjectionSpringContextTests {
>
>     @Autowired
>     @Qualifier("services.dummyServiceClient")
>     private DummyService dummyServiceClient;
>
>     @Override
>     protected String[] getConfigLocations() {
>         return new String[] {
>
> "classpath:spring/config/application-context-wsclient-test.xml"};
>     }
>
>     @SuppressWarnings("unchecked")
>     public void testDummyService () {
>         String greetings = dummyServiceClient.getGreetings();
>     }
> }
>
> This woks for me perfectly, but now, I need to get the response´s raw XML
> (soap message´s payload) before the binding. How could I do this?. Any ideas
> or comments are welcome.
>
> Thanks in advance,
>
> Juanjo.
>
>   


Mime
View raw message