gpt4 book ai didi

java - 在嵌入式Tomcat 8.0.3和tomcat 7.0.53之间建立websocket连接

转载 作者:行者123 更新时间:2023-11-28 23:36:01 26 4
gpt4 key购买 nike

我正在尝试用 Java 创建一个简单的 websocket 客户端。我有一个使用 springboot 的嵌入式 tomcat 8.0.3 服务器。客户端正在尝试连接到另一台运行 tomcat 7.0.53 的计算机上的服务器。但是,在尝试建立 websocket 后出现以下错误:

2014-07-02 11:13:56.861  INFO 13656 --- [nio-8085-exec-1] o.s.w.s.c.WebSocketConnectionManager     : Connecting to WebSocket at ws://54.213.202.109:8880/wspoc/ws/10

2014-07-02 11:14:01.885 ERROR 13656 --- [nio-8085-exec-1] o.s.w.s.c.WebSocketConnectionManager : Failed to connect

javax.websocket.DeploymentException: The HTTP request to initiate the WebSocket connection failed
at org.apache.tomcat.websocket.WsWebSocketContainer.connectToServer(WsWebSocketContainer.java:351)
at org.springframework.web.socket.client.standard.StandardWebSocketClient$1.call(StandardWebSocketClient.java:125)

at org.springframework.web.socket.client.standard.StandardWebSocketClient$1.call(StandardWebSocketClient.java:122)

at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at org.springframework.web.socket.client.standard.StandardWebSocketClient.doHandshakeInternal(StandardWebSocketClient.java:135)

at org.springframework.web.socket.client.AbstractWebSocketClient.doHandshake(AbstractWebSocketClient.java:100)
at org.springframework.web.socket.client.WebSocketConnectionManager.openConnection(WebSocketConnectionManager.java:139)

at org.springframework.web.socket.client.ConnectionManagerSupport.startInternal(ConnectionManagerSupport.java:129)

at org.springframework.web.socket.client.WebSocketConnectionManager.startInternal(WebSocketConnectionManager.java:122)

at org.springframework.web.socket.client.ConnectionManagerSupport.start(ConnectionManagerSupport.java:118)
at com.hp.fucms.impl.TopoRestController.test(TopoRestController.java:77)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:215)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)

at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)

at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:749)

at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:689)

at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:83)

at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:938)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:870)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:852)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:618)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:301)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:503)
at org.apache.catalina.valves.RemoteIpValve.invoke(RemoteIpValve.java:676)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:136)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:74)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:516)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1015)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:652)
at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:222)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1575)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1533)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)

这是我的客户端代码

            WebSocketClient client = new StandardWebSocketClient();
TopoWebSocketHandler handler = new TopoWebSocketHandler();
String pathId = "ws://54.213.202.109:8880/wspoc/ws/10";
WebSocketConnectionManager manager = new WebSocketConnectionManager(client, handler,pathId);
manager.start();

还有我的处理程序类:

public class TopoWebSocketHandler extends AbstractWebSocketHandler {private WebSocketSession session;

@Override
public void handleTextMessage(WebSocketSession session,
TextMessage message) throws Exception{

System.out.println("Message "+message.getPayload());

}

@Override
public void afterConnectionEstablished(WebSocketSession session) throws Exception{
session.sendMessage(new TextMessage("Hello"));
}
}

对于websockets,使用嵌入式服务器独立服务器是否存在一些问题?

最佳答案

我们将其解决为代理问题,该问题似乎与嵌入式服务器/独立服务器连接的性质无关。

关于java - 在嵌入式Tomcat 8.0.3和tomcat 7.0.53之间建立websocket连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24538517/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com