使用Tomcat 7的web套接字



我想使用web套接字,我开始寻找这样做与tomcat API。我现在使用的是Tomcat 7.0.37.

我尝试遵循tomcat文档中的示例代码。

我也在项目中使用maven,所以我将它添加到我的pom.xml:

<dependency>
    <groupId>org.apache.tomcat</groupId>
    <artifactId>tomcat-catalina</artifactId>
    <version>7.0.39</version>
    <scope>provided</scope>
</dependency>

首先奇怪的是,我在Eclipse中得到了这一行的错误消息:

private class MyMessageInbound extends MessageInbound

错误信息是" MyMessageInbound类型的层次结构不一致",但我仍然能够编译并启动web应用程序。

我还在web.xml中添加了如下配置:

<servlet>
    <servlet-name>wsChat</servlet-name>
    <servlet-class>websocket.chat.ChatWebSocketServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>wsChat</servlet-name>
    <url-pattern>/websocket/chat</url-pattern>
</servlet-mapping>

所以,我能够启动webapp,但是当我去聊天页面时,我在聊天板上得到一个错误,说"Info: WebSocket closed."。Tomcat日志给我以下消息:

SEVERE: Servlet.service() for servlet [wsChat] in context with path [/websocket-tuto] threw exception [L''exécution de la servlet a lancé une exception] with root cause
java.lang.NoSuchMethodError: websocket.chat.ChatWebSocketServlet$MyMessageInbound.<init>(Lwebsocket/chat/ChatWebSocketServlet;Luwebsocket/chat/ChatWebSocketServlet$MyMessageInbound;)V
at websocket.chat.ChatWebSocketServlet.createWebSocketInbound(ChatWebSocketServlet.java:34)
at org.apache.catalina.websocket.WebSocketServlet.doGet(WebSocketServlet.java:121)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

我认为这里唯一缺少的信息是聊天页面的来源。

谁知道我做错了什么吗?

谢谢

问题解决了!

我试图用Maven在命令行上打包项目,得到这个错误:

[ERROR] class file for org.apache.coyote.http11.upgrade.UpgradeInbound not found
从这里,我只添加了以下内容到pom.xml:
<dependency>
    <groupId>org.apache.tomcat</groupId>
    <artifactId>tomcat-coyote</artifactId>
    <version>7.0.39</version>
    <scope>provided</scope>
</dependency>

继承的类MessageInbound是否实现了Servlet接口?你能提供你的ChatWebSocketServlet或MessageInbound类的doGet实现吗?对不起,你的信息根本不完整……

相关内容

  • 没有找到相关文章

最新更新