You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by "Willem.Jiang" <wi...@gmail.com> on 2011/03/21 02:07:05 UTC

Re: How to Get SOAP Response from the Last Camel Processor in the Route?

Hi,

Which version of Camel are you using?
It could be helpful if you post your endProcessor code.

Willem


--
View this message in context: http://camel.465427.n5.nabble.com/How-to-Get-SOAP-Response-from-the-Last-Camel-Processor-in-the-Route-tp4127850p4165310.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: How to Get SOAP Response from the Last Camel Processor in the Route?

Posted by hyjshanghai <hy...@gmail.com>.
Just a quick reply.
For the time being, the organization I am in cannot access Camel 2.8. I can
use Camel 2.4 only.
I would appreciate if anyone in our forum can have a try with the latest
Camel:)

--
View this message in context: http://camel.465427.n5.nabble.com/How-to-Get-SOAP-Response-from-the-Last-Camel-Processor-in-the-Route-tp4127850p4270658.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: How to Get SOAP Response from the Last Camel Processor in the Route?

Posted by Willem Jiang <wi...@gmail.com>.
Hi,

Can you try the latest Camel 2.8-SNAPSHOT, I think this issue may relate 
to CAMEL-3792[1] which is fixed in Camel 2.8-SNAPSHOT.

[1]https://issues.apache.org/jira/browse/CAMEL-3792

Willem

On 3/30/11 9:46 AM, hyjshanghai wrote:
> I found the answer finally - returning SOAP response with empty body is
> caused by using the "try ... catch .. finally" camel DSL.
> I regret not having mentioned using this DSL in previous posts.
>
> According to my test, in the following, Route A returns a non-empty SOAP
> message to the client correctly; Route B will return a SOAP message with
> empty body, which is the wrong case I asked for help previously:
> (Note that I replaced the&lt; and&gt; symbols with parentheses.)
>
> Route A:
> 	(camel:camelContext id="camelContext")
> 	   (camel:route streamCache="true")
> 	      (camel:from uri="cxf:bean:serviceEndpoint" /)
> 	      (camel:process ref="dummyProcessor" /)
> 	      (camel:process ref="endProcessor" /)
> 	   (/camel:route)
> 	(/camel:camelContext)
>
> Route B:
> 	(camel:camelContext id="camelContext")
> 		(camel:route streamCache="true")
> 			(camel:from uri="cxf:bean:serviceEndpoint" /)
> 			(camel:doTry)
> 			    (camel:process ref="dummyProcessor" /)
> 				(camel:doCatch)
> 					(camel:exception)java.lang.Exception(/camel:exception)
> 					(camel:handled)
> 						(camel:constant)true(/camel:constant)
> 					(/camel:handled)
> 					(camel:process ref="errorProcessor" /)
> 				(/camel:doCatch)
> 				(camel:doFinally)
> 					(camel:process ref="endProcessor" /)
> 				(/camel:doFinally)
> 			(/camel:doTry)
> 		(/camel:route)
> 	(/camel:camelContext)
>
> In the above, dummyProcessor and errorProcessor have empty process() method;
> endProcessor set the response to client by
> exchange_.getOut().setBody(cxfPayload).
> Why Route B returns empty SOAP message while Route A does not?
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/How-to-Get-SOAP-Response-from-the-Last-Camel-Processor-in-the-Route-tp4127850p4270601.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>


-- 
Willem
----------------------------------
FuseSource
Web: http://www.fusesource.com
Blog:    http://willemjiang.blogspot.com (English)
          http://jnn.javaeye.com (Chinese)
Twitter: willemjiang

Re: How to Get SOAP Response from the Last Camel Processor in the Route?

Posted by hyjshanghai <hy...@gmail.com>.
I found the answer finally - returning SOAP response with empty body is
caused by using the "try ... catch .. finally" camel DSL.
I regret not having mentioned using this DSL in previous posts.

According to my test, in the following, Route A returns a non-empty SOAP
message to the client correctly; Route B will return a SOAP message with
empty body, which is the wrong case I asked for help previously:
(Note that I replaced the &lt; and &gt; symbols with parentheses.)

