tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Daniel Mikusa <dmik...@gopivotal.com>
Subject Tomcat 8 WebSocket Encoders / Decoders Questions
Date Wed, 16 Oct 2013 15:36:35 GMT
I have a simple WebSocket endpoint defined, it is just echoing the data sent by the client.
 Here's the code.

@ServerEndpoint(value="/websocket",
            decoders={ListStringDecoder.class},
            encoders={ListStringEncoder.class})
public static class Server {
        @OnMessage
        public List<String> rx(List<String> in) {
            return in;
        }
}

As you can see by the endpoint annotation, I'm defining an encoder and decoder.  Here's the
code for that.

    public static class ListStringEncoder implements Encoder.Text<List<String>>
{

        @Override
        public void init(EndpointConfig endpointConfig) {
        }

        @Override
        public void destroy() {
        }

        @Override
        public String encode(List<String> list) throws EncodeException {
            return list.toString();
        }
    }

    public static class ListStringDecoder implements Decoder.Text<List<String>>
{

        @Override
        public void init(EndpointConfig endpointConfig) {
        }

        @Override
        public void destroy() {
        }

        @Override
        public List<String> decode(String data) throws DecodeException {
        	List<String> tmp = new ArrayList<String>();
        	for (String str : data.substring(1, data.length() - 1).split(",")) {
        		tmp.add(str);
        	}
        	return tmp;
        }

        @Override
        public boolean willDecode(String s) {
            return s.startsWith("[") && s.endsWith("]");
        }
    }

Now when I run this, I get the following exception as Tomcat starts up.

16-Oct-2013 11:29:40.311 SEVERE [localhost-startStop-1] org.apache.catalina.core.StandardContext.listenerStart
Exception sending context initialized event to listener instance of class org.apache.tomcat.websocket.pojo.TesterUtil$ServerConfigListener
 java.lang.NullPointerException
	at org.apache.tomcat.websocket.Util$DecoderMatch.<init>(Util.java:428)
	at org.apache.tomcat.websocket.pojo.PojoMethodMapping$MessageHandlerInfo.<init>(PojoMethodMapping.java:396)
	at org.apache.tomcat.websocket.pojo.PojoMethodMapping.<init>(PojoMethodMapping.java:114)
	at org.apache.tomcat.websocket.server.WsServerContainer.addEndpoint(WsServerContainer.java:194)
	at org.apache.tomcat.websocket.pojo.TesterUtil$ServerConfigListener.contextInitialized(TesterUtil.java:45)
	at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4830)
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5276)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1390)
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1)
	at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
	at java.util.concurrent.FutureTask.run(FutureTask.java:166)
	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:724)

If I change my encoder & decoder to use "List" rather than "List<String>" everything
works fine.

Any thoughts on what's going on here?

Thanks

Dan


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Mime
View raw message