You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by jogro <jo...@gmail.com> on 2014/11/19 20:20:07 UTC

AHS-WS problem?

Hi,

I wanted to try out the new AHS-WS and Websocket components together with
Spring Boot so I set up
two maven projects based on
 
	Spring Roo 1.1.9.RELEASE
	Apache Camel 2.14.0.
	Java 1.8_05 (MacOS X) 

One client project using the following route configuration:

	from("direct:echo")
			.autoStartup(true)
			.marshal().base64()
			.convertBodyTo(String.class)
			.to("ahc-ws://localhost:9292/echo?sync=true");

		from("ahc-ws://localhost:9292/echo?sync=true")
			.log("Got ${body}");
			
One server project using the following route configuration:

	from("websocket://echo")
    		.unmarshal().base64()
    	    .log(">>> Message received from WebSocket Client : ${body}")
    	    .transform().simple("${in.body}")
    	    .to("websocket://echo");

These configurations actually work fine. Invoking

producerTemplate.requestBody("direct:echo", "Jonas")

generates a log like this.

2014-11-19 19:43:10.855 DEBUG 8577 --- [lication Thread]
o.a.camel.component.ahc.ws.WsProducer    : Sending out Sm9uYXM=

2014-11-19 19:43:11.190  INFO 8577 --- [w I/O worker #1]
o.a.camel.component.ahc.ws.WsEndpoint    : websocket opened
2014-11-19 19:43:11.309  INFO 8577 --- [w I/O worker #1]
o.a.camel.component.ahc.ws.WsEndpoint    : received message --> Hello Jonas!
2014-11-19 19:43:11.326  INFO 8577 --- [w I/O worker #1] route2                                  
: Got Hello Jonas!

But if I remove the call to convertBodyTo method in the client
configuration, the invocation above never gets a response from the server.
The log below shows two invocations:

2014-11-19 19:48:33.634 DEBUG 8592 --- [lication Thread]
o.a.camel.component.ahc.ws.WsProducer    : Sending out [83, 109, 57, 117,
89, 88, 77, 61, 13, 10]
2014-11-19 19:48:33.822  INFO 8592 --- [w I/O worker #1]
o.a.camel.component.ahc.ws.WsEndpoint    : websocket opened
2014-11-19 19:48:37.740 DEBUG 8592 --- [lication Thread]
o.a.camel.component.ahc.ws.WsProducer    : Sending out [83, 109, 57, 117,
89, 88, 77, 61, 13, 10]

What do you think? Is this a bug or is some configuration missing?

My client application config looks like this:

@Configuration
@ComponentScan
@EnableAutoConfiguration
public class Application {
	@Bean
	public ProducerTemplate producerTemplate(SpringCamelContext context) {
		return context.createProducerTemplate();
	}
	@Bean
	public SpringCamelContext camelContext(ApplicationContext
applicationContext)
			throws Exception {
		SpringCamelContext camelContext = new SpringCamelContext(
				applicationContext);
		camelContext.addRoutes(routeBuilder());
		return camelContext;
	}
        @Bean
	public RouteBuilder routeBuilder() {
		return new RouteBuilder() {
			@Override
			public void configure() throws Exception {
				from("direct:echo")
					.autoStartup(true)
					.marshal().base64()
					.convertBodyTo(String.class)
					.to("ahc-ws://localhost:9292/echo?sync=true");

				from("ahc-ws://localhost:9292/echo?sync=true")
					.log("Got ${body}");
			}
		};
	}
}

My server application config looks like this:

@Configuration
@ComponentScan
@EnableAutoConfiguration
public class Application {
	@Bean
	public SpringCamelContext camelContext(ApplicationContext
applicationContext)
			throws Exception {
		SpringCamelContext camelContext = new SpringCamelContext(
				applicationContext);
		camelContext.addRoutes(routeBuilder());
		return camelContext;
	}
	@Bean
	public RouteBuilder routeBuilder() {
		return new RouteBuilder() {
		    @Override
		    public void configure() throws Exception {
		    	from("websocket://echo")
		    		.unmarshal().base64()
		    	    .transform().simple("Hello ${body}!")
		    	    .to("websocket://echo");
		    }
		};
	}

	public static void main(String[] args) {
		SpringApplication.run(Application.class, args);
	}
}










--
View this message in context: http://camel.465427.n5.nabble.com/AHS-WS-problem-tp5759334.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: AHS-WS problem?

Posted by Aki Yoshida <el...@gmail.com>.
cool ;-)
thanks for posting your code example.


2014-11-22 17:25 GMT+01:00 jogro <jo...@gmail.com>:
> Adding the following method to the java config worked liked a charm:
>
>         @Bean
>         public ServletRegistrationBean camelWsServletRegistrationBean() {
>                 ServletRegistrationBean registration = new ServletRegistrationBean(
>                                 new CamelWebSocketServlet(), "/*");
>                 registration.setName("CamelWsServlet");
>                 return registration;
>         }
>
> Thanks for all helpful information!
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/AHS-WS-problem-tp5759334p5759496.html
> Sent from the Camel - Users mailing list archive at Nabble.com.

Re: AHS-WS problem?

Posted by jogro <jo...@gmail.com>.
Adding the following method to the java config worked liked a charm:

        @Bean
	public ServletRegistrationBean camelWsServletRegistrationBean() {
		ServletRegistrationBean registration = new ServletRegistrationBean(
				new CamelWebSocketServlet(), "/*");
		registration.setName("CamelWsServlet");
		return registration;
	}

Thanks for all helpful information!



--
View this message in context: http://camel.465427.n5.nabble.com/AHS-WS-problem-tp5759334p5759496.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: AHS-WS problem?

Posted by Aki Yoshida <el...@gmail.com>.
If you can get a servlet container running, you can attach the
atmosphere-websocket's endpoint using its servlet.
Or if you need to start a server on your own, you can do this like in
this setUp method.
https://git-wip-us.apache.org/repos/asf?p=camel.git;a=blob;f=components/camel-atmosphere-websocket/src/test/java/org/apache/camel/component/atmosphere/websocket/WebsocketCamelRouterTestSupport.java

But we could also add the binary mode to camel-websocket. I have a
slight concern, however, for the producer side, as I see that it is
currently converting any data (also byte[] then) into String and sent
it over the socket. So if someone has a scenario having byte[]
messages at the producer side and their client is expecting String
messages, they will need to add the convertBodyTo step to explicitly
convert the byte[] messge into a String message in that case, though.
CAMEL-8070 created for this.

regards, aki

2014-11-20 15:08 GMT+01:00 jogro <jo...@gmail.com>:
> Thanks for your quick answers. I'll look into the Camel Atmosphere component
> and see if I can have it running within Spring Boot too.
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/AHS-WS-problem-tp5759334p5759356.html
> Sent from the Camel - Users mailing list archive at Nabble.com.

Re: AHS-WS problem?

Posted by jogro <jo...@gmail.com>.
Thanks for your quick answers. I'll look into the Camel Atmosphere component
and see if I can have it running within Spring Boot too.



--
View this message in context: http://camel.465427.n5.nabble.com/AHS-WS-problem-tp5759334p5759356.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: AHS-WS problem?

Posted by Aki Yoshida <el...@gmail.com>.
you don't have an input stream based message but you have a byte[]
message. the rest of the story stays the same.


2014-11-20 0:47 GMT+01:00 Aki Yoshida <el...@gmail.com>:
> Hi,
> I can look at it tomorrow to confirm what I am saying below.
> A quick answer is that ahc-ws sends messages differently based on the
> java type of the message.
> In your case, you have an input stream based object when there is no
> string converter, In this case, the message is sent in a series of
> data fragments, where the last fragment is marked as "last".
>
> And I guess the camel-websocket can only  handle the plain string mode
> and ignores other types of data. I think camel-atmosphere-websocket
> should work with bytes or stream..
>
> regards, aki
>
>
> 2014-11-19 20:20 GMT+01:00 jogro <jo...@gmail.com>:
>> Hi,
>>
>> I wanted to try out the new AHS-WS and Websocket components together with
>> Spring Boot so I set up
>> two maven projects based on
>>
>>         Spring Roo 1.1.9.RELEASE
>>         Apache Camel 2.14.0.
>>         Java 1.8_05 (MacOS X)
>>
>> One client project using the following route configuration:
>>
>>         from("direct:echo")
>>                         .autoStartup(true)
>>                         .marshal().base64()
>>                         .convertBodyTo(String.class)
>>                         .to("ahc-ws://localhost:9292/echo?sync=true");
>>
>>                 from("ahc-ws://localhost:9292/echo?sync=true")
>>                         .log("Got ${body}");
>>
>> One server project using the following route configuration:
>>
>>         from("websocket://echo")
>>                 .unmarshal().base64()
>>             .log(">>> Message received from WebSocket Client : ${body}")
>>             .transform().simple("${in.body}")
>>             .to("websocket://echo");
>>
>> These configurations actually work fine. Invoking
>>
>> producerTemplate.requestBody("direct:echo", "Jonas")
>>
>> generates a log like this.
>>
>> 2014-11-19 19:43:10.855 DEBUG 8577 --- [lication Thread]
>> o.a.camel.component.ahc.ws.WsProducer    : Sending out Sm9uYXM=
>>
>> 2014-11-19 19:43:11.190  INFO 8577 --- [w I/O worker #1]
>> o.a.camel.component.ahc.ws.WsEndpoint    : websocket opened
>> 2014-11-19 19:43:11.309  INFO 8577 --- [w I/O worker #1]
>> o.a.camel.component.ahc.ws.WsEndpoint    : received message --> Hello Jonas!
>> 2014-11-19 19:43:11.326  INFO 8577 --- [w I/O worker #1] route2
>> : Got Hello Jonas!
>>
>> But if I remove the call to convertBodyTo method in the client
>> configuration, the invocation above never gets a response from the server.
>> The log below shows two invocations:
>>
>> 2014-11-19 19:48:33.634 DEBUG 8592 --- [lication Thread]
>> o.a.camel.component.ahc.ws.WsProducer    : Sending out [83, 109, 57, 117,
>> 89, 88, 77, 61, 13, 10]
>> 2014-11-19 19:48:33.822  INFO 8592 --- [w I/O worker #1]
>> o.a.camel.component.ahc.ws.WsEndpoint    : websocket opened
>> 2014-11-19 19:48:37.740 DEBUG 8592 --- [lication Thread]
>> o.a.camel.component.ahc.ws.WsProducer    : Sending out [83, 109, 57, 117,
>> 89, 88, 77, 61, 13, 10]
>>
>> What do you think? Is this a bug or is some configuration missing?
>>
>> My client application config looks like this:
>>
>> @Configuration
>> @ComponentScan
>> @EnableAutoConfiguration
>> public class Application {
>>         @Bean
>>         public ProducerTemplate producerTemplate(SpringCamelContext context) {
>>                 return context.createProducerTemplate();
>>         }
>>         @Bean
>>         public SpringCamelContext camelContext(ApplicationContext
>> applicationContext)
>>                         throws Exception {
>>                 SpringCamelContext camelContext = new SpringCamelContext(
>>                                 applicationContext);
>>                 camelContext.addRoutes(routeBuilder());
>>                 return camelContext;
>>         }
>>         @Bean
>>         public RouteBuilder routeBuilder() {
>>                 return new RouteBuilder() {
>>                         @Override
>>                         public void configure() throws Exception {
>>                                 from("direct:echo")
>>                                         .autoStartup(true)
>>                                         .marshal().base64()
>>                                         .convertBodyTo(String.class)
>>                                         .to("ahc-ws://localhost:9292/echo?sync=true");
>>
>>                                 from("ahc-ws://localhost:9292/echo?sync=true")
>>                                         .log("Got ${body}");
>>                         }
>>                 };
>>         }
>> }
>>
>> My server application config looks like this:
>>
>> @Configuration
>> @ComponentScan
>> @EnableAutoConfiguration
>> public class Application {
>>         @Bean
>>         public SpringCamelContext camelContext(ApplicationContext
>> applicationContext)
>>                         throws Exception {
>>                 SpringCamelContext camelContext = new SpringCamelContext(
>>                                 applicationContext);
>>                 camelContext.addRoutes(routeBuilder());
>>                 return camelContext;
>>         }
>>         @Bean
>>         public RouteBuilder routeBuilder() {
>>                 return new RouteBuilder() {
>>                     @Override
>>                     public void configure() throws Exception {
>>                         from("websocket://echo")
>>                                 .unmarshal().base64()
>>                             .transform().simple("Hello ${body}!")
>>                             .to("websocket://echo");
>>                     }
>>                 };
>>         }
>>
>>         public static void main(String[] args) {
>>                 SpringApplication.run(Application.class, args);
>>         }
>> }
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> --
>> View this message in context: http://camel.465427.n5.nabble.com/AHS-WS-problem-tp5759334.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.

Re: AHS-WS problem?

Posted by Aki Yoshida <el...@gmail.com>.
Hi,
I can look at it tomorrow to confirm what I am saying below.
A quick answer is that ahc-ws sends messages differently based on the
java type of the message.
In your case, you have an input stream based object when there is no
string converter, In this case, the message is sent in a series of
data fragments, where the last fragment is marked as "last".

And I guess the camel-websocket can only  handle the plain string mode
and ignores other types of data. I think camel-atmosphere-websocket
should work with bytes or stream..

regards, aki


2014-11-19 20:20 GMT+01:00 jogro <jo...@gmail.com>:
> Hi,
>
> I wanted to try out the new AHS-WS and Websocket components together with
> Spring Boot so I set up
> two maven projects based on
>
>         Spring Roo 1.1.9.RELEASE
>         Apache Camel 2.14.0.
>         Java 1.8_05 (MacOS X)
>
> One client project using the following route configuration:
>
>         from("direct:echo")
>                         .autoStartup(true)
>                         .marshal().base64()
>                         .convertBodyTo(String.class)
>                         .to("ahc-ws://localhost:9292/echo?sync=true");
>
>                 from("ahc-ws://localhost:9292/echo?sync=true")
>                         .log("Got ${body}");
>
> One server project using the following route configuration:
>
>         from("websocket://echo")
>                 .unmarshal().base64()
>             .log(">>> Message received from WebSocket Client : ${body}")
>             .transform().simple("${in.body}")
>             .to("websocket://echo");
>
> These configurations actually work fine. Invoking
>
> producerTemplate.requestBody("direct:echo", "Jonas")
>
> generates a log like this.
>
> 2014-11-19 19:43:10.855 DEBUG 8577 --- [lication Thread]
> o.a.camel.component.ahc.ws.WsProducer    : Sending out Sm9uYXM=
>
> 2014-11-19 19:43:11.190  INFO 8577 --- [w I/O worker #1]
> o.a.camel.component.ahc.ws.WsEndpoint    : websocket opened
> 2014-11-19 19:43:11.309  INFO 8577 --- [w I/O worker #1]
> o.a.camel.component.ahc.ws.WsEndpoint    : received message --> Hello Jonas!
> 2014-11-19 19:43:11.326  INFO 8577 --- [w I/O worker #1] route2
> : Got Hello Jonas!
>
> But if I remove the call to convertBodyTo method in the client
> configuration, the invocation above never gets a response from the server.
> The log below shows two invocations:
>
> 2014-11-19 19:48:33.634 DEBUG 8592 --- [lication Thread]
> o.a.camel.component.ahc.ws.WsProducer    : Sending out [83, 109, 57, 117,
> 89, 88, 77, 61, 13, 10]
> 2014-11-19 19:48:33.822  INFO 8592 --- [w I/O worker #1]
> o.a.camel.component.ahc.ws.WsEndpoint    : websocket opened
> 2014-11-19 19:48:37.740 DEBUG 8592 --- [lication Thread]
> o.a.camel.component.ahc.ws.WsProducer    : Sending out [83, 109, 57, 117,
> 89, 88, 77, 61, 13, 10]
>
> What do you think? Is this a bug or is some configuration missing?
>
> My client application config looks like this:
>
> @Configuration
> @ComponentScan
> @EnableAutoConfiguration
> public class Application {
>         @Bean
>         public ProducerTemplate producerTemplate(SpringCamelContext context) {
>                 return context.createProducerTemplate();
>         }
>         @Bean
>         public SpringCamelContext camelContext(ApplicationContext
> applicationContext)
>                         throws Exception {
>                 SpringCamelContext camelContext = new SpringCamelContext(
>                                 applicationContext);
>                 camelContext.addRoutes(routeBuilder());
>                 return camelContext;
>         }
>         @Bean
>         public RouteBuilder routeBuilder() {
>                 return new RouteBuilder() {
>                         @Override
>                         public void configure() throws Exception {
>                                 from("direct:echo")
>                                         .autoStartup(true)
>                                         .marshal().base64()
>                                         .convertBodyTo(String.class)
>                                         .to("ahc-ws://localhost:9292/echo?sync=true");
>
>                                 from("ahc-ws://localhost:9292/echo?sync=true")
>                                         .log("Got ${body}");
>                         }
>                 };
>         }
> }
>
> My server application config looks like this:
>
> @Configuration
> @ComponentScan
> @EnableAutoConfiguration
> public class Application {
>         @Bean
>         public SpringCamelContext camelContext(ApplicationContext
> applicationContext)
>                         throws Exception {
>                 SpringCamelContext camelContext = new SpringCamelContext(
>                                 applicationContext);
>                 camelContext.addRoutes(routeBuilder());
>                 return camelContext;
>         }
>         @Bean
>         public RouteBuilder routeBuilder() {
>                 return new RouteBuilder() {
>                     @Override
>                     public void configure() throws Exception {
>                         from("websocket://echo")
>                                 .unmarshal().base64()
>                             .transform().simple("Hello ${body}!")
>                             .to("websocket://echo");
>                     }
>                 };
>         }
>
>         public static void main(String[] args) {
>                 SpringApplication.run(Application.class, args);
>         }
> }
>
>
>
>
>
>
>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/AHS-WS-problem-tp5759334.html
> Sent from the Camel - Users mailing list archive at Nabble.com.