websockets是否可以在cloudbees上使用tomcat7?

时间:2013-03-04 19:39:28

标签: websocket tomcat7 cloudbees

Cloudbees现在支持websockets:http://wiki.cloudbees.com/bin/view/RUN/WebSockets

我尝试使用tomcat7 clickStack

在cloudbees上实现一个非常简单的测试

您可以在此处看到尝试打开此websocket的网页:http://wstest.ws.cloudbe.es/

这适用于我的机器,但不适用于RUN @ cloud

我错过了什么吗? tomcat7 clickStack不支持websockets?

提前致谢。

我的Servlet:

import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;

import org.apache.catalina.websocket.MessageInbound;
import org.apache.catalina.websocket.StreamInbound;
import org.apache.catalina.websocket.WebSocketServlet;
import org.apache.catalina.websocket.WsOutbound;

@WebServlet(urlPatterns = "/testWebsocket")
public class TestWebsocket extends WebSocketServlet {

    private static final long serialVersionUID = 1L;

    @Override
    protected StreamInbound createWebSocketInbound(String string, HttpServletRequest hsr) {
        return new MessageInbound() {
            @Override
            protected void onOpen(WsOutbound outbound) {
                super.onOpen(outbound);
            }

            @Override
            protected void onClose(int status) {
                super.onClose(status);
            }

            @Override
            protected void onBinaryMessage(ByteBuffer bb) throws IOException {
            }

            @Override
            protected void onTextMessage(CharBuffer cb) throws IOException {
                System.out.println(cb.toString());
                WsOutbound outbound = getWsOutbound();
                outbound.writeTextMessage(CharBuffer.wrap((cb.toString()).toCharArray()));
            }
        };
    }

}

1 个答案:

答案 0 :(得分:0)

我从未尝试过这种组合,但是afaik应该可行。您是否在http 1.1模式下配置了路由器?