Hi Your header is some sort of hbase type. So you need to check its API how to convert that type to a String, or some other way of getting the length of it.
As every Object in Java, has a .toString() method due its on java.lang.Object, then invoking .toString() may not in this case return the content of the hbase type, but maybe just the standard toString with the classname and an hashcode of the instance, something a like "HBase@4534f3" On Tue, Nov 27, 2012 at 6:33 PM, dunnlow <dunn...@yahoo.com> wrote: > 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. -- Claus Ibsen ----------------- Red Hat, Inc. FuseSource is now part of Red Hat Email: cib...@redhat.com Web: http://fusesource.com Twitter: davsclaus Blog: http://davsclaus.com Author of Camel in Action: http://www.manning.com/ibsen