対向のサーバが落ちているとき。
素直にハンドシェイクできないという。まぁ、そのまんま。
7 20, 2013 5:43:29 午後 jp.co.epea.firstfxclient.SampleController$TwitterCheckService$1 call
SEVERE: null
javax.websocket.DeploymentException: Handshake response not received.
at org.glassfish.tyrus.client.ClientManager.connectToServer(ClientManager.java:300)
at org.glassfish.tyrus.client.ClientManager.connectToServer(ClientManager.java:172)
at jp.co.epea.firstfxclient.SampleController$TwitterCheckService$1.call(SampleController.java:65)
at jp.co.epea.firstfxclient.SampleController$TwitterCheckService$1.call(SampleController.java:1)
at javafx.concurrent.Task$TaskCallable.call(Task.java:1259)
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)
URI clientURI = new URI(“ws://localhost:8080/first/hellohoge/”);
みたいにURLが間違っている場合。
Handshake errorというやつとスタックとレースにレスポンスコードが返ってくる。
この例だと存在しないパスなので404が返っているけど、WebsocketじゃないただのHTMLだとUpdate Protocolの時に失敗しているので(?)200が返ってくる。
なお、パスの指定時は最後の”/(スラッシュ)”も厳密に見る模様。
7 20, 2013 8:46:51 午後 jp.co.epea.firstfxclient.SampleController$TwitterCheckService$1 call
SEVERE: null
javax.websocket.DeploymentException: Handshake error.
at org.glassfish.tyrus.client.ClientManager.connectToServer(ClientManager.java:285)
at org.glassfish.tyrus.client.ClientManager.connectToServer(ClientManager.java:172)
at jp.co.epea.firstfxclient.SampleController$TwitterCheckService$1.call(SampleController.java:65)
at jp.co.epea.firstfxclient.SampleController$TwitterCheckService$1.call(SampleController.java:1)
at javafx.concurrent.Task$TaskCallable.call(Task.java:1259)
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)
Caused by: org.glassfish.tyrus.websockets.HandshakeException: Response code was not 101: 404
at org.glassfish.tyrus.websockets.HandShake.validateServerResponse(HandShake.java:314)
at org.glassfish.tyrus.websockets.draft06.HandShake06.validateServerResponse(HandShake06.java:98)
at org.glassfish.tyrus.container.grizzly.WebSocketFilter.handleClientHandShake(WebSocketFilter.java:368)
at org.glassfish.tyrus.container.grizzly.WebSocketFilter.handleHandshake(WebSocketFilter.java:353)
at org.glassfish.tyrus.container.grizzly.WebSocketFilter.handleRead(WebSocketFilter.java:274)
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:288)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:206)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:136)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:114)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:837)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:113)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:115)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:55)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:135)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:565)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:545)
... 1 more
Connection had closed.
ちなみに、エラーログをはいているのはSampleController#createTaskの中にあるキャッチ節。
@Override
protected Task createTask() {
Task<Void> task = new Task<Void>() {
@Override
protected Void call() throws Exception {
messageLatch = new CountDownLatch(1);
try {
URI clientURI = new URI("ws://localhost:8080/first/hellohoge/");
ClientManager cliContainer = org.glassfish.tyrus.client.ClientManager.createClient();
cliContainer.connectToServer(new TwitterClient(table), clientURI);
messageLatch.await(1, TimeUnit.SECONDS);
} catch (DeploymentException | URISyntaxException | InterruptedException ex) {
Logger.getLogger(SampleController.class.getName()).log(Level.SEVERE, null, ex);
}
return null;
}
};
return task;
}
下の@OnErrorは通らずに、@OnClose(前のログだと緑字部分)で終わるので注意。
@OnClose
public void closeConnection(Session session) {
System.out.println("Connection had closed.");
}
@OnError
public void onError(Session session,Throwable t) {
System.out.println("error");
t.printStackTrace();
}
javafx.concurrent.Taskの使い方次第でもっとハンドリングできそうな気がする。
とりあえず参考になりそうなサイト