0

I am working on parsing the request. I developed route in Java for parsing incoming request.

I am using Camel 2.9 with FuseESB 7.0.1.0.84.

I used simple(“{body}”).getText() to fetch incoming request as per Camel Manual

So I am checking the incoming request by using the code as:

if (xmlStringToParse == null || xmlStringToParse.equals("") || xmlStringToParse.equals("${body}")) {

            parsedXMLPath = "<error>Incoming request is as folows:"
                    + "\nValue of xmlStringToParse: " + xmlStringToParse
                    + "\n xmlStringToParse is empty: " + (xmlStringToParse.equals(""))
                   + "\n xmlStringToParse equals ${body}: " + (xmlStringToParse.equals("${body}"))
                    + "\nAgain checking incoming request:\n" + xmlStringToParse
                    + "</error>";
        }

Where xmlStringToParse = simple(“${body}”).getText()

The strange outcoming observed:

Value of xmlStringToParse is changed in just one line from soap request to "". Also “xmlStringToParse equals ${body} “ is printed as “xmlStringToParse equals” without printing ${body}. ${body} is not printed in logs.

You can find the log output follows:

   <error>
    Value of xmlStringToParse: <somesoapRequest>
    xmlStringToParse is empty: false
   xmlStringToParse equals : true
  Again checking incoming request:
 </error>

Can anyone tell me how to solve this issue and the reason for this strange behavior?

рüффп
  • 5,172
  • 34
  • 67
  • 113
Ashish Nijai
  • 321
  • 2
  • 13

1 Answers1

2

I used simple(“{body}”).getText() to fetch incoming request as per Camel Manual

Where did you see that? Do you have a link?

You should get the message body in another way than what you do, such as

String body = exchange.getIn().getBody(String.class);

Or if you use bean parameter binding, you can bind the message body and just declare the parameter to be of String type

public void foo(String body) {
   ...
}

See more details at the Camel docs such at: http://camel.apache.org/bean-binding.html

Claus Ibsen
  • 56,060
  • 7
  • 50
  • 65
  • ,I found the information on [http://camel.apache.org/simple.html](http://camel.apache.org/simple.html) and [http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/builder/BuilderSupport.html](http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/builder/BuilderSupport.html) The problem here is that simple("${body}") gives right information in one instance and other instance in same time it modified by Fuse as "". I am baffled by this strange behavior. – Ashish Nijai Jan 10 '13 at 10:14
  • I also used `from().streamCaching()` and `getContext().setStreamCache(true)` before posting this question. But nothing helped. – Ashish Nijai Jan 10 '13 at 11:12
  • As said you should get the message body as I instructed. You cannot do as you do. The simple is an org.apache.camel.Expression, which you would need to call the evaluate method, and pass in the Exchange which has the message header + payload etc. Read the links, and see the other examples to learn how to do this. – Claus Ibsen Jan 10 '13 at 16:36
  • I did my previous coding using Exchange only. Just was doing some R&D on simple where I noticed that strange behavior. – Ashish Nijai Jan 21 '13 at 09:27