【问题标题】:ng2-stomp-service does not connect to Spring server in httpsng2-stomp-service 未在 https 中连接到 Spring 服务器
【发布时间】:2017-11-06 12:37:19
【问题描述】:

我有一个客户端 Angular 2 应用程序和一个 Spring boot (1.4.1.RELEASE) 服务器应用程序。我编写了客户端代码以使用 Angular 库 ng2-stomp-service 向服务器发送连接请求,并编写了服务器代码来管理连接请求。

使用 http 时一切正常,但使用 https 时,我在 javascript 控制台中看到连接错误 (HTTP/1.1 400):

GET https://tomcatunisvid.lunagest.com/unisvid/workflow/046/mmesis4u/websocket [HTTP/1.1 400  358ms]

Firefox non può stabilire una connessione con il server wss://tomcatunisvid.lunagest.com/unisvid/workflow/046/mmesis4u/websocket.

在 Firefox 中,我找到了请求和响应标头:

-- 请求标头

Accept text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Encodinggzip, deflate, br
Accept-Language it-IT,it;q=0.8,en-US;q=0.5,en;q=0.3
Cache-Control no-cache
Connection keep-alive, Upgrade
Host tomcatunisvid.lunagest.com
Origin https://tomcatunisvid.lunagest.com 
Pragma no-cache
Sec-WebSocket-Extensions permessage-deflate
Sec-WebSocket-Key J2Aqm3n2r6vcE7F8SrPr3w==
Sec-WebSocket-Version 13
Upgrade websocket
User-AgentMozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:56.0) Gecko/20100101 Firefox/56.0

-- 响应头

Access-Control-Allow-Credentials true
Access-Control-Allow-Originh ttps://tomcatunisvid.lunagest.com
Cache-Control no-cache, no-store, max-age=0, must-revalidate
Connection close
Date Mon, 06 Nov 2017 11:50:42 GMT
Expires 0
Pragma no-cache
Server Apache/2.4.18 (Ubuntu)Transfer-Encoding chunked
Vary Origin
X-Content-Type-Options nosniff
X-Frame-Options DENY
X-XSS-Protection1; mode=block

响应为空。

这是我的相关客户端代码:

// In the constructor, where stomp is a StompService:

stomp.configure({
  host: this.url,
  debug: true,
  queue: { 'init': false, '/user/queue/user/reply': false },
  // headers: { 'upgrade': 'WebSocket' }
});

// in another method:

this.stomp.startConnect().
  then(() => this.openSocket_OK_Callback(this)).
  catch((error) => this.openSocket_KO_Callback(this, error));

这是我的相关服务器代码:

@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig extends 
AbstractWebSocketMessageBrokerConfigurer {

    @Override
    public void configureMessageBroker(MessageBrokerRegistry config) {
        config.setApplicationDestinationPrefixes("/wfm");
        config.enableSimpleBroker("/topic", "/queue");
    }

    @Override
    public void registerStompEndpoints(StompEndpointRegistry registry) {
        SessionDisconnectionListener sdl = new SessionDisconnectionListener();

        String endpoint = "/workflow";

        registry.addEndpoint(endpoint).
            setAllowedOrigins("*").withSockJS();

        registry.addEndpoint(endpoint).setHandshakeHandler(new DefaultHandshakeHandler(new TomcatRequestUpgradeStrategy())).
            setAllowedOrigins("*").withSockJS();

    }

}

任何提示如何解决这个问题?

【问题讨论】:

    标签: spring angular stomp


    【解决方案1】:

    我把调试后找到的答案放在这里,以防对其他人有用。在发布环境中,Tomcat 由 Apache Http Server 代理。这种情况下的解决方案是去掉Apache Http Server,直接在Tomcat上配置Https。

    【讨论】:

      猜你喜欢
      • 2020-06-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-21
      • 1970-01-01
      相关资源
      最近更新 更多