Return-Path: Delivered-To: apmail-activemq-camel-user-archive@locus.apache.org Received: (qmail 94129 invoked from network); 13 Feb 2008 18:09:09 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 13 Feb 2008 18:09:09 -0000 Received: (qmail 12594 invoked by uid 500); 13 Feb 2008 18:09:03 -0000 Delivered-To: apmail-activemq-camel-user-archive@activemq.apache.org Received: (qmail 12574 invoked by uid 500); 13 Feb 2008 18:09:03 -0000 Mailing-List: contact camel-user-help@activemq.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: camel-user@activemq.apache.org Delivered-To: mailing list camel-user@activemq.apache.org Received: (qmail 12565 invoked by uid 99); 13 Feb 2008 18:09:02 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 13 Feb 2008 10:09:02 -0800 X-ASF-Spam-Status: No, hits=2.6 required=10.0 tests=DNS_FROM_OPENWHOIS,SPF_HELO_PASS,SPF_PASS,WHOIS_MYPRIVREG X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of lists@nabble.com designates 216.139.236.158 as permitted sender) Received: from [216.139.236.158] (HELO kuber.nabble.com) (216.139.236.158) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 13 Feb 2008 18:08:29 +0000 Received: from isper.nabble.com ([192.168.236.156]) by kuber.nabble.com with esmtp (Exim 4.63) (envelope-from ) id 1JPM29-0001io-QW for camel-user@activemq.apache.org; Wed, 13 Feb 2008 10:08:37 -0800 Message-ID: <15461906.post@talk.nabble.com> Date: Wed, 13 Feb 2008 10:08:37 -0800 (PST) From: georgiosgeorgiadis To: camel-user@activemq.apache.org Subject: RE: Camel TCP receiver endpoint In-Reply-To: <15454126.post@talk.nabble.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Nabble-From: georgiosgeorgiadis@yahoo.co.uk References: <15430834.post@talk.nabble.com> <15431436.post@talk.nabble.com> <15432086.post@talk.nabble.com> <15436595.post@talk.nabble.com> <1D195F515BDFE04EA40FA8D046308D6A0167A499@emea-ems1.IONAGLOBAL.COM> <15454126.post@talk.nabble.com> X-Virus-Checked: Checked by ClamAV on apache.org I have scanned the source of MINAConsumer.java and in the doStart() method: IoHandler handler = new IoHandlerAdapter() { @Override public void messageReceived(IoSession session, Object message) throws Exception { getProcessor().process(endpoint.createExchange(session, message)); } }; if I change it to: IoHandler handler = new IoHandlerAdapter() { @Override public void messageReceived(IoSession session, Object message) throws Exception { MinaExchange exchange = endpoint.createExchange(session, message); getProcessor().process(exchange); session.write(exchange.getOut().getBody()); } }; It works and returns the reply back to the caller, otherwise it never seems to return as the MinaProducer.ResponseHandler.messageReceived() never seems to be callled thus the CountDownLatch.counter never decrements. make any sense? Regards Georgios georgiosgeorgiadis wrote: > > Thanks, though still it seems it is not working. I am sending a snippet of > my code just in case I do something wrong. > > First I send my Receiver class: > > public class Receiver{ > > public static void main(String [] s){ > > try{ > > CamelContext context = new DefaultCamelContext(); > > context.addRoutes(new RouteBuilder() { > public void configure() { > from("mina:tcp://localhost:6123").process(new Processor() > { > public void process(Exchange e) { > System.out.println("Received exchange: " + > e.getIn().getBody()); > e.getOut().setBody("tcp reply"); > } > }); > } > }); > > context.start(); > > }catch(Throwable ex){ > ex.printStackTrace(); > } > } > } > > When I start the receiver program, indeed a TCP server at port 6123 > startslistening for calls. > > Now my Sender program: > > public class Sender{ > > public static void main(String [] s){ > > try{ > > CamelContext context = new DefaultCamelContext(); > > context.start(); > > Endpoint endpoint = > context.getEndpoint("mina:tcp://localhost:6123"); > > MinaExchange exchange = > (MinaExchange)endpoint.createExchange(ExchangePattern.InOut); > > Message in = exchange.getIn(); > > in.setBody("tcp request"); > > Producer producer = endpoint.createProducer(); > > producer.start(); > > producer.process(exchange); > > Message out = exchange.getOut(); > > System.out.println(out.getBody()); > > producer.stop(); > > context.stop(); > > }catch(Throwable ex){ > ex.printStackTrace(); > } > > } > } > > When I start the sender, the request is received by the receiver, thus I > see > "Received exchange: tcp request" > printed on the receiver side. > > The sender blocks at Producer.process() method and after 10 seconds throws > > java.lang.RuntimeException: No response from server within 10000 millisecs > at > org.apache.camel.component.mina.MinaProducer.process(MinaProducer.java:76) > at Sender.main(Sender.java:33) > > And the exchange.getOut().getBody() is null. > > I am sure that I am doing something wrong, but I acnnot seem to see it. > The requiremnet is as simple as the above communication. > > The two snippets above should compile and run as is. > > Very best regards > > Georgios > > > Tully, Gary wrote: >> >> Hi Georgios, >> I am new to this so apologies if I put you wrong but I think what you >> need is to access the exchange Out message in your process method: >> >> public void process(Exchange e) { >> e.getOut().setBody("some text"); >> } >> >> Gary. >> >>> -----Original Message----- >>> From: georgiosgeorgiadis [mailto:georgiosgeorgiadis@yahoo.co.uk] >>> Sent: 12 February 2008 17:17 >>> To: camel-user@activemq.apache.org >>> Subject: Re: Camel TCP receiver endpoint >>> >>> >>> Hi James, thanks the examples helped a lot. I managed to >>> create a Mina TCP receiver which routes the call to a >>> component. Then I created a sender that calls the Mina TCP >>> component and passes it a serializable object, which managed >>> to reach my component at the other side of the TCP call. Till >>> here all worked fine. Yeepee. My problem now is a response >>> back to the caller. I have set up the sender to use Exchange >>> of type InOut, but I am sure how to prompt the receiver to >>> return a value via TCP to sender. The sender of course >>> times-out after 10 seconds telling me that the >>> Exchange.getOut() Message is null. >>> >>> Any suggestions? >>> >>> The InOut example from the Camel MINA examples works, but it >>> uses a local variable which is accessed directly by both the >>> receiver and sender (see protected Exchange receivedExchange; >>> in MinaTcpWithInOutTest.java). In my case the receiver and >>> sender in completely separate machines. I can see that my >>> sender blocks for a timeout period of 10 seconds (can we control this >>> parameter?) and returns. My receiver is added as a route >>> listeningto the TCP port but the process method of processor >>> is void thus there is no way to forward back a response. >>> >>> Hope all this makes sense. >>> >>> Thanks again for the huge help. >>> >>> Georgios >>> >>> >>> >>> James.Strachan wrote: >>> > >>> > On 12/02/2008, georgiosgeorgiadis >>> wrote: >>> >> >>> >> Thanks again James, >>> >> >>> >> I will give it a try and will keep posted. >>> >> >>> >> One last thing: >>> >> >>> >> Are there any MINA-Camel examples that I can look through >>> somewhere? >>> > >>> > There's a bunch of test cases here... >>> > >>> https://svn.apache.org/repos/asf/activemq/camel/trunk/components/camel >>> > -mina/ >>> > >>> > in here... >>> > >>> https://svn.apache.org/repos/asf/activemq/camel/trunk/components/camel >>> > -mina/src/test/java/org/apache/camel/component/mina/ >>> > >>> > though these all use the default Codecs and don't configure >>> their own. >>> > >>> > To ease the configuration of your codec, you could create >>> an extension >>> > of the MinaComponent that customizes the Codec to use and then bind >>> > that new component to some URI scheme of your choosing. >>> > >>> > e.g. if you chose 'foo' as your new protocol scheme you could then >>> > route in Camel via... >>> > >>> > from("foo://localhost:1234").to("something"); >>> > >>> > See >>> > http://activemq.apache.org/camel/writing-components.html >>> > -- >>> > James >>> > ------- >>> > http://macstrac.blogspot.com/ >>> > >>> > Open Source Integration >>> > http://open.iona.com >>> > >>> > >>> >>> -- >>> View this message in context: >>> http://www.nabble.com/Camel-TCP-receiver-endpoint-tp15430834s2 >> 2882p15436595.html >>> Sent from the Camel - Users mailing list archive at Nabble.com. >>> >> >> ---------------------------- >> IONA Technologies PLC (registered in Ireland) >> Registered Number: 171387 >> Registered Address: The IONA Building, Shelbourne Road, Dublin 4, Ireland >> >> > > -- View this message in context: http://www.nabble.com/Camel-TCP-receiver-endpoint-tp15430834s22882p15461906.html Sent from the Camel - Users mailing list archive at Nabble.com.