camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dunnlow <dunn...@yahoo.com>
Subject Re: Set body to length of header string in Spring DSL?
Date Tue, 27 Nov 2012 17:33:55 GMT
Thanks, I have some reading up to do on OGNL (and file language).

To my initial question, sorry, I'm still not able to get my test working. 
Basically, nothing is output if I put a value in the name with the
expression you provided.  When I put a value in the name, I get the
following output depending on the contents of the Otherwise statement
(below):

Do you have any more insight as to the issue?  Here are some of the
expressions I tested and their results:

1) <camel:simple>${headerAs("name",String)}</camel:simple> 
       and also
     <camel:simple>${headerAs("name",String).length()}</camel:simple> 
      both output:  John

2) <camel:simple>${header("name").toString()}</camel:simple> 
        and also
    <camel:simple>${header("name").toString().length()}</camel:simple> 
     both output:  (nothing)

3) <camel:simple>${header("name")}</camel:simple>
    outputs: (nothing)

4) <camel:simple>${in.headers.name}</camel:simple>
   outputs:  John  

5)  <camel:javaScript>(request.headers.get('name')).length.toString()
   outputs:  function length() {/* int length() */}

6) <camel:groovy>'hello'.toString().length()</camel:groovy>
   outputs:  TypeConversionException (..."Error during type conversion from
type: java.lang.Integer to the requried typoe: byte[] with value 4 due to
java.lang.NoClassDefFoundError: org/apache/hadoop/hbase/util/Bytes....  at
org.apache.camel.imple.converter.BaseTypeConverterRegistry.convertTo(BaseTypeConverterRegistry.java:126)

7) <camel:groovy>'hello'.toString().length().toString()</camel:groovy>
    outputs: 5

my route:

   <camel:route>
       <camel:from uri="direct:t1">
           <camel:choice>
                <camel:when>
                   
<camel:javaScript>request.headers.get('name')==null</camel:javaScript>
                    <camel:setBody>
                         <camel:constant>Is Null</camel:constant>
                    </camel:setBody>
                </camel:when>
                <camel:otherwise>
                       <camel:setBody>
                            
<camel:simple>${header("name").toString().length()}</camel:simple>
                       </camel:setBody>
                </camel:otherwise>
           </camel:choice>
           <camel:to uri="stream:out"/>
   </camel:route>

my test code:

public class CamelStringTest extends CamelStringTestSupport {
   @Override
   protected AbstractApplicationContext createApplicationContext() {
       return new ClassPathXmlApplicationContext("context.xml");
   }

@Test
   public void testName() throws Exception {
    Map<String,Object> headers = new HashMap<String,Object>();
    headers.put("name","John");
    template.sendBodyAndHeaders("direct:t1","Hello there",headers);
    Thread.sleep(3000);
    assertNotNull(context.getEndpoint("direct:t1"));
  }
}



--
View this message in context: http://camel.465427.n5.nabble.com/Set-body-to-length-of-header-string-in-Spring-DSL-tp5723258p5723312.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Mime
View raw message