Route A:
	(camel:camelContext id="camelContext")
	   (camel:route streamCache="true")
	      (camel:from uri="cxf:bean:serviceEndpoint" /)
	      (camel:process ref="dummyProcessor" /)
	      (camel:process ref="endProcessor" /)
	   (/camel:route)
	(/camel:camelContext)

Route B:
	(camel:camelContext id="camelContext")
		(camel:route streamCache="true")
			(camel:from uri="cxf:bean:serviceEndpoint" /)
			(camel:doTry)
			    (camel:process ref="dummyProcessor" /)
				(camel:doCatch)
					(camel:exception)java.lang.Exception(/camel:exception)
					(camel:handled)
						(camel:constant)true(/camel:constant)
					(/camel:handled)
					(camel:process ref="errorProcessor" /)
				(/camel:doCatch)
				(camel:doFinally)
					(camel:process ref="endProcessor" /)
				(/camel:doFinally)
			(/camel:doTry)
		(/camel:route)
	(/camel:camelContext)

In the above, dummyProcessor and errorProcessor have empty process() method;
endProcessor set the response to client by 
exchange_.getOut().setBody(cxfPayload).
Why Route B returns empty SOAP message while Route A does not?

--
View this message in context: http://camel.465427.n5.nabble.com/How-to-Get-SOAP-Response-from-the-Last-Camel-Processor-in-the-Route-tp4127850p4270601.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: How to Get SOAP Response from the Last Camel Processor in the Route?

Posted by hyjshanghai <hy...@gmail.com>.
I also checked that MEP of the exchange object is set to InOut, before the
last processor returns.
Anyway, an empty SOAP message is received at last.

--
View this message in context: http://camel.465427.n5.nabble.com/How-to-Get-SOAP-Response-from-the-Last-Camel-Processor-in-the-Route-tp4127850p4266128.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: How to Get SOAP Response from the Last Camel Processor in the Route?

Posted by hyjshanghai <hy...@gmail.com>.
Here is Utils.toCxfPayload():
    
    @SuppressWarnings("unchecked")
    public static CxfPayload toCxfPayload(String text_) throws Exception
    {
        // Build w3c Document from text_.
        org.w3c.dom.Document w3cDocument = ... (text_);

        // Prepare header and element lists for Cxfpayload.
        List elements = new ArrayList();
        elements.add(w3cDocument.getDocumentElement());

        // Create Cxfpayload.
        CxfPayload payload = new CxfPayload(null, elements);
        return payload;
    }


As is shown in the log output of the previous post, I think the Cxfpayload
object is correctly constructed.


--
View this message in context: http://camel.465427.n5.nabble.com/How-to-Get-SOAP-Response-from-the-Last-Camel-Processor-in-the-Route-tp4127850p4171293.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: How to Get SOAP Response from the Last Camel Processor in the Route?

Posted by Willem Jiang <wi...@gmail.com>.
I'm not sure about the Utils.toCxfPayLoad doing.
Here is an example[1] that could help you out.

[1]https://svn.apache.org/repos/asf/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfConsumerPayloadTest.java

