Example usage for javax.websocket CloseReason getReasonPhrase

List of usage examples for javax.websocket CloseReason getReasonPhrase

Introduction

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

Prototype

public String getReasonPhrase() 

Source Link

Usage

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 av a 2  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.inbound.SubscriptionEndpoint.java

/**
 * Web socket onClose - Remove the registered sessions
 *
 * @param session      - Users registered session.
 * @param reason       - Status code for web-socket close.
 * @param streamName   - StreamName extracted from the ws url.
 * @param version      - Version extracted from the ws url.
 * @param tenantDomain - Domain of the tenant.
 *//*from   w w  w .j  a v  a 2s .c  om*/
public void onClose(Session session, CloseReason reason, String streamName, String version,
        String tenantDomain) {
    if (log.isDebugEnabled()) {
        log.debug("Closing a WebSocket due to " + reason.getReasonPhrase() + ", for session ID:"
                + session.getId() + ", for request URI - " + session.getRequestURI());
    }
    for (AnalyticsClient analyticsClient : analyticsClientsMap.get(session.getId())) {
        if (analyticsClient != null) {
            try {
                analyticsClient.closeConnection(reason);
            } catch (WSProxyException e) {
                log.error("Error occurred while closing ws connection due to " + reason.getReasonPhrase()
                        + ", for session ID:" + session.getId() + ", for request URI - "
                        + session.getRequestURI(), e);
            }
        }
    }
    analyticsClientsMap.remove(session.getId());
}

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 a  v  a2  s .c om
@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.device.mgt.extensions.remote.session.endpoint.SubscriptionEndpoint.java

/**
 * Web socket onClose use to handle  socket connection close
 *
 * @param session    - Registered  session.
 * @param deviceType - DeviceType/*from  w ww  .  j  a  v  a  2  s  .  c o  m*/
 * @param deviceId   - Device Identifier
 * @param reason     - Status code for web-socket close.
 */
public void onClose(Session session, CloseReason reason, @PathParam("deviceType") String deviceType,
        @PathParam("deviceId") String deviceId) {

    ServiceHolder.getInstance().getRemoteSessionManagementService().endSession(session,
            "Remote session closed");
    if (log.isDebugEnabled()) {
        log.debug("websocket closed due to " + reason.getReasonPhrase() + ", for session ID:" + session.getId()
                + ", for request URI - " + session.getRequestURI() + " device type: " + deviceType + " device "
                + "id: " + deviceId);
    }

}

From source file:org.wso2.carbon.device.mgt.output.adapter.websocket.endpoint.SubscriptionEndpoint.java

/**
 * Web socket onClose - Remove the registered sessions
 *
 * @param session    - Users registered session.
 * @param reason     - Status code for web-socket close.
 * @param streamName - StreamName extracted from the ws url.
 * @param version    - Version extracted from the ws url.
 *//*from  w w w  .  ja va2  s.c o  m*/
public void onClose(Session session, CloseReason reason, String streamName, String version) {
    if (log.isDebugEnabled()) {
        log.debug("Closing a WebSocket due to " + reason.getReasonPhrase() + ", for session ID:"
                + session.getId() + ", for request URI - " + session.getRequestURI());
    }
    ServiceHolder.getInstance().getWebsocketOutputCallbackControllerService().unsubscribeWebsocket(streamName,
            version, session);
}

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 ww .  j  a v  a  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);
    }
}