Spring Websockets 4.1.6 with Tomcat 7.0.54 and Apache 2.4 -
i'm having troubles running simple application using spring websockets 4.1.6, tomcat 7.0.54 , apache 2.4.16 web server.
i have read lot of posts in internet, , don't know what's happening. server starts without problems. have index.html published in server project starts websocket connection.
if access file directly tomcat, works perfectly.
http://localhost:8080/myserver/messaging/index.html
but if access file apache server, doesn't work.
http://localhost/messages/messaging/index.html
in apache server have configured proxy pass:
proxypass /messages http://localhost:8080/myserver proxypassreverse /messages http://localhost:8080/myserver
my server websocket configuration looks follows:
@configuration @enablewebsocketmessagebroker public class puiwebsocketconfig extends abstractwebsocketmessagebrokerconfigurer { @override public void configuremessagebroker(messagebrokerregistry config) { config.setapplicationdestinationprefixes("/app"); config.enablesimplebroker("/user", "/topic"); } @override public void registerstompendpoints(stompendpointregistry registry) { registry.addendpoint("/puimessaging").withsockjs(); } }
and client connection follows:
function connect() { var socket = new sockjs('/server/puimessaging'); var stompclient = stomp.over(socket); var headers = { puisessionid : 'a1234567890z' }; stompclient.connect(headers, function(frame) { setconnected(true); stompclient.subscribe('/user/a1234567890z/response', function(data) { ... }); }); }
the server throws error saying need enable async support, don't know do.
async support must enabled on servlet , filters involved in async request processing. done in java code using servlet api or adding "<async-supported>true</async-supported>" servlet , filter declarations in web.xml. must use servlet 3.0+ container
i tried add property on web.xml file, doesn't work:
<servlet> <servlet-name>spring-mvc</servlet-name> <servlet-class>org.springframework.web.servlet.dispatcherservlet</servlet-class> <load-on-startup>1</load-on-startup> <async-supported>true</async-supported> </servlet> <servlet-mapping> <servlet-name>spring-mvc</servlet-name> <url-pattern>/*</url-pattern> </servlet-mapping>
any idea?
thanks in advance.
marc
i working, not via websockets via xhr_streaming. configuration looks follows:
web.xml
<?xml version="1.0" encoding="utf-8"?> <web-app id="webapp" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0"> <servlet> <servlet-name>spring-mvc</servlet-name> <servlet-class>org.springframework.web.servlet.dispatcherservlet</servlet-class> <load-on-startup>1</load-on-startup> <async-supported>true</async-supported> </servlet> <servlet-mapping> <servlet-name>spring-mvc</servlet-name> <url-pattern>/*</url-pattern> </servlet-mapping> <listener> <listener-class>org.springframework.web.context.contextloaderlistener</listener-class> </listener> <filter> <filter-name>encodingfilter</filter-name> <filter-class>org.springframework.web.filter.characterencodingfilter</filter-class> <init-param> <param-name>encoding</param-name> <param-value>utf-8</param-value> </init-param> <init-param> <param-name>forceencoding</param-name> <param-value>true</param-value> </init-param> <async-supported>true</async-supported> </filter> <filter-mapping> <filter-name>encodingfilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> </web-app>
tomcat (server.xml):
<connector uriencoding="utf-8" connectiontimeout="20000" port="8080" protocol="org.apache.coyote.http11.http11nioprotocol" redirectport="8443" />
apache httpd:
... loadmodule proxy_module modules/mod_proxy.so loadmodule proxy_ajp_module modules/mod_proxy_ajp.so loadmodule proxy_balancer_module modules/mod_proxy_balancer.so loadmodule proxy_connect_module modules/mod_proxy_connect.so loadmodule proxy_express_module modules/mod_proxy_express.so loadmodule proxy_fcgi_module modules/mod_proxy_fcgi.so loadmodule proxy_ftp_module modules/mod_proxy_ftp.so # loadmodule proxy_html_module modules/mod_proxy_html.so loadmodule proxy_http_module modules/mod_proxy_http.so loadmodule proxy_scgi_module modules/mod_proxy_scgi.so loadmodule proxy_wstunnel_module modules/mod_proxy_wstunnel.so ... proxypass /pideweb-gijon http://localhost:8080/pideweb_gijon proxypassreverse /pideweb-gijon http://localhost:8080/pideweb_gijon proxypass /pideweb-gijon/endpointpuisocket/ ws://localhost:8080/pideweb_gijon/endpointpuisocket/ proxypassreverse /pideweb-gijon/endpointpuisocket/ ws://localhost:8080/pideweb_gijon/endpointpuisocket/
spring configuration:
@configuration @enablewebsocketmessagebroker public class websocketconfig extends abstractwebsocketmessagebrokerconfigurer { @autowired private websocketservice websocketservice; @override public void configuremessagebroker(messagebrokerregistry config) { config.setapplicationdestinationprefixes("/app"); config.enablesimplebroker("/user", "/topic"); // config.setuserdestinationprefix("/user"); // config.enablesimplebroker("/queue", "/topic"); } @override public void registerstompendpoints(stompendpointregistry registry) { registry.addendpoint("/endpointpuisocket").withsockjs(); } @override public void configureclientinboundchannel(channelregistration registration) { channelinterceptoradapter interceptor = new channelinterceptoradapter() { @override public message<?> presend(message<?> message, messagechannel channel) { // store or remove session id in list depending on // message connecting or disconnecting stompheaderaccessor accessor = stompheaderaccessor .wrap(message); stompcommand command = accessor.getcommand(); list<string> headerssessionid = accessor .getnativeheader("puisessionid"); if (!collectionutils.isempty(headerssessionid)) { string sessionid = headerssessionid.get(0); switch (command) { case connect: // add session id websocketservice.addsession(sessionid); break; case disconnect: // remove session id websocketservice.removesession(sessionid); break; default: break; } } return message; } }; registration.setinterceptors(interceptor); } }
javascript client:
function(gst) { var url = '/pideweb-gijon/endpointpuisocket'; var socket = new sockjs(url); var stompclient = stomp.over(socket); var headers = { puisessionid : gst }; var self = this; stompclient.connect(headers, function(frame) { console.log('connected: ' + frame); self.stompclient.subscribe('/user/' + gst + '/response', function(data) { console.log(data.body); }); }); };
with this, when enter client, automatically tries connect server. i'm using chrome, , stack of requests:
info request
websocket request
xhr_streaming request
anybody knows happening websocket request?
thanks!
Comments
Post a Comment