camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christian Müller <christian.muel...@gmail.com>
Subject Re: bizzarre situation with Jetty/routing
Date Sat, 22 Sep 2012 17:24:31 GMT
May be this FAQ entry helps:
http://camel.apache.org/using-getin-or-getout-methods-on-exchange.html

Best,
Christian

On Sat, Sep 22, 2012 at 7:16 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