camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Marco Mistroni <mmistr...@gmail.com>
Subject Re: bizzarre situation with Jetty/routing
Date Sat, 22 Sep 2012 18:13:40 GMT
Hello Raul
   i understand  , but in my <choice> i am routing basing on headers..... i
am not really  concerned with
body, only with headers.
I have now modified my processor


        exchange.getIn().setHeader("jsonHeader", action);
        exchange.getIn().setHeader("jsonContent", jsonData);
        exchange.getIn().setHeader("action", action);


still it's evading the jsonRouting for some reason

if instead going to the <choice> route i make it go straight to

<camel:route id="Jetty_Sample">
             <camel:from uri="jetty:http://localhost:8888/myJettyService"
               <!-- camel:marshal ref="jsonFormatter" /-->
             <camel:process ref="myJettyService" />
             <camel:to uri="seda:json" />
  </camel:route>

will try to debug more...

thanks for help

w/kindest regards
 marco


On Sat, Sep 22, 2012 at 6:25 PM, Raul Kripalani <raul@evosent.com> wrote:

> The processor is not transferring the original IN message body to the OUT
> message body, so the result is a Message with headers but with a null body.
>
> Take a look at [1] and you should be fine.
>
> I suggest you set the headers in the IN message, and Camel will take care
> of reusing the modified IN message for the next processor along.
>
> [1] http://camel.apache.org/using-getin-or-getout-methods-on-exchange.html
>
> Hope that helps,
> Raúl.
> On Sep 22, 2012 6:17 PM, "Marco Mistroni" <mmistroni@gmail.com> wrote:
>
> > Hi all
> >   i have a camel app in which i am using a jetty route to process json
> > messages. those messages are then routed to the proper route to produce a
> > response.
> > Here's the configuration
> >
> > <camel:route id="Jetty_Sample">
> >             <camel:from uri="jetty:http://localhost:8888/myJettyService"
> > />
> >             <!-- camel:marshal ref="jsonFormatter" /-->
> >             <camel:process ref="myJettyService" />
> >             <camel:to uri="seda:jsonRouting" />
> >
> >         </camel:route>
> >
> >         <camel:route id="jettyRouting">
> >             <camel:from uri="seda:jsonRouting" />
> >
> >             <camel:choice>
> >                 <camel:when>
> >                     <camel:simple>${in.headers[action]} ==
> > 'shareManagement'
> >                     </camel:simple>
> >                     <camel:to uri="seda:jsonShares" />
> >                 </camel:when>
> >                 ........
> >                 <camel:otherwise>
> >                     <camel:to uri="seda:json" />
> >                 </camel:otherwise>
> >             </camel:choice>
> >
> >         </camel:route>
> >
> >
> >         <camel:route>
> >             <camel:from uri="seda:json" />
> >             <camel:process ref="myJettyService2" />
> >             <camel:marshal ref="jsonFormatter" />
> >         </camel:route>
> >
> > There's a Processor which gets the input message, set few headers and the
> > pass the message through (myJettyService), whose code i sbelow
> >
> >     @Override
> >     public void process(Exchange exchange) throws Exception {
> >         // TODO Auto-generated method stub
> >
> >         ObjectMapper mapper = new ObjectMapper();
> >
> >         String body = exchange.getIn().getBody(String.class);
> >
> >         LOGGER.info("REceived:" + body);
> >         Map<String, Object> jsonData = mapper.readValue(body, Map.class);
> >         LOGGER.info("Setting new body to:" + jsonData);
> >
> >         String action = (String) jsonData.get("action");
> >
> >         LOGGER.info("Setting jsonHeader to:" + action);
> >
> >         exchange.getOut().setHeader("jsonHeader", action);
> >         exchange.getOut().setHeader("jsonContent", jsonData);
> >         exchange.getOut().setHeader("action", action);
> >
> >         LOGGER.info("Out of Processor" + action);
> >
> >
> >     }
> >
> > Now, as this processor sets the header 'action', then the <choice>
> > component of the destination route (jsonRouting) should pick the header
> up
> > and forward the message to the appropriate route.
> > If it cannot find hte header, the  <otherwise>  choice would be selected
> > and the message should end up somewhere (seda:json, route which contains
> a
> > processor)
> >
> > Now , for some reason . after hte above processor is invoked the message
> > end up nowhere (apparently, the message never arrives at the
> <camel:choice>
> > component).
> >
> > I have tried to put a <processor> after  <camel:from
> uri="seda:jsonRouting"
> > />, and i can see the  new headers (jsonHeader, jsonContent and action
> > being populated)
> >
> > If i skip the routing, replacing
> > <camel:route id="Jetty_Sample">
> >             <camel:from uri="jetty:http://localhost:8888/myJettyService"
> > />
> >             <!-- camel:marshal ref="jsonFormatter" /-->
> >             <camel:process ref="myJettyService" />
> >             <camel:to uri="seda:jsonRouting" />
> >
> >         </camel:route>
> > with
> > <camel:route id="Jetty_Sample">
> >             <camel:from uri="jetty:http://localhost:8888/myJettyService"
> > />
> >             <!-- camel:marshal ref="jsonFormatter" /-->
> >             <camel:process ref="myJettyService" />
> >             <camel:to uri="seda:json" />
> >
> >         </camel:route>
> >
> > the message gets processed correctly.
> >
> > I cannnot understand what's going on..... if none of the camel:choice
> > conditions are satisified the message should be routed to the
>  <otherwise>
> > route... But it does not
> >
> > Is it because i am using a processor (myJettyService) in the Jetty route?
> > does that screw up things because it is processing the message?
> >
> > thanks in advance and regards
> >  marco
> >
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message