|
Hi,
I have a l spring bean that which may/may not rreturn a null value. <bean ref="beanX" method="process" /> The trace output when a null is return includes: ... BodyType:null, Body:null Can I configure a spring syntax choice to see if the body is null? I have tried various checkis with simple, but the ${body} !=null is always true. <choice> <whien> <simple>${body} != null</simple> <log message="body not null: ${body}"/> </when> <otherwise> <log message="body null" /> <otherwise> <choice> Thanks |
|
Which version of Camel are you using?
I just add a simple unit test in Camel trunk , the test is passed. Here is the code snippet: public void testNullValue() throws Exception { exchange.getIn().setBody("Value"); assertExpression("${in.body} != null", true); assertExpression("${body} == null", false); exchange.getIn().setBody(null); assertExpression("${in.body} == null", true); assertExpression("${body} != null", false); } Willem On 3/24/11 5:13 AM, Eric East wrote: > Hi, > > I have a l spring bean that which may/may not rreturn a null value. > > > The trace output when a null is return includes: > ... BodyType:null, Body:null > > Can I configure a spring syntax choice to see if the body is null? > > I have tried various checkis with simple, but the ${body} !=null is always > true. > > > > ${body} != null > > > > > > > > Thanks > > -- > View this message in context: http://camel.465427.n5.nabble.com/choice-when-check-BodyType-null-Body-null-tp4259599p4259599.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 |
|
Thanks for response.
I narrowed down my test case where I see the issue. When I initiate a route using a jms activeMQ broker (internal VM), the exchange.setBody(null) does not set the body to null. I am using Camel 2.5. Actvemq 5.4.1 TEST CASE FAILS: template.sendBody("activemqVM:topic:tlm", SomeObject); from("activemqVM:topic:tlm").to("direct:one") TEST CASE WORKS: template.sendBody("direct:one", SomeObject); ROUTE from("direct:one") .log("processing ${in.body}") .process(new Processor(){ public void process(Exchange exchange)throws Exception{ exchange.getIn().setBody(null); } }) .log("new body: [${in.body}]") .choice() .when().simple("${in.body} != null") .log(" != null") .otherwise() .log(" == null"); --Eric |
|
I believe you ran into https://issues.apache.org/jira/browse/CAMEL-3354
On Thu, Mar 24, 2011 at 5:23 PM, Eric East <[hidden email]> wrote: > Thanks for response. > > I narrowed down my test case where I see the issue. > > When I initiate a route using a jms activeMQ broker (internal VM), the > exchange.setBody(null) does not set the body to null. > > I am using Camel 2.5. Actvemq 5.4.1 > > > TEST CASE FAILS: > template.sendBody("activemqVM:topic:tlm", SomeObject); > from("activemqVM:topic:tlm").to("direct:one") > > TEST CASE WORKS: > template.sendBody("direct:one", SomeObject); > > > ROUTE > from("direct:one") > .log("processing ${in.body}") > .process(new Processor(){ > public void process(Exchange exchange)throws Exception{ > exchange.getIn().setBody(null); > } > }) > .log("new body: [${in.body}]") > .choice() > .when().simple("${in.body} != null") > .log(" != null") > .otherwise() > .log(" == null"); > > --Eric > > > > -- > View this message in context: http://camel.465427.n5.nabble.com/choice-when-check-BodyType-null-Body-null-tp4259599p4263203.html > Sent from the Camel - Users mailing list archive at Nabble.com. > |
|
so based on the cause of that bug, it is impossible to set the body of
a jms message to null even if it was transformed earlier. So for example if you had: jmsmessage (a) -> bean which returns (b) based on that message -> bean c which returned null based on b -> bean d.. d would get (a) again. (note that it doesn't even get b which was after a). On Thu, Mar 24, 2011 at 9:38 PM, Tim <[hidden email]> wrote: > I believe you ran into https://issues.apache.org/jira/browse/CAMEL-3354 > > On Thu, Mar 24, 2011 at 5:23 PM, Eric East <[hidden email]> wrote: >> Thanks for response. >> >> I narrowed down my test case where I see the issue. >> >> When I initiate a route using a jms activeMQ broker (internal VM), the >> exchange.setBody(null) does not set the body to null. >> >> I am using Camel 2.5. Actvemq 5.4.1 >> >> >> TEST CASE FAILS: >> template.sendBody("activemqVM:topic:tlm", SomeObject); >> from("activemqVM:topic:tlm").to("direct:one") >> >> TEST CASE WORKS: >> template.sendBody("direct:one", SomeObject); >> >> >> ROUTE >> from("direct:one") >> .log("processing ${in.body}") >> .process(new Processor(){ >> public void process(Exchange exchange)throws Exception{ >> exchange.getIn().setBody(null); >> } >> }) >> .log("new body: [${in.body}]") >> .choice() >> .when().simple("${in.body} != null") >> .log(" != null") >> .otherwise() >> .log(" == null"); >> >> --Eric >> >> >> >> -- >> View this message in context: http://camel.465427.n5.nabble.com/choice-when-check-BodyType-null-Body-null-tp4259599p4263203.html >> Sent from the Camel - Users mailing list archive at Nabble.com. >> > |
|
On Fri, Mar 25, 2011 at 3:42 AM, Tim <[hidden email]> wrote:
> so based on the cause of that bug, it is impossible to set the body of > a jms message to null even if it was transformed earlier. > So for example if you had: > Its not a bug, thats how it was designed. Its very unusual to route null messages. You should most likely be able to do a exchange.setIn(new DefaultMessage()); Or something like that to work around your issue. > jmsmessage (a) -> bean which returns (b) based on that message -> bean > c which returned null based on b -> bean d.. d would get (a) again. > (note that it doesn't even get b which was after a). > > On Thu, Mar 24, 2011 at 9:38 PM, Tim <[hidden email]> wrote: >> I believe you ran into https://issues.apache.org/jira/browse/CAMEL-3354 >> >> On Thu, Mar 24, 2011 at 5:23 PM, Eric East <[hidden email]> wrote: >>> Thanks for response. >>> >>> I narrowed down my test case where I see the issue. >>> >>> When I initiate a route using a jms activeMQ broker (internal VM), the >>> exchange.setBody(null) does not set the body to null. >>> >>> I am using Camel 2.5. Actvemq 5.4.1 >>> >>> >>> TEST CASE FAILS: >>> template.sendBody("activemqVM:topic:tlm", SomeObject); >>> from("activemqVM:topic:tlm").to("direct:one") >>> >>> TEST CASE WORKS: >>> template.sendBody("direct:one", SomeObject); >>> >>> >>> ROUTE >>> from("direct:one") >>> .log("processing ${in.body}") >>> .process(new Processor(){ >>> public void process(Exchange exchange)throws Exception{ >>> exchange.getIn().setBody(null); >>> } >>> }) >>> .log("new body: [${in.body}]") >>> .choice() >>> .when().simple("${in.body} != null") >>> .log(" != null") >>> .otherwise() >>> .log(" == null"); >>> >>> --Eric >>> >>> >>> >>> -- >>> View this message in context: http://camel.465427.n5.nabble.com/choice-when-check-BodyType-null-Body-null-tp4259599p4263203.html >>> Sent from the Camel - Users mailing list archive at Nabble.com. >>> >> > -- Claus Ibsen ----------------- FuseSource Email: [hidden email] Web: http://fusesource.com Twitter: davsclaus Blog: http://davsclaus.blogspot.com/ Author of Camel in Action: http://www.manning.com/ibsen/ |
|
On Fri, Mar 25, 2011 at 11:44 AM, Claus Ibsen <[hidden email]> wrote:
> On Fri, Mar 25, 2011 at 3:42 AM, Tim <[hidden email]> wrote: >> so based on the cause of that bug, it is impossible to set the body of >> a jms message to null even if it was transformed earlier. >> So for example if you had: >> > > Its not a bug, thats how it was designed. > Its very unusual to route null messages. > > You should most likely be able to do a > exchange.setIn(new DefaultMessage()); > > Or something like that to work around your issue. > I was a bit vague here when referring to not a bug, which was the CAMEL-3554 I was referring to. Indeed the JmsMessage would re-initialize the underlying JMS message if you set the message body to null. As it would think it wasn't initialized. So I have created a ticket to track that https://issues.apache.org/jira/browse/CAMEL-3805 > > > >> jmsmessage (a) -> bean which returns (b) based on that message -> bean >> c which returned null based on b -> bean d.. d would get (a) again. >> (note that it doesn't even get b which was after a). >> >> On Thu, Mar 24, 2011 at 9:38 PM, Tim <[hidden email]> wrote: >>> I believe you ran into https://issues.apache.org/jira/browse/CAMEL-3354 >>> >>> On Thu, Mar 24, 2011 at 5:23 PM, Eric East <[hidden email]> wrote: >>>> Thanks for response. >>>> >>>> I narrowed down my test case where I see the issue. >>>> >>>> When I initiate a route using a jms activeMQ broker (internal VM), the >>>> exchange.setBody(null) does not set the body to null. >>>> >>>> I am using Camel 2.5. Actvemq 5.4.1 >>>> >>>> >>>> TEST CASE FAILS: >>>> template.sendBody("activemqVM:topic:tlm", SomeObject); >>>> from("activemqVM:topic:tlm").to("direct:one") >>>> >>>> TEST CASE WORKS: >>>> template.sendBody("direct:one", SomeObject); >>>> >>>> >>>> ROUTE >>>> from("direct:one") >>>> .log("processing ${in.body}") >>>> .process(new Processor(){ >>>> public void process(Exchange exchange)throws Exception{ >>>> exchange.getIn().setBody(null); >>>> } >>>> }) >>>> .log("new body: [${in.body}]") >>>> .choice() >>>> .when().simple("${in.body} != null") >>>> .log(" != null") >>>> .otherwise() >>>> .log(" == null"); >>>> >>>> --Eric >>>> >>>> >>>> >>>> -- >>>> View this message in context: http://camel.465427.n5.nabble.com/choice-when-check-BodyType-null-Body-null-tp4259599p4263203.html >>>> Sent from the Camel - Users mailing list archive at Nabble.com. >>>> >>> >> > > > > -- > Claus Ibsen > ----------------- > FuseSource > Email: [hidden email] > Web: http://fusesource.com > Twitter: davsclaus > Blog: http://davsclaus.blogspot.com/ > Author of Camel in Action: http://www.manning.com/ibsen/ > -- Claus Ibsen ----------------- FuseSource Email: [hidden email] Web: http://fusesource.com Twitter: davsclaus Blog: http://davsclaus.blogspot.com/ Author of Camel in Action: http://www.manning.com/ibsen/ |
|
Thanks for confirming issue. I thought it may be in my environment/test cases.
|
|
On Fri, Mar 25, 2011 at 4:12 PM, Eric East <[hidden email]> wrote:
> Thanks for confirming issue. I thought it may be in my environment/test > cases. You can use .setBody(constant(null)) in the DSL which works properly. > > > > > > -- > View this message in context: http://camel.465427.n5.nabble.com/choice-when-check-BodyType-null-Body-null-tp4259599p4264301.html > Sent from the Camel - Users mailing list archive at Nabble.com. > -- Claus Ibsen ----------------- FuseSource Email: [hidden email] Web: http://fusesource.com Twitter: davsclaus Blog: http://davsclaus.blogspot.com/ Author of Camel in Action: http://www.manning.com/ibsen/ |
|
Hi, I am trying to modify the contents of a file using a Camel processor in a Camel component that I created.
When I do the routing from one file to another using my component, it works. However, when trying to modify the contents of the file using the processor and putting the modified text in the second file, it doesn't work, it says the contents are null. See the code below: public class ComponentStub extends DefaultComponent { public Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception { FileComponent fileComp = new FileComponent(); fileComp.setCamelContext(this.getCamelContext()); Collection<Endpoint> endpointCol = fileComp.getCamelContext().getEndpoints(); Iterator endpointIt = endpointCol.iterator(); endpointIt.next(); endpointIt.next(); endpointIt.next(); Endpoint e4 = (Endpoint)endpointIt.next(); Exchange inExchange = e4.createExchange(); final Processor myProcessor = new Processor() { public void process(Exchange exchange) throws Exception { String body = (String) exchange.getIn().getBody(); System.out.println(exchange); System.out.println(exchange.getFromEndpoint()); } } myProcessor.process(inExchange); FileEndpoint outEndPt = (FileEndpoint) fileComp.createEndpoint(uri); return outEndPt; } } Output: Exchange[Message: [Body is null]] Endpoint[file:///home/tnedelescu/workspace/CurrentMavenProject/src/alogatr/src/data/input/Component?noop=true] |
|
I think the problem is caused by this line:
Exchange inExchange = e4.createExchange(); createExchange() creates a new exchange which is null, and what I want is to get the message contents from the endpoint e4, and then modify them. How could I do that ? |
|
In reply to this post by Tereza Nedelescu
I've never implemented a component myself, but I think you should
override the PollingConsumer implementation of your file component if you want your component to be able to manipulate the exchange's contents. In your code your are simply creating a new blank exchange (which by default has no body), then passing it to a processor which will print its contents. Are you sure you need a component to do that? Manipulating contents can be easily done by plugging a custom processor in your route. Mirko On Tue, Aug 9, 2011 at 8:25 PM, Tereza Nedelescu <[hidden email]> wrote: > Hi, I am trying to modify the contents of a file using a Camel processor in a > Camel component that I created. > When I do the routing from one file to another using my component, it works. > However, when trying to modify the contents of the file using the processor > and putting the modified text in the second file, it doesn't work, it says > the contents are null. See the code below: > > public class ComponentStub extends DefaultComponent { > public Endpoint createEndpoint(String uri, String remaining, > Map<String, Object> parameters) throws Exception { > FileComponent fileComp = new FileComponent(); > fileComp.setCamelContext(this.getCamelContext()); > Collection<Endpoint> endpointCol = > fileComp.getCamelContext().getEndpoints(); > Iterator endpointIt = endpointCol.iterator(); endpointIt.next(); > endpointIt.next(); endpointIt.next(); > Endpoint e4 = (Endpoint)endpointIt.next(); > > Exchange inExchange = e4.createExchange(); > final Processor myProcessor = new Processor() { > public void process(Exchange exchange) throws Exception { > String body = (String) exchange.getIn().getBody(); > System.out.println(exchange); > > System.out.println(exchange.getFromEndpoint()); > } > } > myProcessor.process(inExchange); > > FileEndpoint outEndPt = (FileEndpoint) > fileComp.createEndpoint(uri); > return outEndPt; > } > } > > Output: Exchange[Message: [Body is null]] > > Endpoint[file:///home/tnedelescu/workspace/CurrentMavenProject/src/alogatr/src/data/input/Component?noop=true] > > > > > -- > View this message in context: http://camel.465427.n5.nabble.com/choice-when-check-BodyType-null-Body-null-tp4259599p4683052.html > Sent from the Camel - Users mailing list archive at Nabble.com. > |
|
Thank you, Mirko. I'll insert a customized processor in the route.
Tereza |
| Powered by Nabble | Edit this page |
