You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by xiangqiuzhao <xi...@gmail.com> on 2012/01/09 13:58:46 UTC
in netty.why sended 6bytes, but server recved 9bytes
my Encoder:
protected Object encode(
ChannelHandlerContext ctx, Channel channel, Object msg) throws
Exception {
if (!(msg instanceof String)) {
return msg;//(1)
}
System.out.println("IN INCODE:" + msg);
buf.writeBytes(data); //6bytes
return buf;//(3)
}
my camelContext:
SimpleRegistry registry = new SimpleRegistry();
registry.put("myEncoder", encoder);
CamelContext context = new DefaultCamelContext(registry);
my routeBuilder:
context.addRoutes(new RouteBuilder() {
public void configure() throws Exception {
from("direct:cpsp")
.process(new MyToProcessor())
.to("netty:tcp://localhost:6789?sync=true")
.process(new MyFromProcessor());
}
});
why my server recved 9bytes??
and how camel know the encoder i put in DefaultCamelContext?
--
View this message in context: http://camel.465427.n5.nabble.com/in-netty-why-sended-6bytes-but-server-recved-9bytes-tp5131271p5131271.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: in netty.why sended 6bytes, but server recved 9bytes
Posted by xiangqiuzhao <xi...@gmail.com>.
Object decoder = appctx.getBean("mydecoder");
Object encoder = appctx.getBean("myencoder");
SimpleRegistry registry = new SimpleRegistry();
List<ChannelDownstreamHandler> encoders = new
ArrayList<ChannelDownstreamHandler>();
encoders.add((ChannelDownstreamHandler)encoder);
registry.put("myDecoder", decoder);
registry.put("myEncoder", encoder);
registry.put("myEncoders", encoders);
CamelContext context = new DefaultCamelContext(registry);
context.addRoutes(new RouteBuilder() {
public void configure() throws Exception {
from("direct:cpsp")
.process(new MyToProcessor())
.to("netty:tcp://localhost:6789?encoder=#myEncoder&sync=true")
.process(new MyFromProcessor());
}
});
why the to URI "encoder=#myEncoder"... exception like:
Failed to create route route1 at: >>>
To[netty:tcp://localhost:6789?encoder=#myEncoder&sync=true] <<< in route:
Route[[From[direct:cpsp]] -> [process[Wrap[com.sunyard.camel... because of
Failed to resolve endpoint:
netty://tcp://localhost:6789?encoder=%23myEncoder&sync=true due to: Could
not find a suitable setter for property: encoder 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.ChannelDownstreamHandler with value
#myEncoder
but that's ok if URI set to "encoders=#myEncoders".
--
View this message in context: http://camel.465427.n5.nabble.com/in-netty-why-sended-6bytes-but-server-recved-9bytes-tp5131271p5148545.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: in netty.why sended 6bytes, but server recved 9bytes
Posted by Willem Jiang <wi...@gmail.com>.
Hi,
You can put the encoding information on Exchange like this
exchange.setProperty(Exchange.CHARSET_NAME, “UTF_8”);
On 1/9/12 8:58 PM, xiangqiuzhao wrote:
> my Encoder:
>
> protected Object encode(
> ChannelHandlerContext ctx, Channel channel, Object msg) throws
> Exception {
> if (!(msg instanceof String)) {
> return msg;//(1)
> }
> System.out.println("IN INCODE:" + msg);
> buf.writeBytes(data); //6bytes
> return buf;//(3)
> }
>
> my camelContext:
>
> SimpleRegistry registry = new SimpleRegistry();
> registry.put("myEncoder", encoder);
> CamelContext context = new DefaultCamelContext(registry);
>
> my routeBuilder:
>
> context.addRoutes(new RouteBuilder() {
> public void configure() throws Exception {
> from("direct:cpsp")
> .process(new MyToProcessor())
> .to("netty:tcp://localhost:6789?sync=true")
> .process(new MyFromProcessor());
> }
> });
>
> why my server recved 9bytes??
>
> and how camel know the encoder i put in DefaultCamelContext?
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/in-netty-why-sended-6bytes-but-server-recved-9bytes-tp5131271p5131271.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
--
Willem
----------------------------------
FuseSource
Web: http://www.fusesource.com
Blog: http://willemjiang.blogspot.com (English)
http://jnn.javaeye.com (Chinese)
Twitter: willemjiang
Weibo: willemjiang
Re: in netty.why sended 6bytes, but server recved 9bytes
Posted by xiangqiuzhao <xi...@gmail.com>.
i use netty example client/server for test, recved content is correct.
but why add 8 bytes at header in Camel-netty?
--
View this message in context: http://camel.465427.n5.nabble.com/in-netty-why-sended-6bytes-but-server-recved-9bytes-tp5131271p5141678.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: in netty.why sended 6bytes, but server recved 9bytes
Posted by xiangqiuzhao <xi...@gmail.com>.
yes, i'm sure 6bytes only. add 8bytes to the header of netty by default. why?
--
View this message in context: http://camel.465427.n5.nabble.com/in-netty-why-sended-6bytes-but-server-recved-9bytes-tp5131271p5132953.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: in netty.why sended 6bytes, but server recved 9bytes
Posted by Łukasz Dywicki <lu...@code-house.org>.
You use String as payload so it might use UTF-8 as encoding. Your string is not typicall set of bytes, it is set of characters. Make sure first that you write a 6 byte string, not string with 6 characters.
Best regards,
Lukasz
--
Code-House
http://code-house.org
Wiadomość napisana przez xiangqiuzhao w dniu 2012-01-09, o godz. 16:43:
> sorry, my server recved 14bytes.
>
> client in Camel send "230111" string.
>
> but server recved "0000000A05740006323338303131" by hex string
>
> why had 8bytes with 0000000A05740006 ?
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/in-netty-why-sended-6bytes-but-server-recved-9bytes-tp5131271p5131578.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
Re: in netty.why sended 6bytes, but server recved 9bytes
Posted by xiangqiuzhao <xi...@gmail.com>.
sorry, my server recved 14bytes.
client in Camel send "230111" string.
but server recved "0000000A05740006323338303131" by hex string
why had 8bytes with 0000000A05740006 ?
--
View this message in context: http://camel.465427.n5.nabble.com/in-netty-why-sended-6bytes-but-server-recved-9bytes-tp5131271p5131578.html
Sent from the Camel - Users mailing list archive at Nabble.com.