@Override public void onClose(javax.websocket.Session session, javax.websocket.CloseReason closeCode) { logger.trace("{} closed {}", session, closeCode); if (request != null) { request.destroy(); webSocketProcessor.close(webSocket, closeCode.getCloseCode().getCode()); } }
.queryString(session.getQueryString()); if (!webSocketProcessor.handshake(request)) { try { session.close(new CloseReason(CloseReason.CloseCodes.CANNOT_ACCEPT, "Handshake not accepted.")); webSocketProcessor.open(webSocket, request, AtmosphereResponseImpl.newInstance(framework.getAtmosphereConfig(), request, webSocket));
@Override public void onError(javax.websocket.Session session, java.lang.Throwable t) { try { logger.debug("Problem in web socket session", t); webSocketProcessor.notifyListener(webSocket, new WebSocketEventListener.WebSocketEvent<Throwable>(t, WebSocketEventListener.WebSocketEvent.TYPE.EXCEPTION, webSocket)); } catch (Exception ex) { // Ignore completely // https://github.com/Atmosphere/atmosphere/issues/1758 } } }
@Override public void operationComplete(ChannelFuture future) throws Exception { if (!future.isSuccess()) { future.channel().close(); } else { websocketChannels.add(ctx.channel()); ctx.channel().attr(ATTACHMENT).set(webSocket); if (config.noInternalAlloc()) { webSocket.resource(proxiedResource); } AtmosphereResponse response = config.noInternalAlloc() ? proxiedResponse : AtmosphereResponseImpl.newInstance(framework.getAtmosphereConfig(), atmosphereRequest, webSocket); webSocketProcessor.open(webSocket, atmosphereRequest, response); if (webSocketTimeout > 0) { webSocket.closeFuture(suspendTimer.scheduleAtFixedRate(() -> { if (webSocket.lastWriteTimeStampInMilliseconds() != 0 && (System.currentTimeMillis() - webSocket.lastWriteTimeStampInMilliseconds() > webSocketTimeout)) { logger.debug("Timing out {}", webSocket); webSocket.close(); } }, webSocketTimeout, webSocketTimeout, TimeUnit.MILLISECONDS)); } } } });
private void handleString(String string) { this.webSocketProcessor.invokeWebSocketProtocol(this.playWebSocket, string); }
final AtmosphereRequest atmosphereRequest = createAtmosphereRequest(ctx, request, EMPTY); if (!webSocketProcessor.handshake(atmosphereRequest)) { sendError(ctx, HttpResponseStatus.BAD_REQUEST, null); return; webSocketProcessor.notifyListener(webSocket, new WebSocketEventListener.WebSocketEvent("", HANDSHAKE, webSocket));
public synchronized void destroy() { for (WebSocketProcessor processor : processors.values()) { processor.destroy(); } processors.clear(); }
private WebSocketProcessor createProcessor(AtmosphereFramework framework) { WebSocketProcessor processor = null; String webSocketProcessorName = framework.getWebSocketProcessorClassName(); if (!webSocketProcessorName.equalsIgnoreCase(DefaultWebSocketProcessor.class.getName())) { try { processor = framework.newClassInstance(WebSocketProcessor.class, (Class<WebSocketProcessor>) IOUtils.loadClass(getClass(), webSocketProcessorName)); } catch (Exception ex) { logger.error("Unable to create {}", webSocketProcessorName); processor = new DefaultWebSocketProcessor(); } } if (processor == null) { processor = new DefaultWebSocketProcessor(); } processor.configure(framework.getAtmosphereConfig()); return processor; } }
@Override public void operationComplete(ChannelFuture future) throws Exception { if (!future.isSuccess()) { future.channel().close(); } else { websocketChannels.add(ctx.channel()); ctx.channel().attr(ATTACHMENT).set(webSocket); if (config.noInternalAlloc()) { webSocket.resource(proxiedResource); } AtmosphereResponse response = config.noInternalAlloc() ? proxiedResponse : AtmosphereResponseImpl.newInstance(framework.getAtmosphereConfig(), atmosphereRequest, webSocket); webSocketProcessor.open(webSocket, atmosphereRequest, response); if (webSocketTimeout > 0) { webSocket.closeFuture(suspendTimer.scheduleAtFixedRate(() -> { if (webSocket.lastWriteTimeStampInMilliseconds() != 0 && (System.currentTimeMillis() - webSocket.lastWriteTimeStampInMilliseconds() > webSocketTimeout)) { logger.debug("Timing out {}", webSocket); webSocket.close(); } }, webSocketTimeout, webSocketTimeout, TimeUnit.MILLISECONDS)); } } } });
@Override public void handle(Buffer data) { webSocketProcessor.invokeWebSocketProtocol(w, data.toString()); } });
final AtmosphereRequest atmosphereRequest = createAtmosphereRequest(ctx, request, EMPTY); if (!webSocketProcessor.handshake(atmosphereRequest)) { sendError(ctx, HttpResponseStatus.BAD_REQUEST, null); return; webSocketProcessor.notifyListener(webSocket, new WebSocketEventListener.WebSocketEvent("", HANDSHAKE, webSocket));
void patchGlassFish(NullPointerException e) { // https://java.net/jira/browse/TYRUS-175 logger.trace("", e); WebSocketProcessorFactory.getDefault().getWebSocketProcessor(config().framework()).close(this, 1002); }
@Override public void preStart() { try { this.playWebSocket = new PlayWebSocket(actorRef, atmosphereConfig); this.webSocketProcessor = WebSocketProcessorFactory.getDefault().getWebSocketProcessor(atmosphereConfig.framework()); AtmosphereRequest atmosphereRequest = AtmosphereUtils.request(new Http.RequestImpl(requestHeader), additionalAttributes); this.webSocketProcessor.open(playWebSocket, atmosphereRequest, AtmosphereResponseImpl.newInstance(atmosphereConfig, atmosphereRequest, playWebSocket)); } catch (Throwable throwable) { LOG.error("Failed to start the actor ", throwable); } }
private void handleByteString(ByteString byteString) { this.webSocketProcessor.invokeWebSocketProtocol(this.playWebSocket, byteString.toString()); }
@Override public void postStop() { this.webSocketProcessor.close(playWebSocket, 1002); }
webSocketProcessor.invokeWebSocketProtocol(attachment, body, 0, body.length); } else if (frame instanceof TextWebSocketFrame) { webSocketProcessor.invokeWebSocketProtocol(attachment, ((TextWebSocketFrame) frame).text()); } else if (frame instanceof PongWebSocketFrame) {
@Override public void handle(Throwable event) { w.close(); logger.debug("", event); webSocketProcessor.close(w, 1006); } });
webSocketProcessor.invokeWebSocketProtocol(attachment, body, 0, body.length); } else if (frame instanceof TextWebSocketFrame) { webSocketProcessor.invokeWebSocketProtocol(attachment, ((TextWebSocketFrame) frame).text()); } else if (frame instanceof PongWebSocketFrame) {
@Override public void channelInactive(ChannelHandlerContext ctx) throws Exception { super.channelInactive(ctx); Object o = ctx.attr(ATTACHMENT).get(); if (o == null) return; if (WebSocket.class.isAssignableFrom(o.getClass())) { NettyWebSocket webSocket = NettyWebSocket.class.cast(o); logger.trace("Closing {}", webSocket.uuid()); try { if (webSocket.closeFuture() != null) { webSocket.closeFuture().cancel(true); } webSocketProcessor.close(webSocket, 1005); } catch (Exception ex) { logger.error("{}", webSocket, ex); } } else if (State.class.isAssignableFrom(o.getClass())) { logger.trace("State {}", o); State s = State.class.cast(o); if (s.action.type() == Action.TYPE.SUSPEND) { asynchronousProcessor.endRequest(s.resource(), true); } } else { logger.warn("Invalid state {} and Channel {}", o, ctx.channel()); } }