You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by jkab016 <jk...@gmail.com> on 2014/10/08 14:41:19 UTC

Apache Mina getting response from remote tcp server

I have been working on a project that posts messages to a remote tcp server
and I need the response from the server. In one of a hundred times I get the
right response. in other times the response is *Type 'exit' to quit*

my code is :

CamelContext context = new DefaultCamelContext();

        final String msg =
"SECTOR,GCS/I,JKAB016/123123,333,DESCRIPTION::=\"this is it
man\",SHORT.NAME::=\"integration\"";
        try {   

            Endpoint e =
context.getEndpoint("mina:tcp://127.0.0.1:7023?timeout=120000&textline=true&sync=true");
            Exchange ex = e.createExchange(ExchangePattern.InOut);

            ex.getIn().setBody(msg, String.class);
            Producer p = e.createProducer();
            p.start();
            p.process(ex);
            context.start();
            String resp = ex.getOut().getBody(String.class);

            System.out.println("t24 says: " + resp);
            Thread.sleep(1000);
            p.stop();
            context.stop();
       
        } catch (Exception e) {
            e.printStackTrace();
        }


can someone point out to me how I can disable the message *Type 'exit' to
quit.* so that I can get the right message from the server.
Thanks



--
View this message in context: http://camel.465427.n5.nabble.com/Apache-Mina-getting-response-from-remote-tcp-server-tp5757409.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Apache Mina getting response from remote tcp server

Posted by Willem Jiang <wi...@gmail.com>.
Can you using ProducerTemplate to send the message instead of using Producer directly?


BTW, you need start the camel context before staring the Producer.

--  
Willem Jiang

Red Hat, Inc.
Web: http://www.redhat.com
Blog: http://willemjiang.blogspot.com (English)
http://jnn.iteye.com (Chinese)
Twitter: willemjiang  
Weibo: 姜宁willem



On October 9, 2014 at 9:56:53 AM, jkab016 (jkab016@gmail.com) wrote:
> I have been working on a project that posts messages to a remote tcp server
> and I need the response from the server. In one of a hundred times I get the
> right response. in other times the response is *Type 'exit' to quit*
>  
> my code is :
>  
> CamelContext context = new DefaultCamelContext();
>  
> final String msg =
> "SECTOR,GCS/I,JKAB016/123123,333,DESCRIPTION::=\"this is it
> man\",SHORT.NAME::=\"integration\"";
> try {
>  
> Endpoint e =
> context.getEndpoint("mina:tcp://127.0.0.1:7023?timeout=120000&textline=true&sync=true");  
> Exchange ex = e.createExchange(ExchangePattern.InOut);
>  
> ex.getIn().setBody(msg, String.class);
> Producer p = e.createProducer();
> p.start();
> p.process(ex);
> context.start();
> String resp = ex.getOut().getBody(String.class);
>  
> System.out.println("t24 says: " + resp);
> Thread.sleep(1000);
> p.stop();
> context.stop();
>  
> } catch (Exception e) {
> e.printStackTrace();
> }
>  
>  
> can someone point out to me how I can disable the message *Type 'exit' to
> quit.* so that I can get the right message from the server.
> Thanks
>  
>  
>  
> --
> View this message in context: http://camel.465427.n5.nabble.com/Apache-Mina-getting-response-from-remote-tcp-server-tp5757409.html  
> Sent from the Camel - Users mailing list archive at Nabble.com.
>  


Re: Apache Mina getting response from remote tcp server

Posted by jkab016 <jk...@gmail.com>.
Thanks for your reply. Ideally I realized the code works. The issue is that
the server expects more than one exchanges-one to open up the port. So if I
fire two messages, I am able to get the right response. the trick is to send
two messages in a loop; the first message being a fake message and then the
actual message in the second instance



-----
sontranosa porahale iyanda gabba
--
View this message in context: http://camel.465427.n5.nabble.com/Apache-Mina-getting-response-from-remote-tcp-server-tp5757409p5757459.html
Sent from the Camel - Users mailing list archive at Nabble.com.