ng2-stomp-service无法连接到https中的Spring服务器

时间:2017-11-06 12:37:19

标签: spring angular stomp

我有一个客户端Angular 2应用程序和一个Spring启动(1.4.1.RELEASE)服务器应用程序。我编写了客户端代码,使用角度库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();

    }

}

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

1 个答案:

答案 0 :(得分:0)

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