Websocket works on localhost but not Heroku (updated)

I have an application that uses websockets (STOMP over SockJs), with Spring on the server. The application works fine (websockets) on localhost on Tomcat, but when I deploy to Heroku or AWS Web Sockets it stops working. My websocket configuration in Angular2

let sockjs = new SockJS('/rest/add?jwt=' + this.authService.getToken(), {"devel":true,"debug":true}, {"transports":["websocket"]}); 

I also tried using

 {"disabled_transports":["websocket"]} 

but both do not work. web.xml

  <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1"> <context-param> <param-name>spring.profiles.default</param-name> <param-value>default</param-value> </context-param> <servlet> <servlet-name>ws</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:/spring/ws-context.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> <async-supported>true</async-supported> </servlet> <servlet-mapping> <servlet-name>ws</servlet-name> <url-pattern>/rest/*</url-pattern> </servlet-mapping> <filter> <filter-name>springSecurityFilterChain</filter-name> <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class> <async-supported>true</async-supported> </filter> <filter-mapping> <filter-name>springSecurityFilterChain</filter-name> <url-pattern>/rest/*</url-pattern> </filter-mapping> </web-app> 

websocket in spring

  <websocket:message-broker application-destination-prefix="/app"> <websocket:stomp-endpoint path="/add"> <websocket:sockjs/> </websocket:stomp-endpoint> <websocket:simple-broker prefix="/topic, /queue" /> </websocket:message-broker> 

The URL of my Heroku app so you can check your web browser console yourself. Link Please see Updated Logs, this part bothers me No TransportHandler

 CJyb2xlcyI6IkNVU1RPTUVSIn0.wFqNOduN-lD1-9GIRnG1X1aLJZTxtz9c6vmO7jmPPiE2017-04-06T16:23:32.439917+00:00 app[web.1]: 2017-04-06 16:2332 WARN DefaultSockJsService:239 - No TransportHandler for http://myapp-ws.herokuapp.com/rest/add/097/eyocvxic/websocket?jwt=eyJhbGciOiJI 
+5
source share
1 answer

OK, so finally I made it work. It turned out that Tomcat on heroku does not have a standard set of libraries. First, I deployed locally to webapp-runner https://devcenter.heroku.com/articles/java-webapp-runner , after which I saw a strange error. I tested several libraries and finally after adding

 <dependency> <groupId>org.apache.tomcat.embed</groupId> <artifactId>tomcat-embed-websocket</artifactId> <version>8.5.11</version> </dependency> 

and

 <build> ... <plugins> ... <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <version>2.3</version> <executions> <execution> <phase>package</phase> <goals><goal>copy</goal></goals> <configuration> <artifactItems> <artifactItem> <groupId>com.github.jsimone</groupId> <artifactId>webapp-runner</artifactId> <version>8.5.11.3</version> <destFileName>webapp-runner.jar</destFileName> </artifactItem> </artifactItems> </configuration> </execution> </executions> </plugin> </plugins> 

I worked locally. Then I added PROCFILE with the following content

 web: java $JAVA_OPTS -jar myapp-ws/target/dependency/webapp-runner.jar --port $PORT myapp-ws/target/*.war 

and passed to GITHUB (I have git integrated with Heroku), the build is started from inside Heroku, and it works.

+7
source

Source: https://habr.com/ru/post/1266229/


All Articles