You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by hyjshanghai <hy...@gmail.com> on 2011/03/20 10:50:05 UTC

How to Get SOAP Response at the End of a Camel Route?

I have a camel route like this:


    
    


As is shown above, dummySerivceEndpoint is simply an entrance to accept SOAP
messages.

End processor invokes exchange.getOut().setBody(cxfPayload) to manually set
the response to be returned to the client, where cxfPayload's body contains
a W3C XML DOM object built from a file on the local disk.

To use the route, I send a SOAP message to dummySerivceEndpoint with the XML
sender plug-in of the Eclipse IDE. 

However, despite that exchange.out is set by endProcessor, I still get empty
body in the "Response text" control of the XML Sender. Why?

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

Re: How to Get SOAP Response at the End of a Camel Route?

Posted by William Tam <em...@gmail.com>.
If your processor is doing something like below, the only thing I can 
think of is PAYLOAD mode was not specified properly.  You can raise the 
log level to DEBUG or TRACE to see what is going on.

  public  void process(final  Exchange exchange)throws  Exception {
                     ...
                     CxfPayload<SoapHeader>  responsePayload =new  CxfPayload<SoapHeader>(null, outElements);
                     exchange.getOut().setBody(responsePayload);
                 }


On 03/20/2011 12:59 PM, Claus Ibsen wrote:
> On Sun, Mar 20, 2011 at 1:55 PM, hyjshanghai<hy...@gmail.com>  wrote:
>> I have a camel route like this (I removed the<  and>  symbols to prevent from
>> being filtered by Nabble):
>>
>> route
>> from uri="cxf:bean:dummySerivceEndpoint" /
>> process ref="endProcessor" /
>> /route
>>
>> As is shown above, dummySerivceEndpoint is simply an entrance to accept SOAP
>> messages. It is synchronous, and uses the PAYLOAD message format.
>>
>> End processor invokes exchange.getOut().setBody(cxfPayload) to manually set
>> the response to be returned to the client, where cxfPayload's body contains
>> a W3C XML DOM object built from a file on the local disk.
>>
>> To use the route, I send a SOAP message to dummySerivceEndpoint with the XML
>> sender plug-in of the Eclipse IDE.
>>
>> However, despite that exchange.out is set by endProcessor, I still get a
>> SOAP message with empty SOAP body in the "Response text" control of the XML
>> Sender. Why?
> Read this FAQ
> http://camel.apache.org/using-getin-or-getout-methods-on-exchange.html
>
>
> And post your code you do in the processor
>
>
>> --
>> View this message in context: http://camel.465427.n5.nabble.com/How-to-Get-SOAP-Response-from-the-Last-Camel-Processor-in-the-Route-tp4127850p4135591.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>
>
>

Re: How to Get SOAP Response at the End of a Camel Route?

Posted by Claus Ibsen <cl...@gmail.com>.
On Sun, Mar 20, 2011 at 1:55 PM, hyjshanghai <hy...@gmail.com> wrote:
> I have a camel route like this (I removed the < and > symbols to prevent from
> being filtered by Nabble):
>
> route
> from uri="cxf:bean:dummySerivceEndpoint" /
> process ref="endProcessor" /
> /route
>
> As is shown above, dummySerivceEndpoint is simply an entrance to accept SOAP
> messages. It is synchronous, and uses the PAYLOAD message format.
>
> End processor invokes exchange.getOut().setBody(cxfPayload) to manually set
> the response to be returned to the client, where cxfPayload's body contains
> a W3C XML DOM object built from a file on the local disk.
>
> To use the route, I send a SOAP message to dummySerivceEndpoint with the XML
> sender plug-in of the Eclipse IDE.
>
> However, despite that exchange.out is set by endProcessor, I still get a
> SOAP message with empty SOAP body in the "Response text" control of the XML
> Sender. Why?

Read this FAQ
http://camel.apache.org/using-getin-or-getout-methods-on-exchange.html


And post your code you do in the processor


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



-- 
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/

Re: How to Get SOAP Response at the End of a Camel Route?

Posted by hyjshanghai <hy...@gmail.com>.
I have a camel route like this (I removed the < and > symbols to prevent from
being filtered by Nabble):

route
from uri="cxf:bean:dummySerivceEndpoint" /
process ref="endProcessor" /
/route

As is shown above, dummySerivceEndpoint is simply an entrance to accept SOAP
messages. It is synchronous, and uses the PAYLOAD message format.

End processor invokes exchange.getOut().setBody(cxfPayload) to manually set
the response to be returned to the client, where cxfPayload's body contains
a W3C XML DOM object built from a file on the local disk.

To use the route, I send a SOAP message to dummySerivceEndpoint with the XML
sender plug-in of the Eclipse IDE. 

However, despite that exchange.out is set by endProcessor, I still get a
SOAP message with empty SOAP body in the "Response text" control of the XML
Sender. Why?

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

Re: How to Get SOAP Response at the End of a Camel Route?

Posted by hyjshanghai <hy...@gmail.com>.
What do you mean by the xml being deleted?

The XML text "" is visible by the URL of this post
http://camel.465427.n5.nabble.com/template/NamlServlet.jtp?macro=reply&node=4128666. 

It means a camel route starting with a CXF endpoint as the "from" node,
followed by a Camel processor which ends the route.

My question is why I can get a SOAP response only with an empty body?

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

Re: How to Get SOAP Response at the End of a Camel Route?

Posted by Christian Schneider <ch...@die-schneider.net>.
Hi,

your xml was deleted by Nabble. Please subscribe to the list by mail and 
send the question again.

Christian


Am 20.03.2011 10:50, schrieb hyjshanghai:
> I have a camel route like this:
>
>
>
>
>
>
> As is shown above, dummySerivceEndpoint is simply an entrance to accept SOAP
> messages.
>
> End processor invokes exchange.getOut().setBody(cxfPayload) to manually set
> the response to be returned to the client, where cxfPayload's body contains
> a W3C XML DOM object built from a file on the local disk.
>
> To use the route, I send a SOAP message to dummySerivceEndpoint with the XML
> sender plug-in of the Eclipse IDE.
>
> However, despite that exchange.out is set by endProcessor, I still get empty
> body in the "Response text" control of the XML Sender. Why?
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/How-to-Get-SOAP-Response-at-the-End-of-a-Camel-Route-tp4127850p4127850.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>

-- 
----
http://www.liquid-reality.de


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.

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

Posted by "Willem.Jiang" <wi...@gmail.com>.
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.