Note that there are some explanatory texts on larger screens.

plurals
  1. POSending big exchanges over netty on camel
    text
    copied!<p>I get a TooLongFrameException exception when trying to write large transfers using netty in camel. I can't really shrink the size of my exchanges without some serious refactoring.</p> <p>As a workaround, I explicitly specify an ObjectEncoder with a larger estimatedLength. However, it does not automatically convert the object back to its native form. I have to call convertBodyTo() on the camel route, which requires knowing beforehand the type of the class.</p> <p>Here's an example:</p> <pre><code>public static void main(String[] args) throws Exception{ JndiContext registry=new JndiContext(); //Workaround #1: explicitly specify the encoder so we can increase the estinatedLength. registry.bind("encoder", new ObjectEncoder(99999999)); CamelContext context=new DefaultCamelContext(registry); context.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { //This is the receiving end of the large data. from("netty:tcp://0.0.0.0:9002?transferExchange=true&amp;encoder=#encoder") //At this point the body is a BigEndianHeapChannelBuffer not a String .to("log:nettyin?level=INFO") .bean(System.out, "println") //Workaround #2: explicitly convert the body to the expected class. What do you do if you want several possible classes? .convertBodyTo(String.class) //Now we have a String as the body. .to("log:nettyin.string?level=INFO") .bean(System.out, "println"); //Use this endpoint to send large data. from("direct:start") .to("log:start?level=INFO") .to("netty:tcp://localhost:9002?transferExchange=true&amp;encoder=#encoder"); } }); context.start(); final ProducerTemplate template = context.createProducerTemplate(); String s=org.apache.commons.lang.StringUtils.repeat("x", 1133461); template.sendBody("direct:start", s); context.stop(); } </code></pre> <p>Is there a way to not explicitly call convertBodyTo()? Also how do I handle generics? For example convertBodyTo(List.class) does not work for List&lt;String>. I get an exception like this:</p> <pre> Caused by: org.apache.camel.NoTypeConversionAvailableException: No type converter available to convert from type: org.jboss.netty.buffer.BigEndianHeapChannelBuffer to the required type: java.util.ArrayList with value BigEndianHeapChannelBuffer(ridx=0, widx=422, cap=422) at org.apache.camel.impl.converter.BaseTypeConverterRegistry.mandatoryConvertTo(BaseTypeConverterRegistry.java:169) ~[camel-core-2.10.3.jar:2.10.3] at org.apache.camel.impl.MessageSupport.getMandatoryBody(MessageSupport.java:99) ~[camel-core-2.10.3.jar:2.10.3] ... 40 common frames omitted </pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload