javax.websocket.deploymentexception:在尝试部署到tomcat时,没有找到方法[onmessage]上存在的消息参数的解码器

xggvc2p6  于 2021-10-10  发布在  Java
关注(0)|答案(1)|浏览(1022)

我一直在使用netbeans ide开发我的网站,同时也使用内置于glassfish/tomcat服务器的netbeans,没有任何问题;但是,当我尝试将我的站点上载到托管服务器时,我在尝试部署时遇到了一个错误,我找不到有关该错误的详细信息,也不知道为什么会出现此错误。我使用的是aws风格的托管解决方案,我自己在服务器上安装和更新文件,而不是由托管提供商来完成这项工作。我得到的错误是:

SEVERE [http-nio-8080-exec-35] org.apache.catalina.core.StandardContext.startInternal Error during ServletContainerInitializer processing
javax.servlet.ServletException: javax.websocket.DeploymentException: No decoder was found for message parameters present on the method [onMessage] of class [WebsocketClass] that was annotated with OnMessage
    at org.apache.tomcat.websocket.server.WsSci.onStartup(WsSci.java:129)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5160)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
    at org.apache.catalina.manager.ManagerServlet.start(ManagerServlet.java:1386)
    at org.apache.catalina.manager.HTMLManagerServlet.start(HTMLManagerServlet.java:697)
    at org.apache.catalina.manager.HTMLManagerServlet.doPost(HTMLManagerServlet.java:218)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:652)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:733)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.apache.catalina.filters.CsrfPreventionFilter.doFilter(CsrfPreventionFilter.java:211)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.apache.catalina.filters.HttpHeaderSecurityFilter.doFilter(HttpHeaderSecurityFilter.java:126)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.apache.catalina.filters.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:109)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:669)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:143)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:698)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:364)
    at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:616)
    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:831)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1629)
    at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:748)
Caused by: javax.websocket.DeploymentException: No decoder was found for message parameters present on the method [onMessage] of class [WebsocketClass] that was annotated with OnMessage
    at org.apache.tomcat.websocket.pojo.PojoMethodMapping$MessageHandlerInfo.<init>(PojoMethodMapping.java:488)
    at org.apache.tomcat.websocket.pojo.PojoMethodMapping.<init>(PojoMethodMapping.java:139)
    at org.apache.tomcat.websocket.server.WsServerContainer.addEndpoint(WsServerContainer.java:155)
    at org.apache.tomcat.websocket.server.WsServerContainer.addEndpoint(WsServerContainer.java:280)
    at org.apache.tomcat.websocket.server.WsSci.onStartup(WsSci.java:126)
    ... 38 more

至于onmessage,这是方法头,

@OnMessage
public void onMessage(Session session,EndpointConfig config, String message, @PathParam("param") String name)

根据https://docs.oracle.com/javaee/7/api/javax/websocket/decoder.html
上面说 The lifecycle of the Decoder instance is governed by the container calls to the init(javax.websocket.EndpointConfig) and destroy() methods. 有了这个,我假设“endpointconfig”调用可能与解码器问题有关?
https://docs.oracle.com/javaee/7/api/javax/websocket/endpointconfig.html
我确实有几个例子使用base64解码器,但这是在另一个方法中使用的,该方法是从onmessage中调用的,但我认为这是与此不同的另一个方法。
我只是不确定为什么这个问题只源于1主机而不是其他主机,我也不知道如何处理这个问题。
除了使用netbeans ide中的内置服务器外,我还尝试使用另一个已安装的主机解决方案,该主机由公司自己管理,预先安装了tomcat,并使用c-panel。将站点部署到该tomcat示例似乎是可行的,因为部署时该服务器上的catalina.out文件中没有任何错误。
我想知道是否有人知道是什么导致了这个错误?我假设我在服务器上安装tomcat时可能弄错了什么,可能是server.xml文件的问题?我只是觉得奇怪,它与WebSocket有关,如果是这样的话,尽管。。。这就是我所能想到的netbeans内置服务器和托管托管解决方案与我管理的解决方案之间的区别。
非常感谢您的帮助,谢谢!

z9gpfhce

z9gpfhce1#

服务器正在抱怨服务器错误 EndpointConfig 参数,这是不允许的。你可以有:
最多一个参数来接收消息内容(参见类型列表的onmessagejavadoc)。默认情况下支持某些类型,对于其余类型,您需要 Decoder ,
倍数 @PathParam 注解 String 参数,
可选的 Session 参数
EndpointConfig 参数在签名中是允许的 @OnOpen 注解的方法,因此可能会产生混淆。

相关问题