On 3/21/11 10:19 AM, hyjshanghai wrote:
> I made some corrections for the following text.
> I am using Camel 2.4.0. Below is the code of the end processor and the log
> output.
>
> public class EndProcessor implements Processor {
>      private static final Logger _LOGGER =
> LoggerFactory.getLogger(EndProcessor.class);
>
>      @Override
>      public void process(Exchange exchange_) throws Exception {
>
>          // I try to set both in and out messages.
>          exchange_.getIn().setBody(generateResponse(exchange_));
>          exchange_.getOut().setBody(generateResponse(exchange_));
> 		
> 	// Logging. The log output is shown below. Utility.exchange2String() simply
> prints the properties, in and out messages of an Exchange
> 	_LOGGER.debug("End proccessor. exchange: \nhas out: "+exchange_.hasOut()+"
> original pattern: " + exchange_.getPattern().name() + "\n" +
> Utility.exchange2String(exchange_));
> 		
>          return;
>      }
>
>      @SuppressWarnings("unchecked")
>      private static CxfPayload generateResponse(Exchange exchange_) throws
> Exception
>      {
>          String value = "&lt;Response&gt;hello&lt;/Response&gt;";
>
> 	// Build Cxfpayload object from XML in the way mentioned in the previous
> post.
>          return Utils.toCxfPayload(value);
>      }
> }
>
> The log output when executing the processor:
>
> 10:00:19.134 [33165064@qtp-12758948-0 - /SoapContext/SoapPort] DEBUG
> c.m.q.aaa.XX.YY - End proccessor. exchange:
> has out: true original pattern: InOut
> properties: {CamelToEndpoint=http:// ... ,
> RequestContext=org.apache.cxf.jaxws.context.WrappedMessageContext@10f9de8,
> org.apache.cxf.service.model.BindingOperationInfo=[BindingOperationInfo:
> {http:// ... }execute], CamelCXFDataFormat=PAYLOAD}
> in: Message: org.apache.camel.component.cxf.CxfPayload headers: nullbody: [
> [&lt;Response&gt;hello&lt;/Response&gt;]]
> out: Message: org.apache.camel.component.cxf.CxfPayload headers: nullbody: [
> [&lt;Response&gt;hello&lt;/Response&gt;]]
>
> Finally, I am poor to get only an empty body in the SOAP response displayed
> in the XML sender plug-in of Eclipse IDE...
>
>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/How-to-Get-SOAP-Response-from-the-Last-Camel-Processor-in-the-Route-tp4127850p4169731.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>


-- 
Willem
----------------------------------
FuseSource
Web: http://www.fusesource.com
Blog:    http://willemjiang.blogspot.com (English)
          http://jnn.javaeye.com (Chinese)
Twitter: willemjiang

Re: How to Get SOAP Response from the Last Camel Processor in the Route?

Posted by hyjshanghai <hy...@gmail.com>.
I made some corrections for the following text.
I am using Camel 2.4.0. Below is the code of the end processor and the log
output.

public class EndProcessor implements Processor {
    private static final Logger _LOGGER =
LoggerFactory.getLogger(EndProcessor.class);

    @Override
    public void process(Exchange exchange_) throws Exception {
        
        // I try to set both in and out messages.
        exchange_.getIn().setBody(generateResponse(exchange_));
        exchange_.getOut().setBody(generateResponse(exchange_));
		
	// Logging. The log output is shown below. Utility.exchange2String() simply
prints the properties, in and out messages of an Exchange
	_LOGGER.debug("End proccessor. exchange: \nhas out: "+exchange_.hasOut()+"
original pattern: " + exchange_.getPattern().name() + "\n" +
Utility.exchange2String(exchange_));
		
        return;
    }
    
    @SuppressWarnings("unchecked")
    private static CxfPayload generateResponse(Exchange exchange_) throws
Exception
    {
        String value = "&lt;Response&gt;hello&lt;/Response&gt;";
        
	// Build Cxfpayload object from XML in the way mentioned in the previous
post.
        return Utils.toCxfPayload(value);
    }
}

The log output when executing the processor:

10:00:19.134 [33165064@qtp-12758948-0 - /SoapContext/SoapPort] DEBUG
c.m.q.aaa.XX.YY - End proccessor. exchange: 
has out: true original pattern: InOut
properties: {CamelToEndpoint=http:// ... ,
RequestContext=org.apache.cxf.jaxws.context.WrappedMessageContext@10f9de8,
org.apache.cxf.service.model.BindingOperationInfo=[BindingOperationInfo:
{http:// ... }execute], CamelCXFDataFormat=PAYLOAD}
in: Message: org.apache.camel.component.cxf.CxfPayload headers: nullbody: [
[&lt;Response&gt;hello&lt;/Response&gt;]]
out: Message: org.apache.camel.component.cxf.CxfPayload headers: nullbody: [
[&lt;Response&gt;hello&lt;/Response&gt;]]

Finally, I am poor to get only an empty body in the SOAP response displayed
in the XML sender plug-in of Eclipse IDE...





--
View this message in context: http://camel.465427.n5.nabble.com/How-to-Get-SOAP-Response-from-the-Last-Camel-Processor-in-the-Route-tp4127850p4169731.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: How to Get SOAP Response from the Last Camel Processor in the Route?

Posted by hyjshanghai <hy...@gmail.com>.
I am using Camel 2.4.0. Below is the code of the end processor and the log
output.

public class EndProcessor implements Processor {
    private static final Logger _LOGGER =
LoggerFactory.getLogger(EndProcessor.class);

    @Override
    public void process(Exchange exchange_) throws Exception {
        
		// I try to set both in and out messages.
        exchange_.getIn().setBody(generateResponse(exchange_));
        exchange_.getOut().setBody(generateResponse(exchange_));
		
		// Logging. The log output is shown below. Utility.exchange2String()
simply prints the properties, in and out messages of an Exchange
		_LOGGER.debug("End proccessor. exchange: \nhas out: "+exchange_.hasOut()+"
original pattern: " + exchange_.getPattern().name() + "\n" +
Utility.exchange2String(exchange_));
		
        return;
    }
    
    @SuppressWarnings("unchecked")
    private static CxfPayload generateResponse(Exchange exchange_) throws
Exception
    {
        String value = hello";
        
	// Build Cxfpayload object from XML in the way mentioned in the previous
post.
        return Utils.toCxfPayload(value);
    }
}

The log output when executing the processor:

10:00:19.134 [33165064@qtp-12758948-0 - /SoapContext/SoapPort] DEBUG
c.m.q.aaa.XX.YY - End proccessor. exchange: 
has out: true original pattern: InOut
properties: {CamelToEndpoint=http:// ... ,
RequestContext=org.apache.cxf.jaxws.context.WrappedMessageContext@10f9de8,
org.apache.cxf.service.model.BindingOperationInfo=[BindingOperationInfo:
{http:// ... }execute], CamelCXFDataFormat=PAYLOAD}
in: Message: org.apache.camel.component.cxf.CxfPayload headers: nullbody: [
[hello]]
out: Message: org.apache.camel.component.cxf.CxfPayload headers: nullbody: [
[hello]]

Finally, I am poor to get only an empty body in the SOAP response displayed
in the XML sender plug-in of Eclipse IDE...

<?xml version="1.0" encoding="UTF-8"?>

  





--
View this message in context: http://camel.465427.n5.nabble.com/How-to-Get-SOAP-Response-from-the-Last-Camel-Processor-in-the-Route-tp4127850p4169389.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: How to Get SOAP Response from the Last Camel Processor in the Route?

Posted by hyjshanghai <hy...@gmail.com>.
Yes, that is exactly what I do in the end processor.

Build a W3C XML document object from an XML file.
Create a new CxfPayload object, with the element list containing the root
element of this document object.
exchange.getOut().setBody(the CxfPayload object).

I found the following log about operation info, where output size is "1".
Does it matter?
09:37:47.836 [20318304@qtp-17745616-0 - /SoapContext/SoapPort] DEBUG
o.a.c.j.i.HolderOutInterceptor - op: [OperationInfo:
{http://xml.ms.com/ns/com/company/lab}process]
09:37:47.836 [20318304@qtp-17745616-0 - /SoapContext/SoapPort] DEBUG
o.a.c.j.i.HolderOutInterceptor - op.hasOutput(): true
09:37:47.836 [20318304@qtp-17745616-0 - /SoapContext/SoapPort] DEBUG
o.a.c.j.i.HolderOutInterceptor - op.getOutput().size(): 1

--
View this message in context: http://camel.465427.n5.nabble.com/How-to-Get-SOAP-Response-from-the-Last-Camel-Processor-in-the-Route-tp4127850p4167701.html
Sent from the Camel - Users mailing list archive at Nabble.com.