I'm trying to create what I thought was a very simple WebSocket example, but
boy have I had difficulties…
I started by basically coping the EchoAnnotation example from the Tomcat
examples. However, it was like my endpoint was never getting instantiated. (Is
this temporary? Will Tomcat 8 ultimately scan for and instantiate these
endpoints? Or will the server container always have to be created manually?)
I then noticed the listener that the examples application was using to
initialize the container and add the endpoints. I didn't want to tie my example
to the Tomcat classes, so I tried to do it a bit more generically based on the
WebSocket API. Below you will find the listener I created. It compiles just
fine, but on deployment I get the very unusual error further down. What's up
with this? Is this just an example of Tomcat being behind the RC1 API?
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;
import javax.websocket.server.ServerContainer;
import javax.websocket.server.ServerContainerProvider;
@WebListener
public class WebSocketInitializerListener implements ServletContextListener
{
@Override
public void contextInitialized(ServletContextEvent servletContextEvent)
{
try
{
ServerContainer container =
ServerContainerProvider.getServerContainer();
container.addEndpoint(EchoEndpoint.class);
}
catch (Exception e)
{
System.err.println(e.toString());
e.printStackTrace(System.err);
throw new RuntimeException("Could not start WebSocket container.");
}
}
@Override
public void contextDestroyed(ServletContextEvent servletContextEvent)
{
}
}
SEVERE: Exception sending context initialized event to listener instance of
class com.wrox.WebSocketInitializerListener
java.lang.IllegalAccessError: tried to access method
javax.websocket.server.ServerContainerProvider.getServerContainer()Ljavax/websocket/server/ServerContainer;
from class com.wrox.WebSocketInitializerListener
at
com.wrox.WebSocketInitializerListener.contextInitialized(WebSocketInitializerListener.java:17)
at
org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4769)
at
org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5210)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at
org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:726)
at
org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:702)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:698)
at
org.apache.catalina.startup.HostConfig.manageApp(HostConfig.java:1492)
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:487)
at
org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:300)
at
com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819)
at
com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:791)
at
org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:468)
at
org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:415)
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:487)
at
org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:300)
at
com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819)
at
com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:791)
at
javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1465)
at
javax.management.remote.rmi.RMIConnectionImpl.access$300(RMIConnectionImpl.java:75)
at
javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1306)
at
javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1398)
at
javax.management.remote.rmi.RMIConnectionImpl.invoke(RMIConnectionImpl.java:827)
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:487)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:322)
at sun.rmi.transport.Transport$1.run(Transport.java:177)
at sun.rmi.transport.Transport$1.run(Transport.java:174)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:173)
at
sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:556)
at
sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:811)
at
sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:670)
at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]