Hi

instead of

        <simple>${in.headers['Content-Type']} == 'application/json'</simple>

just write

        <simple>${in.headers[Content-Type]} == 'application/json'</simple>

For whatever reason I added the single quotes around the name of the header 
attribute, remove them and everything works as expected. I knew this and did it 
on another project just a few minutes ago without thinking about it. While 
testing it I realised my mistake on this one. So shame on me :)

Thanks for helping!

harald



On 22 Aug 2014, at 17:02, Claus Ibsen <[email protected]> wrote:

> Hi
> 
> I just tried with 2.14-snapshot on karaf 2.3.6 and it worked fine
> 
> davsclaus:~/$ curl -X POST -H "Content-Type:application/json" --data
> "{"Hello":"World"}" http://localhost:4000/harald/call
> {Hello:World}davsclaus:~/$
> davsclaus:~/$ curl -X POST -H "Content-Type:application/xml" --data
> "<Hello>World</Hello>" http://localhost:4000/harald/call
> <Hello>World</Hello>davsclaus:~/$
> 
> 
> 
> On Thu, Aug 21, 2014 at 11:10 AM, Harald Neiss <[email protected]> wrote:
>> Hi
>> 
>> On 21 Aug 2014, at 08:18, Claus Ibsen <[email protected]> wrote:
>> 
>>> Hi
>>> 
>>> You can use tracer to see the messages details during routing and see
>>> what headers you have
>>> http://camel.apache.org/tracer
>> 
>> Thanks for the reference! I added the trace attribute to the route (see 
>> below).
>> 
>>> Also mind that maybe the content type header is not 100% matching
>>> 'application/xml' etc. As sometimes they may have charset or other
>>> values included.
>> 
>> Yes, but since I’m currently using curl I am sure (and see the trace below) 
>> that it is send without encoding information.
>> 
>>> 
>>> The simple language has a contains function you can use
>>> http://camel.apache.org/simple
>>> 
>> 
>> Tanks for referencing.
>> 
>> 
>> I just realised that I did not include the version I use and the 
>> environment. Sorry for that. It’s Camel 2.10.7 which is embedded in 
>> ServiceMix 4.5.3.
>> 
>> The file I copy into the deploy folder of SMX looks like this (it’s the 
>> simplified version)
>> 
>> <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0";
>>           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
>>           xsi:schemaLocation="
>>           http://www.osgi.org/xmlns/blueprint/v1.0.0 
>> http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
>>           ">
>>  <camelContext xmlns="http://camel.apache.org/schema/blueprint";>
>>    <route trace="true">
>>      <from uri="jetty:http://localhost:4000/harald/call"/>
>>       <choice>
>>         <when>
>>           <simple>${in.headers['Content-Type']} == 
>> 'application/json'</simple>
>>           <to uri="log:JSON?level=INFO"/>
>>         </when>
>>         <when>
>>           <simple>${in.headers['Content-Type']} == 'application/xml'</simple>
>>           <to uri="log:XML?level=INFO"/>
>>         </when>
>>         <otherwise>
>>           <to uri="log:RAW?level=INFO"/>
>>         </otherwise>
>>       </choice>
>>    </route>
>>  </camelContext>
>> </blueprint>
>> 
>> Then I used curl to send requests. The following shows three calls and the 
>> output of them, hard to read but complete.
>> 
>> Thanks for helping!
>> 
>> Best regards,
>> harald
>> 
>> 
>> 
>> curl -X POST -H "Content-Type:application/json" --data "{"Hello":"World"}" 
>> http://localhost:4000/harald/call
>> 
>> 
>> 10:39:19,421 | INFO  | qtp795636687-809 | Tracer                           | 
>> 100 - org.apache.camel.camel-core - 2.10.7 | 
>> ID-beauty-49610-1408606366390-10-10 >>> (route24) 
>> from(http://localhost:4000/harald/call) --> choice <<< Pattern:InOut, 
>> Headers:{CamelHttpMethod=POST, Host=localhost:4000, 
>> CamelHttpPath=/harald/call, CamelHttpUri=/harald/call, CamelHttpQuery=null, 
>> Content-Length=13, CamelHttpServletResponse=HTTP/1.1 200
>> 
>> , User-Agent=curl/7.30.0, breadcrumbId=ID-beauty-49610-1408606366390-10-11, 
>> Content-Type=application/json, Accept=*/*, 
>> CamelHttpUrl=http://localhost:4000/harald/call, 
>> CamelHttpServletRequest=(POST /harald/call)@504434790 
>> org.eclipse.jetty.server.Request@1e111066}, 
>> BodyType:org.apache.camel.converter.stream.InputStreamCache, Body:[Body is 
>> instance of org.apache.camel.StreamCache]
>> 10:39:19,422 | INFO  | qtp795636687-809 | Tracer                           | 
>> 100 - org.apache.camel.camel-core - 2.10.7 | 
>> ID-beauty-49610-1408606366390-10-10 >>> (route24) choice --> 
>> log://RAW?level=INFO <<< Pattern:InOut, Headers:{CamelHttpMethod=POST, 
>> Host=localhost:4000, CamelHttpPath=/harald/call, CamelHttpUri=/harald/call, 
>> CamelHttpQuery=null, Content-Length=13, CamelHttpServletResponse=HTTP/1.1 200
>> 
>> , User-Agent=curl/7.30.0, breadcrumbId=ID-beauty-49610-1408606366390-10-11, 
>> Content-Type=application/json, Accept=*/*, 
>> CamelHttpUrl=http://localhost:4000/harald/call, 
>> CamelHttpServletRequest=(POST /harald/call)@504434790 
>> org.eclipse.jetty.server.Request@1e111066}, 
>> BodyType:org.apache.camel.converter.stream.InputStreamCache, Body:[Body is 
>> instance of org.apache.camel.StreamCache]
>> 10:39:19,422 | INFO  | qtp795636687-809 | RAW                              | 
>> 100 - org.apache.camel.camel-core - 2.10.7 | Exchange[ExchangePattern:InOut, 
>> BodyType:org.apache.camel.converter.stream.InputStreamCache, Body:[Body is 
>> instance of org.apache.camel.StreamCache]]
>> 
>> 
>> curl -X POST -H "Content-Type:application/xml" --data "<Hello>World</Hello>" 
>> http://localhost:4000/harald/call
>> 
>> 
>> 10:39:58,098 | INFO  | qtp795636687-809 | Tracer                           | 
>> 100 - org.apache.camel.camel-core - 2.10.7 | 
>> ID-beauty-49610-1408606366390-10-12 >>> (route24) 
>> from(http://localhost:4000/harald/call) --> choice <<< Pattern:InOut, 
>> Headers:{CamelHttpUrl=http://localhost:4000/harald/call, 
>> CamelHttpQuery=null, breadcrumbId=ID-beauty-49610-1408606366390-10-13, 
>> CamelHttpServletResponse=HTTP/1.1 200
>> 
>> , CamelHttpMethod=POST, Content-Type=application/xml, 
>> CamelHttpServletRequest=(POST /harald/call)@954758347 
>> org.eclipse.jetty.server.Request@38e874cb, Host=localhost:4000, 
>> CamelHttpPath=/harald/call, User-Agent=curl/7.30.0, Content-Length=20, 
>> Accept=*/*, CamelHttpUri=/harald/call}, 
>> BodyType:org.apache.camel.converter.stream.InputStreamCache, Body:[Body is 
>> instance of org.apache.camel.StreamCache]
>> 10:39:58,098 | INFO  | qtp795636687-809 | Tracer                           | 
>> 100 - org.apache.camel.camel-core - 2.10.7 | 
>> ID-beauty-49610-1408606366390-10-12 >>> (route24) choice --> 
>> log://RAW?level=INFO <<< Pattern:InOut, 
>> Headers:{CamelHttpUrl=http://localhost:4000/harald/call, 
>> CamelHttpQuery=null, breadcrumbId=ID-beauty-49610-1408606366390-10-13, 
>> CamelHttpServletResponse=HTTP/1.1 200
>> 
>> , CamelHttpMethod=POST, Content-Type=application/xml, 
>> CamelHttpServletRequest=(POST /harald/call)@954758347 
>> org.eclipse.jetty.server.Request@38e874cb, Host=localhost:4000, 
>> CamelHttpPath=/harald/call, User-Agent=curl/7.30.0, Content-Length=20, 
>> Accept=*/*, CamelHttpUri=/harald/call}, 
>> BodyType:org.apache.camel.converter.stream.InputStreamCache, Body:[Body is 
>> instance of org.apache.camel.StreamCache]
>> 10:39:58,098 | INFO  | qtp795636687-809 | RAW                              | 
>> 100 - org.apache.camel.camel-core - 2.10.7 | Exchange[ExchangePattern:InOut, 
>> BodyType:org.apache.camel.converter.stream.InputStreamCache, Body:[Body is 
>> instance of org.apache.camel.StreamCache]]
>> 
>> 
>> curl -X POST -H "Content-Type:text/text" --data "Hello World" 
>> http://localhost:4000/harald/call
>> 
>> 
>> 10:41:32,288 | INFO  | qtp795636687-810 | Tracer                           | 
>> 100 - org.apache.camel.camel-core - 2.10.7 | 
>> ID-beauty-49610-1408606366390-10-14 >>> (route24) 
>> from(http://localhost:4000/harald/call) --> choice <<< Pattern:InOut, 
>> Headers:{CamelHttpQuery=null, 
>> CamelHttpUrl=http://localhost:4000/harald/call, CamelHttpMethod=POST, 
>> Accept=*/*, Content-Type=text/text, CamelHttpServletRequest=(POST 
>> /harald/call)@789730262 org.eclipse.jetty.server.Request@2f1253d6, 
>> CamelHttpUri=/harald/call, breadcrumbId=ID-beauty-49610-1408606366390-10-15, 
>> CamelHttpPath=/harald/call, CamelHttpServletResponse=HTTP/1.1 200
>> 
>> , Content-Length=11, Host=localhost:4000, User-Agent=curl/7.30.0}, 
>> BodyType:org.apache.camel.converter.stream.InputStreamCache, Body:[Body is 
>> instance of org.apache.camel.StreamCache]
>> 10:41:32,289 | INFO  | qtp795636687-810 | Tracer                           | 
>> 100 - org.apache.camel.camel-core - 2.10.7 | 
>> ID-beauty-49610-1408606366390-10-14 >>> (route24) choice --> 
>> log://RAW?level=INFO <<< Pattern:InOut, Headers:{CamelHttpQuery=null, 
>> CamelHttpUrl=http://localhost:4000/harald/call, CamelHttpMethod=POST, 
>> Accept=*/*, Content-Type=text/text, CamelHttpServletRequest=(POST 
>> /harald/call)@789730262 org.eclipse.jetty.server.Request@2f1253d6, 
>> CamelHttpUri=/harald/call, breadcrumbId=ID-beauty-49610-1408606366390-10-15, 
>> CamelHttpPath=/harald/call, CamelHttpServletResponse=HTTP/1.1 200
>> 
>> , Content-Length=11, Host=localhost:4000, User-Agent=curl/7.30.0}, 
>> BodyType:org.apache.camel.converter.stream.InputStreamCache, Body:[Body is 
>> instance of org.apache.camel.StreamCache]
>> 10:41:32,289 | INFO  | qtp795636687-810 | RAW                              | 
>> 100 - org.apache.camel.camel-core - 2.10.7 | Exchange[ExchangePattern:InOut, 
>> BodyType:org.apache.camel.converter.stream.InputStreamCache, Body:[Body is 
>> instance of org.apache.camel.StreamCache]]
>> 
> 
> 
> 
> -- 
> Claus Ibsen
> -----------------
> Red Hat, Inc.
> Email: [email protected]
> Twitter: davsclaus
> Blog: http://davsclaus.com
> Author of Camel in Action: http://www.manning.com/ibsen
> hawtio: http://hawt.io/
> fabric8: http://fabric8.io/

Reply via email to