You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@servicemix.apache.org by alexcpn <al...@gmail.com> on 2010/09/15 12:47:30 UTC

Re: servicemix 3.3.2 and camel-core 2.2.0

I just printed out the body of the exchange in the camel aggregator and it is
returning null. I guess this is one reason why the xpath is not working.
Could this be a bug in camel 2.2 ?


Here are two snippets; one just printing the expected body as is , and the
second which routes it through the aggregator
-------------------------------------------------------------------------------------------------------
public class MyRouteBuilder extends RouteBuilder {

   public void configure() {
	System.out.println("In MyRouteBuilder------------------");
       	
	Namespaces ns = new Namespaces("p", "http://nsn.com/obs/mw/medfra/snmpbc")
       	.add("xsd", "http://www.w3.org/2001/XMLSchema");
		
from("jbi:service:http://servicemix.apache.org/test/camel-receiver")
   	.to("log:tutorial");  

--------------------------------------------------------------------------------------------------------------------
INFO  - AutoDeploymentService          - Directory: hotdeploy: Finished
installation of archive:  inmc-snmp-sa-1.0-SNAPSHOT.jar
INFO  - tutorial                       -
Exchange[BodyType:javax.xml.transform.stream.StreamSource,
 Body:<p:snmp-getResponse xmlns:p="http://nsn.com/obs/mw/medf
ra/snmpbc" xmlns:xsi="http://www.w3.org/2001/XMLSchema">
  <p:NE ipaddr="10.58.128.10"/>
  <p:get-response> 1.3.6.1.6.3.1.1.4.1.0
    <p:variable-bindings>
      <p:varBinding name="1.3.6.1.6.3.1.1.4.1.0">noSuchObject</p:varBinding>
     </p:variable-bindings>
  </p:get-response>
</p:snmp-getResponse>
--------------------------------------------------------------------------------------------------------------------

public class MyRouteBuilder extends RouteBuilder {
		
    public void configure() {
 	from("jbi:service:http://servicemix.apache.org/test/camel-receiver")
       	.aggregate(new MyAggregationStrategy()) //camel 2
    	//.aggregator(new MyAggregationStrategy()) //camel 1.6
    	.header("*")
    	//.xpath("string(/p:snmp-getResponse/p:NE/@ipaddr)",String.class, ns)
    	//.completedPredicate(header("completed").isEqualTo("true")) //camel
1.6
		.completionPredicate(header("completed").isEqualTo("true")) //camel 2
	
//.to("jbi:endpoint:http://servicemix.apache.org/test/file_sender_getbulk/endpoint"); 
// 3 
		.to("log:tutorial");  




---------------------------------------------------------------------------------------------------------
public class MyAggregationStrategy implements AggregationStrategy {

public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {


String oldBody = oldExchange.getIn().getBody(String.class);
String newBody = newIn.getBody(String.class);

System.out.println("---------------------------");
System.out.println("New Body "+newBody);
System.out.println("Old Body "+oldBody);
System.out.println("---------------------------");

String oldBody2 = oldExchange.getOut().getBody(String.class);
String newBody2 = newExchange.getOut().getBody(String.class);

System.out.println("---------------------------");
System.out.println("New Body Out "+newBody2);
System.out.println("Old Body  Out "+oldBody2);
System.out.println("---------------------------");

-------------------------------------------------------------------------------------
INFO  - AutoDeploymentService          - Directory: hotdeploy: Finis
tion of archive:  inmc-snmp-sa-1.0-SNAPSHOT.jar
Going in aggregate 123i4
Exception in Aggregator
java.lang.NullPointerException
Going in aggregate 123i4
---------------------------
New Body null
Old Body null
---------------------------
---------------------------
New Body Out null
Old Body  Out null
---------------------------
getIp - inXMLnull
Exception caught getIp java.lang.NullPointerException
Ip-->
Status-->
Exception in Aggregator
java.lang.NumberFormatException: For input string: ""

-- 
View this message in context: http://servicemix.396122.n5.nabble.com/servicemix-3-3-1-and-camel-core-2-3-0-tp1624310p2840430.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.

Re: servicemix 3.3.2 and camel-core 2.2.0

Posted by alexcpn <al...@gmail.com>.
I guess this is a bug in camel 2.2 .Is there any possibility that servicemix
takes the latest camel 2.4 ?
Since we have already released this I guess I will have to rewrite  the
aggregation logic in java directly

-- 
View this message in context: http://servicemix.396122.n5.nabble.com/servicemix-3-3-1-and-camel-core-2-3-0-tp1624310p2841629.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.

Re: servicemix 3.3.2 and camel-core 2.2.0

Posted by alexcpn <al...@gmail.com>.
I was never using getOut. I just put it in the test snippet. Sorry for the
confusion

The code snippet below

String oldBody = oldExchange.getIn().getBody(String.class);
String newBody = newIn.getBody(String.class);

that I had put was working flawlessly in  camel 1.6. I checked in
http://camel.apache.org/camel-200-release.html and could not find any change
in the Exchange class in camel 2.2. 

But now in camel 2,2 it is retuning null. Though everything else is same.
Am I missing something here ?

(File poller reading a xnl file and sending it to custom aggregator - (the
aggregation strategy is slightly complex)

Here is the route

from("jbi:service:http://servicemix.apache.org/test/camel-receiver")
       	.aggregate(new MyAggregationStrategy()) //camel 2
    	.header("*")
	.completionPredicate(header("completed").isEqualTo("true")) //camel 2
	.to("log:tutorial");  




-- 
View this message in context: http://servicemix.396122.n5.nabble.com/servicemix-3-3-1-and-camel-core-2-3-0-tp1624310p2840503.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.

Re: servicemix 3.3.2 and camel-core 2.2.0

Posted by Claus Ibsen <cl...@gmail.com>.
Read the java doc of the Exchange
You should use hasOut() to test if an OUT message has been set or not.

And make sure you only use IN when aggregating, its the easiest. Just
forget all about OUT, its only for advanced use cases and for certain
components.



On Wed, Sep 15, 2010 at 1:16 PM, alexcpn <al...@gmail.com> wrote:
>
> I am using getIn() method in the aggregation strategy; It is returning null ;
>
> So I just printed getOut() just to see whether it is null. This is also null
> (as expected).
>
> System.out.println("Going in aggregate 123i4");
> Message newIn = newExchange.getIn();
>
> String oldBody = oldExchange.getIn().getBody(String.class);
> String newBody = newIn.getBody(String.class);
>
> System.out.println("---------------------------");
> System.out.println("New Body "+newBody);
> System.out.println("Old Body "+oldBody);
> System.out.println("---------------------------");
> -----------------------------
> Output
>
>
> ---------------------------
> New Body null
> Old Body null
> ---------------------------
> --
> View this message in context: http://servicemix.396122.n5.nabble.com/servicemix-3-3-1-and-camel-core-2-3-0-tp1624310p2840452.html
> Sent from the ServiceMix - User mailing list archive at Nabble.com.
>



-- 
Claus Ibsen
Apache Camel Committer

Author of Camel in Action: http://www.manning.com/ibsen/
Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus

Re: servicemix 3.3.2 and camel-core 2.2.0

Posted by alexcpn <al...@gmail.com>.
I am using getIn() method in the aggregation strategy; It is returning null ; 

So I just printed getOut() just to see whether it is null. This is also null
(as expected). 

System.out.println("Going in aggregate 123i4");
Message newIn = newExchange.getIn();

String oldBody = oldExchange.getIn().getBody(String.class);
String newBody = newIn.getBody(String.class);

System.out.println("---------------------------");
System.out.println("New Body "+newBody);
System.out.println("Old Body "+oldBody);
System.out.println("---------------------------");
-----------------------------
Output


---------------------------
New Body null
Old Body null
---------------------------
-- 
View this message in context: http://servicemix.396122.n5.nabble.com/servicemix-3-3-1-and-camel-core-2-3-0-tp1624310p2840452.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.

Re: servicemix 3.3.2 and camel-core 2.2.0

Posted by Claus Ibsen <cl...@gmail.com>.
Use getIn() instead of getOut() in your AggregateStrategy class.


On Wed, Sep 15, 2010 at 12:47 PM, alexcpn <al...@gmail.com> wrote:
>
> I just printed out the body of the exchange in the camel aggregator and it is
> returning null. I guess this is one reason why the xpath is not working.
> Could this be a bug in camel 2.2 ?
>
>
> Here are two snippets; one just printing the expected body as is , and the
> second which routes it through the aggregator
> -------------------------------------------------------------------------------------------------------
> public class MyRouteBuilder extends RouteBuilder {
>
>   public void configure() {
>        System.out.println("In MyRouteBuilder------------------");
>
>        Namespaces ns = new Namespaces("p", "http://nsn.com/obs/mw/medfra/snmpbc")
>        .add("xsd", "http://www.w3.org/2001/XMLSchema");
>
> from("jbi:service:http://servicemix.apache.org/test/camel-receiver")
>        .to("log:tutorial");
>
> --------------------------------------------------------------------------------------------------------------------
> INFO  - AutoDeploymentService          - Directory: hotdeploy: Finished
> installation of archive:  inmc-snmp-sa-1.0-SNAPSHOT.jar
> INFO  - tutorial                       -
> Exchange[BodyType:javax.xml.transform.stream.StreamSource,
>  Body:<p:snmp-getResponse xmlns:p="http://nsn.com/obs/mw/medf
> ra/snmpbc" xmlns:xsi="http://www.w3.org/2001/XMLSchema">
>  <p:NE ipaddr="10.58.128.10"/>
>  <p:get-response> 1.3.6.1.6.3.1.1.4.1.0
>    <p:variable-bindings>
>      <p:varBinding name="1.3.6.1.6.3.1.1.4.1.0">noSuchObject</p:varBinding>
>     </p:variable-bindings>
>  </p:get-response>
> </p:snmp-getResponse>
> --------------------------------------------------------------------------------------------------------------------
>
> public class MyRouteBuilder extends RouteBuilder {
>
>    public void configure() {
>        from("jbi:service:http://servicemix.apache.org/test/camel-receiver")
>        .aggregate(new MyAggregationStrategy()) //camel 2
>        //.aggregator(new MyAggregationStrategy()) //camel 1.6
>        .header("*")
>        //.xpath("string(/p:snmp-getResponse/p:NE/@ipaddr)",String.class, ns)
>        //.completedPredicate(header("completed").isEqualTo("true")) //camel
> 1.6
>                .completionPredicate(header("completed").isEqualTo("true")) //camel 2
>
> //.to("jbi:endpoint:http://servicemix.apache.org/test/file_sender_getbulk/endpoint");
> // 3
>                .to("log:tutorial");
>
>
>
>
> ---------------------------------------------------------------------------------------------------------
> public class MyAggregationStrategy implements AggregationStrategy {
>
> public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
>
>
> String oldBody = oldExchange.getIn().getBody(String.class);
> String newBody = newIn.getBody(String.class);
>
> System.out.println("---------------------------");
> System.out.println("New Body "+newBody);
> System.out.println("Old Body "+oldBody);
> System.out.println("---------------------------");
>
> String oldBody2 = oldExchange.getOut().getBody(String.class);
> String newBody2 = newExchange.getOut().getBody(String.class);
>
> System.out.println("---------------------------");
> System.out.println("New Body Out "+newBody2);
> System.out.println("Old Body  Out "+oldBody2);
> System.out.println("---------------------------");
>
> -------------------------------------------------------------------------------------
> INFO  - AutoDeploymentService          - Directory: hotdeploy: Finis
> tion of archive:  inmc-snmp-sa-1.0-SNAPSHOT.jar
> Going in aggregate 123i4
> Exception in Aggregator
> java.lang.NullPointerException
> Going in aggregate 123i4
> ---------------------------
> New Body null
> Old Body null
> ---------------------------
> ---------------------------
> New Body Out null
> Old Body  Out null
> ---------------------------
> getIp - inXMLnull
> Exception caught getIp java.lang.NullPointerException
> Ip-->
> Status-->
> Exception in Aggregator
> java.lang.NumberFormatException: For input string: ""
>
> --
> View this message in context: http://servicemix.396122.n5.nabble.com/servicemix-3-3-1-and-camel-core-2-3-0-tp1624310p2840430.html
> Sent from the ServiceMix - User mailing list archive at Nabble.com.
>



-- 
Claus Ibsen
Apache Camel Committer

Author of Camel in Action: http://www.manning.com/ibsen/
Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus