HOW TO convert SOAPMessage to POJO

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

HOW TO convert SOAPMessage to POJO

chaij
I use CXF endpoint in CXF_MESSAGE format. The incoming message body is type of SOAPMessage.

This request is wsdl first approach and I have access to all the wsdl2java generated classes. I wonder if there is an easy way to convert this message to POJO?
Camel must be doing it since that is behavior when CXF endpoint data format is POJO.

Now I need to do the same myself.

Thanks.
Reply | Threaded
Open this post in threaded view
|

Re: HOW TO convert SOAPMessage to POJO

dkulp@apache.org

On Mar 26, 2014, at 8:00 AM, chaij <[hidden email]> wrote:

> I use CXF endpoint in CXF_MESSAGE format. The incoming message body is type
> of SOAPMessage.
>
> This request is wsdl first approach and I have access to all the wsdl2java
> generated classes. I wonder if there is an easy way to convert this message
> to POJO?
> Camel must be doing it since that is behavior when CXF endpoint data format
> is POJO.

If you need the POJO’s, just use the CXF POJO mode.   CXF will then unmarshall the incoming data directly into the JAXB objects and avoid all the intermediary types which can consume extra memory and processing time and such.

If you NEED to use CXF_MESSAGE (and there shouldn’t be any reason to use CXF_MESSAGE), then you would need to do  something like an XPath to select the first element in the soap:Body element and then a convert using the JAXB data binding thing.   Something like:

DataFormat jaxb = new JaxbDataFormat("com.acme.model");
from (“cxf:….”)
   .filter().xpath(“//soap:Body/*”, new Namespaces(“soap”, “http://schemas.xmlsoap.org/wsdl/soap/”))
   .unmarshall(jaxb)
   .to(…….)


Like I said though, don’t do that unless there really is a big reason for it, which usually there is not.   Just let CXF do it’s job.


--
Daniel Kulp
[hidden email] - http://dankulp.com/blog
Talend Community Coder - http://coders.talend.com



Reply | Threaded
Open this post in threaded view
|

Re: HOW TO convert SOAPMessage to POJO

chaij
Dan -  Your response has been very helpful and concrete enough for me to follow through. Really appreciate. I am relatively new to Camel.. has a lot to learn.

I am facing the following issues when use CXF Endpoint POJO mode with WSS4J interceptors for security related processing.

Please see this post for more details.
http://camel.465427.n5.nabble.com/Camel-CXF-Proxy-with-WS-Security-td5749223i20.html

org.apache.cxf.binding.soap.SoapFault: An error was discovered processing the <wsse:Security> header
        at org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor.createSoapFault(WSS4JInInterceptor.java:788)[162:org.apache.cxf.cxf-rt-ws-security:2.7.7]
        at org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor.handleMessage(WSS4JInInterceptor.java:336)[162:org.apache.cxf.cxf-rt-ws-security:2.7.7]
        at org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor.handleMessage(WSS4JInInterceptor.java:95)[162:org.apache.cxf.cxf-rt-ws-security:2.7.7]
        at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:272)[122:org.apache.cxf.cxf-api:2.7.7]
        at org.apache.cxf.endpoint.ClientImpl.onMessage(ClientImpl.java:817)[122:org.apache.cxf.cxf-api:2.7.7]
        at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponseInternal(HTTPConduit.java:1606)[130:org.apache.cxf.cxf-rt-transports-http:2.7.7]
        at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream$1.run(HTTPConduit.java:1128)[130:org.apache.cxf.cxf-rt-transports-http:2.7.7]
        at org.apache.cxf.workqueue.AutomaticWorkQueueImpl$3.run(AutomaticWorkQueueImpl.java:428)[122:org.apache.cxf.cxf-api:2.7.7]
        at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)[:1.6.0_29]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)[:1.6.0_29]
        at org.apache.cxf.workqueue.AutomaticWorkQueueImpl$AWQThreadFactory$1.run(AutomaticWorkQueueImpl.java:353)[122:org.apache.cxf.cxf-api:2.7.7]
        at java.lang.Thread.run(Thread.java:662)[:1.6.0_29]
Caused by: org.apache.ws.security.WSSecurityException: An error was discovered processing the <wsse:Security> header
        at org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor.checkActions(WSS4JInInterceptor.java:363)[162:org.apache.cxf.cxf-rt-ws-security:2.7.7]
        at org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor.handleMessage(WSS4JInInterceptor.java:319)[162:org.apache.cxf.cxf-rt-ws-security:2.7.7]
        ... 10 more
