public void closeAuthenticatedSession(String httpSessionId) { Set<WsSession> wsSessions = authenticatedSessions.remove(httpSessionId); if (wsSessions != null && !wsSessions.isEmpty()) { for (WsSession wsSession : wsSessions) { try { wsSession.close(AUTHENTICATED_HTTP_SESSION_CLOSED); } catch (IOException e) { // Any IOExceptions during close will have been caught and the // onError method called. } } } }
@Override public void close(CloseReason closeReason) throws IOException { doClose(closeReason, closeReason); }
/** * {@inheritDoc} * * Overridden to make it visible to other classes in this package. */ @Override protected void registerSession(Endpoint endpoint, WsSession wsSession) { super.registerSession(endpoint, wsSession); if (wsSession.isOpen() && wsSession.getUserPrincipal() != null && wsSession.getHttpSessionId() != null) { registerAuthenticatedSession(wsSession, wsSession.getHttpSessionId()); } }
/** * {@inheritDoc} * * Overridden to make it visible to other classes in this package. */ @Override protected void unregisterSession(Endpoint endpoint, WsSession wsSession) { if (wsSession.getUserPrincipal() != null && wsSession.getHttpSessionId() != null) { unregisterAuthenticatedSession(wsSession, wsSession.getHttpSessionId()); } super.unregisterSession(endpoint, wsSession); log.debug("unregisterSession: {} endpoint: {}", wsSession.getId(), endpoint); }
/** * {@inheritDoc} * * Overridden to make it visible to other classes in this package. */ @Override protected void unregisterSession(Endpoint endpoint, WsSession wsSession) { if (wsSession.getUserPrincipal() != null && wsSession.getHttpSessionId() != null) { unregisterAuthenticatedSession(wsSession, wsSession.getHttpSessionId()); } super.unregisterSession(endpoint, wsSession); }
wsSession.onClose(new CloseReason(Util.getCloseCode(code), reason)); } else if (opCode == Constants.OPCODE_PING) { if (wsSession.isOpen()) { wsSession.getBasicRemote().sendPong(controlBufferBinary); wsSession.getPongMessageHandler(); if (mhPong != null) { try { } catch (Throwable t) { ExceptionUtils.handleThrowable(t); wsSession.getLocal().onError(wsSession, t); } finally { controlBufferBinary.clear();
/** * Cleans up the resources still in use by WebSocket sessions created from * this container. This includes closing sessions and cancelling * {@link Future}s associated with blocking read/writes. */ public void destroy() { CloseReason cr = new CloseReason( CloseCodes.GOING_AWAY, sm.getString("wsWebSocketContainer.shutdown")); for (WsSession session : sessions.keySet()) { try { session.close(cr); } catch (IOException ioe) { log.debug(sm.getString( "wsWebSocketContainer.sessionCloseFail", session.getId()), ioe); } } }
httpSessionId = Optional.ofNullable(wsSession.getHttpSessionId()).orElse(wsSession.getId()); wsSession.getNegotiatedExtensions().forEach(extension -> { if (extensions == null) { extensions = new HashMap<>(); log.debug("extensions: {}", extensions); String queryString = wsSession.getQueryString(); log.debug("queryString: {}", queryString); if (StringUtils.isNotBlank(queryString)) { Map<String, String> pathParameters = wsSession.getPathParameters(); log.debug("pathParameters: {}", pathParameters); Map<String, Object> userProps = wsSession.getUserProperties(); log.debug("userProps: {}", userProps);
@Override public final void onMessage(T message, boolean last) { if (params.length == 1 && params[0] instanceof DecodeException) { ((WsSession) session).getLocal().onError(session, (DecodeException) params[0]); return; } Object[] parameters = params.clone(); if (indexBoolean != -1) { parameters[indexBoolean] = Boolean.valueOf(last); } if (indexSession != -1) { parameters[indexSession] = session; } if (convert) { parameters[indexPayload] = ((ByteBuffer) message).array(); } else { parameters[indexPayload] = message; } Object result; try { result = method.invoke(pojo, parameters); } catch (IllegalAccessException | InvocationTargetException e) { throw new IllegalArgumentException(e); } processResult(result); } }
sm.getString("wsHttpUpgradeHandler.serverStop")); try { wsSession.close(cr); } catch (IOException ioe) { onError(ioe); case ERROR: String msg = sm.getString("wsHttpUpgradeHandler.closeOnError"); wsSession.doClose(new CloseReason(CloseCodes.GOING_AWAY, msg), new CloseReason(CloseCodes.CLOSED_ABNORMALLY, msg));
try { wsRemoteEndpointServer = new WsRemoteEndpointImplServer(socketWrapper, webSocketContainer); wsSession = new WsSession(ep, wsRemoteEndpointServer, webSocketContainer, handshakeRequest.getRequestURI(), handshakeRequest.getParameterMap(),
protected void checkExpiration() { long timeout = maxIdleTimeout; if (timeout < 1) { return; } if (System.currentTimeMillis() - lastActive > timeout) { String msg = sm.getString("wsSession.timeout", getId()); if (log.isDebugEnabled()) { log.debug(msg); } doClose(new CloseReason(CloseCodes.GOING_AWAY, msg), new CloseReason(CloseCodes.CLOSED_ABNORMALLY, msg)); } }
@Override protected void sendMessageBinary(ByteBuffer msg, boolean last) throws WsIOException { ClassLoader cl = Thread.currentThread().getContextClassLoader(); try { Thread.currentThread().setContextClassLoader(applicationClassLoader); // set connection local to the message handler so WSMessage will contain the connection ((DefaultWebSocketEndpoint) wsSession.getLocal()).setConnectionLocal((WebSocketConnection) wsSession.getUserProperties().get(WSConstants.WS_CONNECTION)); // super! super.sendMessageBinary(msg, last); } finally { // clear thread local ((DefaultWebSocketEndpoint) wsSession.getLocal()).setConnectionLocal(null); Thread.currentThread().setContextClassLoader(cl); } }
private void sendMessageBlock(byte opCode, ByteBuffer payload, boolean last, long timeoutExpiry) throws IOException { wsSession.updateLastActive(); if (!messagePartInProgress.tryAcquire(timeout, TimeUnit.MILLISECONDS)) { String msg = sm.getString("wsRemoteEndpoint.acquireTimeout"); wsSession.doClose(new CloseReason(CloseCodes.GOING_AWAY, msg), new CloseReason(CloseCodes.CLOSED_ABNORMALLY, msg)); throw new SocketTimeoutException(msg); wsSession.doClose(new CloseReason(CloseCodes.GOING_AWAY, msg), new CloseReason(CloseCodes.CLOSED_ABNORMALLY, msg)); throw new IOException(msg, e); messagePartInProgress.release(); Throwable t = bsh.getSendResult().getException(); wsSession.doClose(new CloseReason(CloseCodes.GOING_AWAY, t.getMessage()), new CloseReason(CloseCodes.CLOSED_ABNORMALLY, t.getMessage())); throw new IOException (t);
private long getBlockingSendTimeout() { Object obj = wsSession.getUserProperties().get(Constants.BLOCKING_SEND_TIMEOUT_PROPERTY); Long userTimeout = null; if (obj instanceof Long) { userTimeout = (Long) obj; } if (userTimeout == null) { return Constants.DEFAULT_BLOCKING_SEND_TIMEOUT; } else { return userTimeout.longValue(); } }
protected void registerSession(Endpoint endpoint, WsSession wsSession) { if (!wsSession.isOpen()) { // The session was closed during onOpen. No need to register it. return; } synchronized (endPointSessionMapLock) { if (endpointSessionMap.size() == 0) { BackgroundProcessManager.getInstance().register(this); } Set<WsSession> wsSessions = endpointSessionMap.get(endpoint); if (wsSessions == null) { wsSessions = new HashSet<WsSession>(); endpointSessionMap.put(endpoint, wsSessions); } wsSessions.add(wsSession); } sessions.put(wsSession, wsSession); }
wsSession = new WsSession(ep, wsRemoteEndpointServer, webSocketContainer, handshakeRequest.getRequestURI(), handshakeRequest.getParameterMap(), handshakeRequest.getQueryString(), handshakeRequest.getUserPrincipal(), httpSessionId, negotiatedExtensions, subProtocol, pathParameters, secure, endpointConfig); wsFrame = new WsFrameServer(socketWrapper, wsSession, transformation, applicationClassLoader); wsSession.getUserProperties().put(WSConstants.WS_CONNECTION, conn);
sendFuture = wsSession.getAsyncRemote().sendBinary(ByteBuffer.wrap(buf)); wsSession.getBasicRemote().sendBinary(ByteBuffer.wrap(buf));
@Override public final void onMessage(T message, boolean last) { if (params.length == 1 && params[0] instanceof DecodeException) { ((WsSession) session).getLocal().onError(session, (DecodeException) params[0]); return; ThreadBindingListener tbl = ((WsSession) session).getThreadBindingListener(); ClassLoader old = Thread.currentThread().getContextClassLoader(); try { Thread.currentThread().setContextClassLoader(((WsSession)session).getClassLoader()); tbl.bind(); result = method.invoke(pojo, parameters);
/** * Returns the WsSession id associated with this connection. * * @return sessionId */ public String getSessionId() { return wsSession.getId(); }