the class LengthDecoder and MessageEncoder code:
public class LengthDecoder extends FrameDecoder {
private static final transient Logger LOG =
LoggerFactory.getLogger(LengthDecoder.class);
@Override
protected Object decode(
ChannelHandlerContext ctx, Channel channel, ChannelBuffer
buffer) throws Exception {
LOG.info("in Length decoder");
while (buffer.readableBytes() < 6) {
Thread.currentThread().sleep(1000);
LOG.info("SLEEP 1000ms");
}
buffer.skipBytes(5);
LOG.info("decoder buffer:" + buffer.toString());
return buffer.toString();
}
}
public class MessageEncoder extends OneToOneEncoder {
private static final transient Logger LOG =
LoggerFactory.getLogger(MessageEncoder.class);
private int i = 10;
public MessageEncoder(int i) {
this.i = i;
}
@Override
protected Object encode(ChannelHandlerContext ctx, Channel channel,
Object msg)
throws Exception {
if (!(msg instanceof String)) {
LOG.info("msg type is:" + msg.getClass().getName());
return msg;
}
LOG.info("I=" + i);
String res = (String)msg;
byte[] data = res.getBytes();
LOG.info("IN INCODE:" + msg);
ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
buf.writeBytes(data);
return buf;
}
}
I test use URI as
.to("netty:tcp://localhost:6789?encoder=#myEncoder&decoder=#myDecoder&sync=true").
the full stracktrace:
23:10:57.515 [main] INFO o.a.camel.impl.DefaultCamelContext - Uptime: 1.797
seconds
23:10:57.515 [main] INFO o.a.camel.impl.DefaultCamelContext - Apache Camel
2.7.2 (CamelContext: camel-1) is shutdown in 0.031 seconds
Exception in thread "main" org.apache.camel.FailedToCreateRouteException:
Failed to create route route1 at: >>>
To[netty:tcp://localhost:6789?encoder=#myEncoder&decoder=#myDecoder&sync=true]
<<< in route: Route[[From[direct:cpsp]] ->
[process[Wrap[com.sunyard.camel... because of Failed to resolve endpoint:
netty://tcp://localhost:6789?decoder=%23myDecoder&encoder=%23myEncoder&sync=true
due to: Could not find a suitable setter for property: decoder as there
isn't a setter method with same type: java.lang.String nor type conversion
possible: No type converter available to convert from type: java.lang.String
to the required type: org.jboss.netty.channel.ChannelUpstreamHandler with
value #myDecoder
at
org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:815)
at
org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:165)
at
org.apache.camel.impl.DefaultCamelContext.startRoute(DefaultCamelContext.java:706)
at
org.apache.camel.impl.DefaultCamelContext.startRouteDefinitions(DefaultCamelContext.java:1643)
at
org.apache.camel.impl.DefaultCamelContext.doStartCamel(DefaultCamelContext.java:1432)
at
org.apache.camel.impl.DefaultCamelContext.doStart(DefaultCamelContext.java:1336)
at org.apache.camel.impl.ServiceSupport.start(ServiceSupport.java:67)
at org.apache.camel.impl.ServiceSupport.start(ServiceSupport.java:54)
at
org.apache.camel.impl.DefaultCamelContext.start(DefaultCamelContext.java:1314)
at com.sunyard.camel.TestNetty.main(TestNetty.java:109)
Caused by: org.apache.camel.ResolveEndpointFailedException: Failed to
resolve endpoint:
netty://tcp://localhost:6789?decoder=%23myDecoder&encoder=%23myEncoder&sync=true
due to: Could not find a suitable setter for property: decoder as there
isn't a setter method with same type: java.lang.String nor type conversion
possible: No type converter available to convert from type: java.lang.String
to the required type: org.jboss.netty.channel.ChannelUpstreamHandler with
value #myDecoder
at
org.apache.camel.impl.DefaultCamelContext.getEndpoint(DefaultCamelContext.java:450)
at
org.apache.camel.util.CamelContextHelper.getMandatoryEndpoint(CamelContextHelper.java:47)
at
org.apache.camel.model.RouteDefinition.resolveEndpoint(RouteDefinition.java:180)
at
org.apache.camel.impl.DefaultRouteContext.resolveEndpoint(DefaultRouteContext.java:110)
at
org.apache.camel.impl.DefaultRouteContext.resolveEndpoint(DefaultRouteContext.java:116)
at
org.apache.camel.model.SendDefinition.resolveEndpoint(SendDefinition.java:61)
at
org.apache.camel.model.SendDefinition.createProcessor(SendDefinition.java:55)
at
org.apache.camel.model.ProcessorDefinition.makeProcessor(ProcessorDefinition.java:410)
at
org.apache.camel.model.ProcessorDefinition.addRoutes(ProcessorDefinition.java:181)
at
org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:812)
... 9 more
Caused by: java.lang.IllegalArgumentException: Could not find a suitable
setter for property: decoder as there isn't a setter method with same type:
java.lang.String nor type conversion possible: No type converter available
to convert from type: java.lang.String to the required type:
org.jboss.netty.channel.ChannelUpstreamHandler with value #myDecoder
at
org.apache.camel.util.IntrospectionSupport.setProperty(IntrospectionSupport.java:341)
at
org.apache.camel.util.IntrospectionSupport.setProperties(IntrospectionSupport.java:291)
at
org.apache.camel.util.EndpointHelper.setProperties(EndpointHelper.java:225)
at
org.apache.camel.component.netty.NettyConfiguration.parseURI(NettyConfiguration.java:125)
at
org.apache.camel.component.netty.NettyComponent.createEndpoint(NettyComponent.java:49)
at
org.apache.camel.impl.DefaultComponent.createEndpoint(DefaultComponent.java:75)
at
org.apache.camel.impl.DefaultCamelContext.getEndpoint(DefaultCamelContext.java:432)
... 18 more
--
View this message in context:
http://camel.465427.n5.nabble.com/about-netty-encoder-and-encoders-tp5479417p5482725.html
Sent from the Camel - Users mailing list archive at Nabble.com.