Reply | Threaded
Open this post in threaded view
|

Re: HOW TO convert SOAPMessage to POJO

dkulp@apache.org

You would need to capture the SOAP message (wireshark or use the logging interceptors) and double check that the SOAP message matches what you have configured for the WSS4JInInterceptor.

Another suggestion is to subclass the WSS4JInInterceptor and override the method:

protected boolean checkReceiverResultsAnyOrder(
        List<WSSecurityEngineResult> wsResult, List<Integer> actions
    )

to print out information about the actions in the wsResult list there to see what was actually processed compared to the actions that were configured.   Here’s the full code for the method as it is now:


    protected boolean checkReceiverResultsAnyOrder(
        List<WSSecurityEngineResult> wsResult, List<Integer> actions
    ) {
        List<Integer> recordedActions = new ArrayList<Integer>(actions.size());
        for (Integer action : actions) {
            recordedActions.add(action);
        }
       
        for (WSSecurityEngineResult result : wsResult) {
            final Integer actInt = (Integer) result.get(WSSecurityEngineResult.TAG_ACTION);
            int act = actInt.intValue();
            if (act == WSConstants.SC || act == WSConstants.BST) {
                continue;
            }
           
            if (!recordedActions.remove(actInt)) {
                return false;
            }
        }

        if (!recordedActions.isEmpty()) {
            return false;
        }

        return true;
    }



Dan





On Mar 26, 2014, at 4:29 PM, chaij <[hidden email]> wrote:

> Dan -  Your response has been very helpful and concrete enough for me to
> follow through. Really appreciate. I am relatively new to Camel.. has a lot
> to learn.
>
> I am facing the following issues when use CXF Endpoint POJO mode with WSS4J
> interceptors for security related processing.
>
> Please see this post for more details.
> http://camel.465427.n5.nabble.com/Camel-CXF-Proxy-with-WS-Security-td5749223i20.html
>
> org.apache.cxf.binding.soap.SoapFault: An error was discovered processing
> the <wsse:Security> header
>        at
> org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor.createSoapFault(WSS4JInInterceptor.java:788)[162:org.apache.cxf.cxf-rt-ws-security:2.7.7]
>        at
> org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor.handleMessage(WSS4JInInterceptor.java:336)[162:org.apache.cxf.cxf-rt-ws-security:2.7.7]
>        at
> org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor.handleMessage(WSS4JInInterceptor.java:95)[162:org.apache.cxf.cxf-rt-ws-security:2.7.7]
>        at
> org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:272)[122:org.apache.cxf.cxf-api:2.7.7]
>        at
> org.apache.cxf.endpoint.ClientImpl.onMessage(ClientImpl.java:817)[122:org.apache.cxf.cxf-api:2.7.7]
>        at
> org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponseInternal(HTTPConduit.java:1606)[130:org.apache.cxf.cxf-rt-transports-http:2.7.7]
>        at
> org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream$1.run(HTTPConduit.java:1128)[130:org.apache.cxf.cxf-rt-transports-http:2.7.7]
>        at
> org.apache.cxf.workqueue.AutomaticWorkQueueImpl$3.run(AutomaticWorkQueueImpl.java:428)[122:org.apache.cxf.cxf-api:2.7.7]
>        at
> java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)[:1.6.0_29]
>        at
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)[:1.6.0_29]
>        at
> org.apache.cxf.workqueue.AutomaticWorkQueueImpl$AWQThreadFactory$1.run(AutomaticWorkQueueImpl.java:353)[122:org.apache.cxf.cxf-api:2.7.7]
>        at java.lang.Thread.run(Thread.java:662)[:1.6.0_29]
> Caused by: org.apache.ws.security.WSSecurityException: An error was
> discovered processing the <wsse:Security> header
>        at
> org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor.checkActions(WSS4JInInterceptor.java:363)[162:org.apache.cxf.cxf-rt-ws-security:2.7.7]
>        at
> org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor.handleMessage(WSS4JInInterceptor.java:319)[162:org.apache.cxf.cxf-rt-ws-security:2.7.7]
>        ... 10 more
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/HOW-TO-convert-SOAPMessage-to-POJO-tp5749392p5749400.html
> Sent from the Camel - Users mailing list archive at Nabble.com.

--
Daniel Kulp
[hidden email] - http://dankulp.com/blog
Talend Community Coder - http://coders.talend.com