Example usage for javax.websocket CloseReason getCloseCode

List of usage examples for javax.websocket CloseReason getCloseCode

Introduction

In this page you can find the example usage for javax.websocket CloseReason getCloseCode.

Prototype

public CloseCode getCloseCode() 

Source Link

Usage

From source file:com.almende.eve.transport.ws.WebsocketTransport.java

/**
 * On close./*ww w.j  a v  a2 s. co m*/
 * 
 * @param session
 *            the session
 * @param closeReason
 *            the close reason
 */
public void onClose(final Session session, final CloseReason closeReason) {
    LOG.info("Connection closed:" + closeReason.getReasonPhrase() + "(" + closeReason.getCloseCode().getCode()
            + ":" + closeReason.getCloseCode().toString() + ")");
    setConnected(false);
}

From source file:cito.server.AbstractEndpoint.java

@OnClose
@Override/*from   ww w. ja  v a2 s .com*/
public void onClose(Session session, CloseReason reason) {
    this.log.info("WebSocket connection closed. [id={},principle={},code={},reason={}]", session.getId(),
            session.getUserPrincipal(), reason.getCloseCode(), reason.getReasonPhrase());
    final WebSocketContext ctx = webSocketContext(this.beanManager);
    try (QuietClosable c = ctx.activate(session)) {
        this.registry.unregister(session);
        this.sessionEvent.select(cito.annotation.OnClose.Literal.onClose()).fire(session);
    }
    ctx.dispose(session);
}

From source file:org.axonframework.commandhandling.distributed.websockets.WebsocketCommandBusConnectorClient.java

@Override
public void onClose(Session session, CloseReason closeReason) {
    if (closeReason.getCloseCode() != CloseReason.CloseCodes.NORMAL_CLOSURE) {
        LOGGER.warn("Session closed because " + closeReason.getReasonPhrase());
    }/*w w  w  .j  av  a  2  s.c o  m*/
    try {
        sessions.invalidateObject(session);
        repository.cancelCallbacks(session.getId());
    } catch (Exception e) {
        LOGGER.error("Could not invalidate session", e);
    }
}

From source file:org.springframework.web.socket.adapter.standard.StandardWebSocketHandlerAdapter.java

@Override
public void onClose(javax.websocket.Session session, CloseReason reason) {
    CloseStatus closeStatus = new CloseStatus(reason.getCloseCode().getCode(), reason.getReasonPhrase());
    try {//from  w  w w.  ja  v a2 s . com
        this.handler.afterConnectionClosed(this.wsSession, closeStatus);
    } catch (Throwable ex) {
        if (logger.isWarnEnabled()) {
            logger.warn("Unhandled on-close exception for " + this.wsSession, ex);
        }
    }
}

From source file:org.springframework.web.socket.adapter.StandardEndpointAdapter.java

@Override
public void onClose(javax.websocket.Session session, CloseReason reason) {
    CloseStatus closeStatus = new CloseStatus(reason.getCloseCode().getCode(), reason.getReasonPhrase());
    try {/*from ww w  .j a  v  a2 s. c om*/
        this.handler.afterConnectionClosed(this.wsSession, closeStatus);
    } catch (Throwable t) {
        logger.error("Unhandled error for " + this.wsSession, t);
    }
}

From source file:org.wso2.carbon.device.mgt.analytics.wsproxy.outbound.AnalyticsClient.java

/**
 * Callback hook for Connection close events.
 *
 * @param userSession the analyticsSession which is getting closed.
 * @param reason      the reason for connection close
 *///from w w w.  j ava  2 s .  c  o m
@OnClose
public void onClose(Session userSession, CloseReason reason) {
    if (log.isDebugEnabled()) {
        log.debug("Closing web socket session: '" + userSession.getId() + "'. Code: "
                + reason.getCloseCode().toString() + " Reason: " + reason.getReasonPhrase());
    }
}

From source file:org.wso2.carbon.identity.agent.outbound.server.UserStoreServerEndpoint.java

@OnClose
public void onClose(@PathParam("node") String node, CloseReason closeReason, Session session) {

    Boolean isOnCloseNeeded = this.isOnCloseNeededMap.get(session.getId());
    if (isOnCloseNeeded != null && !isOnCloseNeeded) {
        isOnCloseNeededMap.remove(session.getId());
        return;//from w w  w.  j  ava 2 s.c  o m
    }

    TokenMgtDao tokenMgtDao = new TokenMgtDao();
    AccessToken accessToken = tokenMgtDao
            .getAccessToken(getAccessTokenFromUserProperties(session.getUserProperties()));

    LOGGER.info("Connection close triggered with status code : " + closeReason.getCloseCode().getCode()
            + " On reason " + closeReason.getReasonPhrase() + " from " + node + " in tenant "
            + accessToken.getTenant());
    if (accessToken != null) {
        serverHandler.removeSession(accessToken.getTenant(), accessToken.getDomain(), session);
        AgentMgtDao agentMgtDao = new AgentMgtDao();
        agentMgtDao.updateConnection(accessToken.getId(), node, serverNode,
                UserStoreConstants.CLIENT_CONNECTION_STATUS_CONNECTION_FAILED);
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Connection close for tenant: " + accessToken.getTenant());
        }
        String msg = "Client : " + node + " from " + accessToken.getTenant()
                + " disconnected from server node: " + serverNode;
        LOGGER.info(msg);
    }
}