在本地主机上工作但不是Heroku的Websocket(已更新) [英] Websocket working on localhost but not Heroku (updated)

查看:155
本文介绍了在本地主机上工作但不是Heroku的Websocket(已更新)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序使用websockets(STOMP over SockJs),后端使用Spring。应用程序在Tomcat上的localhost上正常工作(websockets),但是当我部署到Heroku或AWS Web Sockets停止工作时。
Angular2中的websocket配置

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

我也尝试过

  {disabled_transports:[websocket]} 

但都是失败。
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>
<参数值>默认值< /参数值>
< / 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>
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>

spring中的websocket

 < 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>

我在Heroku上的应用程序的URL,以便您可以在您的Web浏览器的控制台中自行检查。
链接
请参阅最新日志,这篇文章让我很担心 No TransportHandler

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


解决方案

好的,最后我让它工作。原来,heroku上的Tomcat没有标准的库集。
首先我在webapp-runner上本地部署 https://devcenter.heroku。 com / articles / java-webapp-runner 后发现了一个奇怪的错误。我测试了几个库,最后在添加了

 < dependency>后, 
< groupId> org.apache.tomcat.embed< / groupId>
< artifactId> tomcat-embed-websocket< / artifactId>
< version> 8.5.11< / version>
< /依赖关系>

 <建立> 
...
< plugins>
...
< plugin>
< groupId> org.apache.maven.plugins< / groupId>
< artifactId> maven-dependency-plugin< / artifactId>
< version> 2.3< / version>
<执行次数>
<执行>
<阶段>包< /阶段>
<目标><目标>副本< /目标>< /目标>
<配置>
< 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>
< /执行>
< /执行次数>
< / plugin>
< / plugins>



我在本地工作。
然后我在以下内容中添加了PROCFILE:
$ b $ pre $ web:java $ JAVA_OPTS -jar myapp-ws / target / dependency / webapp-runner.jar --port $ PORT myapp-ws / target / * .war

并已提交到GITHUB(我把git与Heroku集成在一起),从Heroku内部触发构建,并且工作。


I have an application that uses websockets (STOMP over SockJs), with Spring at the backend. Application works fine (websockets) on localhost on Tomcat but when I deploy to Heroku or AWS Web Sockets stop 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 with

{"disabled_transports":["websocket"]}

but both are failing. 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>

URL to my application on Heroku so you can check by yourself in console of your web browser. Link Please see updated logs, this piece makes me worried 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

解决方案

ok, so finally I made it working. Turned out that Tomcat on heroku does not have the standard set of libraries. First I deployed locally on webapp-runner https://devcenter.heroku.com/articles/java-webapp-runner after which I I saw a strange error. I tested with a few libraries and finally after 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 got it working locally. Then I added PROCFILE with following content

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

and committed to GITHUB (I have git integrated with Heroku), triggered build from within Heroku and it works.

这篇关于在本地主机上工作但不是Heroku的Websocket(已更新)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