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/02/13 15:32:27 UTC

about netty encoder and encoders...

if i use encoders and decoders property, the program is ok. 

        Object decoder = new LengthDecoder(); //appctx.getBean("mydecoder");
        Object encoder = new MessageEncoder(10);
//appctx.getBean("myencoder");
        
        SimpleRegistry registry = new SimpleRegistry(); 
        
        List<ChannelDownstreamHandler> encoders = new
ArrayList<ChannelDownstreamHandler>();
        List<ChannelUpstreamHandler> decoders = new
ArrayList<ChannelUpstreamHandler>();
        encoders.add((ChannelDownstreamHandler)encoder);
        decoders.add((ChannelUpstreamHandler)decoder);
        
        registry.put("myDecoder", decoder);
        registry.put("myEncoder", encoder);
        registry.put("myEncoders", encoders);
        registry.put("myDecoders", decoders);
        
        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?encoders=#myEncoders&decoders=#myDecoders&sync=true")
                .process(new MyFromProcessor());
            }
        });

but if i use the netty uri like:


.to("netty:tcp://localhost:6789?encoder=myEncoder&decoder=myDecoder&sync=true")

exception with :

Caused by: org.apache.camel.ResolveEndpointFailedException: Failed to
resolve endpoint:
netty://tcp://localhost:6789?decoder=myDecoder&encoder=myEncoder&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

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


what's wrong? MyDecoder is type of ChannelUpstreamHandler. why is
java.lang.String? 


--
View this message in context: http://camel.465427.n5.nabble.com/about-netty-encoder-and-encoders-tp5479417p5479417.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: about netty encoder and encoders...

Posted by Babak Vahdat <ba...@swissonline.ch>.
Hi

You make use of Camel 2.7.2 which means you're suffering from the ticket [1]
not being resolved by your used version, so consider an upgrade if possible.

Just a side note:
As you own one *single* encoder and *one* single decoder just make use of
encoder/decoder parameters and remove the encoders/decoders bindings into
the registery as it's obsolete.

[1] https://issues.apache.org/jira/browse/CAMEL-4367

Babak

--
View this message in context: http://camel.465427.n5.nabble.com/about-netty-encoder-and-encoders-tp5479417p5483010.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: about netty encoder and encoders...

Posted by xiangqiuzhao <xi...@gmail.com>.
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.

Re: about netty encoder and encoders...

Posted by Babak Vahdat <ba...@swissonline.ch>.
Hi

No it's NOT a mistake of yours, as both encoder/encoders as well as
decoder/decoders are ALL supported, see [1] which supports these!

Question: does your encoder extends
org.jboss.netty.channel.ChannelDownStreamHandler and your decoder extends
org.jboss.netty.channel.ChannelUpStreamHandler.

Can we see the source of your LengthDecoder as well as MessageEncoder. And
also please provide the full stack trace.

BTW I don't know much about camel-netty however I intend to help *if* I can.

[1] 
https://svn.apache.org/repos/asf/camel/trunk/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyConfiguration.java

Babak

--
View this message in context: http://camel.465427.n5.nabble.com/about-netty-encoder-and-encoders-tp5479417p5482489.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: about netty encoder and encoders...

Posted by xiangqiuzhao <xi...@gmail.com>.
i had look at http://camel.apache.org/netty.html, and described as "Registry
based Options".

so it's a mistake?

--
View this message in context: http://camel.465427.n5.nabble.com/about-netty-encoder-and-encoders-tp5479417p5482422.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: about netty encoder and encoders...

Posted by Willem Jiang <wi...@gmail.com>.
You should use the options of decoders and encoders.
The netty endpoint doesn't support the option of encoder and decoder.

