OpenShift:无法使用Alias连接到WebSocket(bug)

时间:2016-09-04 04:40:51

标签: websocket openshift spring-websocket openshift-origin java-websocket

我有一个使用WebSockets的 Java Spring Web应用程序 。 HTML文件使用uri连接到WebSocket:

var wsUri = "wss://" + document.location.hostname + ":8443" + "/serverendpoint";

这是我创建WebSocket的serverendpoint.java代码:

package com.myapp.spring.web.controller;
import java.io.IOException;

import javax.websocket.OnClose;
import javax.websocket.OnError;
import javax.websocket.OnMessage;
import javax.websocket.OnOpen;
import javax.websocket.Session;
import javax.websocket.server.ServerEndpoint;

import org.springframework.web.socket.server.standard.SpringConfigurator;


@ServerEndpoint(value="/serverendpoint", configurator = SpringConfigurator.class)

public class serverendpoint {

    @OnOpen
    public void handleOpen () {
        System.out.println("JAVA: Client is now connected...");
    }

    @OnMessage
    public String handleMessage (Session session, String message) throws IOException {

        if (message.equals("ping")) {
//            return "pong"
                session.getBasicRemote().sendText("pong");
        }
        else if (message.equals("close")) {
            handleClose();
            return null;
        }
        System.out.println("JAVA: Received from client: "+ message);
        MyClass mc = new MyClass(message);
        String res = mc.action();
        session.getBasicRemote().sendText(res);
        return res;
    }

    @OnClose
    public void handleClose() {
        System.out.println("JAVA: Client is now disconnected...");
    }

    @OnError
    public void handleError (Throwable t) {
        t.printStackTrace();
    }
}

当我使用http://myapp-myproject.rhcloud.com/mt URL连接到websocket时,WebSocket会连接。但是,当我为名为http://myapp-myproject.rhcloud.comhttps://someurl.com/mt设置别名时,websocket无法连接。为什么是这样?我在Google Chrome中收到以下错误消息: enter image description here

此外,websocket在端口8443使用wss连接。这是一个等同于https的安全请求。因此,它如何使用作为http网址的http://myapp-myproject.rhcloud.com/mt网址,为什么它不与别名连接?

非常感谢你的帮助!

0 个答案:

没有答案