I have written a client program that connects to my websocket on the server. I set up tomcat8 with the examples working and hit the EchoAnnotation endpoint with my client program.
I wrote this endpoint program as follows:
@ServerEndpoint(value = "/websocket") public class PortServer implements AirMessageListener { public PortServer() { } @OnOpen public void start(Session session) { //do stuff } @OnClose public void end() { //do stuff } } @OnMessage public void incoming(String message) { //do stuff } @OnError public void onError(Throwable tw) throws Throwable { //do stuff } I compile this and create a war file called portserver and drop it into my tomcat webapps directory. I then switched my client program from connecting to: ws://localhost:8080/examples/websocket/echoAnnotation to ws://localhost:8080/portserver/websocket and run it. I get:
Connecting to:ws://localhost:8080/portserver/websocket Exception in thread "main" com.corrisoft.air.exception.AirException: Error connecting to server at com.corrisoft.air.socket.AirSocketClient.<init>(AirSocketClient.java:60) at test.corrisoft.air.portserver.SocketConversation.<init>(SocketConversation.java:46) at test.corrisoft.air.portserver.RunPortServerTester.initConfigProperties(RunPortServerTester.java:76) at test.corrisoft.air.portserver.RunPortServerTester.<init>(RunPortServerTester.java:34) at test.corrisoft.air.portserver.RunPortServerTester.main(RunPortServerTester.java:109) Caused by: javax.websocket.DeploymentException: Handshake error. at org.glassfish.tyrus.client.ClientManager$1$1.run(ClientManager.java:466) at org.glassfish.tyrus.client.ClientManager$1.run(ClientManager.java:502) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at org.glassfish.tyrus.client.ClientManager$SameThreadExecutorService.execute(ClientManager.java:654) at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:112) at org.glassfish.tyrus.client.ClientManager.connectToServer(ClientManager.java:359) at org.glassfish.tyrus.client.ClientManager.connectToServer(ClientManager.java:195) at com.corrisoft.air.socket.AirSocketClient.<init>(AirSocketClient.java:58) ... 4 more Caused by: org.glassfish.tyrus.core.HandshakeException: Response code was not 101: 404. at org.glassfish.tyrus.core.Handshake.validateServerResponse(Handshake.java:279) at org.glassfish.tyrus.client.TyrusClientEngine.processResponse(TyrusClientEngine.java:138) at org.glassfish.tyrus.container.grizzly.client.GrizzlyClientFilter.handleHandshake(GrizzlyClientFilter.java:318) at org.glassfish.tyrus.container.grizzly.client.GrizzlyClientFilter.handleRead(GrizzlyClientFilter.java:288) at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119) at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:291) at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:209) at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:137) at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:115) at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77) at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:550) at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112) at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117) at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56) at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137) at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:565) at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:545) at java.lang.Thread.run(Thread.java:744) I placed an index.html inside my portserver app and can hit: http://localhost:8080/portserver just fine, which means the directories are OK. I then verified that my class was in my WEB-INF/classes directory.
I looked at the examples and found the ExamplesConfig class that I thought might be a "magic" class that enables the endpoints, so I implemented my own and and stuck in the jar file.
/** * */ package com.corrisoft.air.portserver; import java.util.HashSet; import java.util.Set; import javax.websocket.Endpoint; import javax.websocket.server.ServerApplicationConfig; import javax.websocket.server.ServerEndpointConfig; /** * @author Corrisoft Android Development */ public class WebSocketConfig implements ServerApplicationConfig { /* (non-Javadoc) * @see javax.websocket.server.ServerApplicationConfig#getAnnotatedEndpointClasses(java.util.Set) */ @Override public Set<Class<?>> getAnnotatedEndpointClasses(Set<Class<?>> scanned) { // Deploy all WebSocket endpoints defined by annotations in the // web application. Filter out all others to avoid issues when running // tests on Gump Set<Class<?>> results = new HashSet<>(); for (Class<?> clazz : scanned) { if (clazz.getPackage().getName().startsWith("com.corrisoft.air")) { System.out.println("Adding endpoint for:" + clazz.getName()); results.add(clazz); } } return results; } /* (non-Javadoc) * @see javax.websocket.server.ServerApplicationConfig#getEndpointConfigs(java.util.Set) */ @Override public Set<ServerEndpointConfig> getEndpointConfigs( Set<Class<? extends Endpoint>> scanned) { return null; } } It does not seem to be running this class.
Is there some configuration I missed?