On Tue Feb 14 12:46:27 2012, xiangqiuzhao wrote:
> I change the URI with
> .to("netty:tcp://localhost:6789?encoder=#myEncoder&decoder=#myDecoder&sync=true").
>
> but the same exception be throw.
>
> the whole code like:
>
>          Object decoder = new LengthDecoder(); //appctx.getBean("mydecoder");
>          Object encoder = new MessageEncoder(10);
> //appctx.getBean("myencoder");
>
>          SimpleRegistry registry = new SimpleRegistry();
>
>          List<ChannelDownstreamHandler>  encoders = new
> ArrayList<ChannelDownstreamHandler>();
>          List<ChannelUpstreamHandler>  decoders = new
> ArrayList<ChannelUpstreamHandler>();
>          encoders.add((ChannelDownstreamHandler)encoder);
>          decoders.add((ChannelUpstreamHandler)decoder);
>
>          registry.put("myDecoder", decoder);
>          registry.put("myEncoder", encoder);
>
>          registry.put("myEncoders", encoders);
>          registry.put("myDecoders", decoders);
>
>          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?encoders=#myEncoders&decoders=myDecoders&sync=true")
>
> .to("netty:tcp://localhost:6789?encoder=#myEncoder&decoder=#myDecoder&sync=true")
>                  .process(new MyFromProcessor());
>              }
>          });
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/about-netty-encoder-and-encoders-tp5479417p5481472.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: about netty encoder and encoders...

Posted by xiangqiuzhao <xi...@gmail.com>.
I change the URI with
.to("netty:tcp://localhost:6789?encoder=#myEncoder&decoder=#myDecoder&sync=true").

but the same exception be throw.

the whole code like:

        Object decoder = new LengthDecoder(); //appctx.getBean("mydecoder");
        Object encoder = new MessageEncoder(10);
//appctx.getBean("myencoder");
        
        SimpleRegistry registry = new SimpleRegistry(); 
        
        List<ChannelDownstreamHandler> encoders = new
ArrayList<ChannelDownstreamHandler>();
        List<ChannelUpstreamHandler> decoders = new
ArrayList<ChannelUpstreamHandler>();
        encoders.add((ChannelDownstreamHandler)encoder);
        decoders.add((ChannelUpstreamHandler)decoder);
        
        registry.put("myDecoder", decoder);
        registry.put("myEncoder", encoder);
        
        registry.put("myEncoders", encoders);
        registry.put("myDecoders", decoders);
        
        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?encoders=#myEncoders&decoders=myDecoders&sync=true")
               
.to("netty:tcp://localhost:6789?encoder=#myEncoder&decoder=#myDecoder&sync=true")
                .process(new MyFromProcessor());
            }
        });

--
View this message in context: http://camel.465427.n5.nabble.com/about-netty-encoder-and-encoders-tp5479417p5481472.html
Sent from the Camel - Users mailing list archive at Nabble.com.

RE: about netty encoder and encoders...

Posted by "Boller, Stefan" <st...@sap.com>.
Hi,

please try ".to("netty:tcp://localhost:6789?encoder=#myEncoder&decoder=#myDecoder&sync=true")". Please note the "#" sign in the url, which marks a reference.

Best regards, STefan

-----Original Message-----
From: xiangqiuzhao [mailto:xiangqiuzhao@gmail.com] 
Sent: Montag, 13. Februar 2012 15:32
To: users@camel.apache.org
Subject: about netty encoder and encoders...

if i use encoders and decoders property, the program is ok. 

        Object decoder = new LengthDecoder(); //appctx.getBean("mydecoder");
        Object encoder = new MessageEncoder(10);
//appctx.getBean("myencoder");
        
        SimpleRegistry registry = new SimpleRegistry(); 
        
        List<ChannelDownstreamHandler> encoders = new
ArrayList<ChannelDownstreamHandler>();
        List<ChannelUpstreamHandler> decoders = new
ArrayList<ChannelUpstreamHandler>();
        encoders.add((ChannelDownstreamHandler)encoder);
        decoders.add((ChannelUpstreamHandler)decoder);
        
        registry.put("myDecoder", decoder);
        registry.put("myEncoder", encoder);
        registry.put("myEncoders", encoders);
        registry.put("myDecoders", decoders);
        
        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?encoders=#myEncoders&decoders=#myDecoders&sync=true")
                .process(new MyFromProcessor());
            }
        });

but if i use the netty uri like:


.to("netty:tcp://localhost:6789?encoder=myEncoder&decoder=myDecoder&sync=true")

exception with :

Caused by: org.apache.camel.ResolveEndpointFailedException: Failed to
resolve endpoint:
netty://tcp://localhost:6789?decoder=myDecoder&encoder=myEncoder&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

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


what's wrong? MyDecoder is type of ChannelUpstreamHandler. why is
java.lang.String? 


--
View this message in context: http://camel.465427.n5.nabble.com/about-netty-encoder-and-encoders-tp5479417p5479417.html
Sent from the Camel - Users mailing list archive at Nabble.com.