Question

I am trying to deploy WebSockets on tomcat 7.0.50. following is my code

 @ServerEndpoint(value="/ws/fileuploadtracker/")
 public class FileUploadTrackerEndPoint{

@OnOpen
public void onOpen(Session session) {
    .....
}
@OnMessage
public void onMessage(Session session, String msg) {
    try {
        session.getBasicRemote().sendText(msg);
    } catch (IOException e) {
        logger.error(e.getMessage());
    }
}

} I picked above code from oracles' notes on javaee's websocket example from the link: http://docs.oracle.com/javaee/7/tutorial/doc/websocket004.htm My tomcat fails to start with following exception :

   SEVERE: Error during ServletContainerInitializer processing
   javax.servlet.ServletException: javax.websocket.DeploymentException: A parameter of          type [interface javax.websocket.Session] was found on method[onOpen] of class [java.lang.reflect.Method] that did not have a @PathParam annotation
at org.apache.tomcat.websocket.server.WsSci.onStartup(WsSci.java:146)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5444)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
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)
 Caused by: javax.websocket.DeploymentException: A parameter of type [interface javax.websocket.Session] was found on method[onOpen] of class [java.lang.reflect.Method] that did not have a @PathParam annotation
at org.apache.tomcat.websocket.pojo.PojoMethodMapping.getPathParams(PojoMethodMapping.java:233)
at org.apache.tomcat.websocket.pojo.PojoMethodMapping.<init>(PojoMethodMapping.java:122)
at org.apache.tomcat.websocket.server.WsServerContainer.addEndpoint(WsServerContainer.java:239)
at org.apache.tomcat.websocket.server.WsSci.onStartup(WsSci.java:143)
... 8 more

1) How am I supposed to configure server end points as annotated class on tomcat 7. 2) IS there any tomcat specific way to write annotated server endpoints? 3)if tomcat implements JSR356 why does not it support above config?

I tried hard to find a suitable example but couldn't. I also tried putting @pathparam annotation but it only acepts strings and throws classcastexception.

Était-ce utile?

La solution 2

I was using 1.b09 api. changed it to 1.0. lesson learnt : always go for stable versions and not beta ones

Autres conseils

It's also possible you used the wrong @PathParam, make sure you use:

import javax.websocket.server.PathParam;

and not:

import javax.ws.rs.PathParam;
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top