Example usage for javax.websocket EndpointConfig getUserProperties

List of usage examples for javax.websocket EndpointConfig getUserProperties

Introduction

In this page you can find the example usage for javax.websocket EndpointConfig getUserProperties.

Prototype

Map<String, Object> getUserProperties();

Source Link

Usage

From source file:com.websocket.WebSocketNewAnn.java

/**
 * WebSocket//from   w ww.  j  a  va2s. c o m
 * 
 * @param userSession
 * @param config
 * @throws IOException
 * @throws Exception
 */
@OnOpen
public void onOpen(Session userSession, EndpointConfig config) throws IOException, Exception {
    this.httpSession = (HttpSession) config.getUserProperties().get(HttpSession.class.getName());
    UserHeader loginInfo = (UserHeader) httpSession.getAttribute("LoginInfo");
    int userID = loginInfo.getUserID();

    //??httpSession
    userSessions.put(userID, userSession);
}

From source file:freddo.dtalk2.broker.servlet.DTalkServerEndpoint.java

@OnOpen
public void onOpen(Session session, EndpointConfig config) {
    LOG.trace(">>> onOpen: {}, userProperties: {}", session.getId(), config.getUserProperties());

    mConfig = config;/*from   w  w w.  j a  va 2 s. co  m*/
    mSession = session;

    if (LOG.isDebugEnabled()) {
        HandshakeRequest req = getHandshakeRequest();
        HttpSession httpSession = (HttpSession) req.getHttpSession();
        LOG.debug("=================================");
        LOG.debug("QueryString   : {}", req.getQueryString());
        LOG.debug("RequestURI    : {}", req.getRequestURI());
        LOG.debug("Headers       : {}", req.getHeaders());
        LOG.debug("UserPrincipal : {}", req.getUserPrincipal());
        LOG.debug("ParameterMap  : {}", req.getParameterMap());
        LOG.debug("=================================");
        if (httpSession != null) {
            Enumeration<String> e = httpSession.getAttributeNames();
            while (e.hasMoreElements()) {
                final String attr = e.nextElement();
                LOG.debug("Session[{}]: {}", attr, httpSession.getAttribute(attr));
            }
            LOG.debug("=================================");
        }
    }

    // TODO register connection & notify context listener

}

From source file:hr.ws4is.websocket.WebSocketEndpoint.java

public final void onOpen(final Session session, final EndpointConfig config) {

    try {//  w ww  .  j  a v  a2s  .  c om
        final HttpSession httpSession = (HttpSession) config.getUserProperties()
                .get(HttpSession.class.getName());
        final WebSocketSession wsession = new WebSocketSession(session, httpSession);

        session.getUserProperties().put(WS4ISConstants.WEBSOCKET_PATH,
                config.getUserProperties().get(WS4ISConstants.WEBSOCKET_PATH));

        websocketContextThreadLocal.set(wsession);
        webSocketEvent.fire(new WebsocketEvent(wsession, WebSocketEventStatus.START));

        if (!wsession.isValidHttpSession()) {
            LOGGER.error(WS4ISConstants.HTTP_SEESION_REQUIRED);
            final IllegalStateException ise = new IllegalStateException(WS4ISConstants.HTTP_SEESION_REQUIRED);
            final WebSocketResponse wsResponse = getErrorResponse(ise);
            final String responseString = JsonDecoder.getJSONEngine().writeValueAsString(wsResponse);
            session.close(new CloseReason(CloseCodes.VIOLATED_POLICY, responseString));
        }

    } catch (IOException exception) {
        LOGGER.error(exception.getMessage(), exception);
    } finally {
        websocketContextThreadLocal.remove();
    }

}

From source file:cito.server.AbstractEndpoint.java

@OnOpen
@Override/*from   www .  j  a va2s .  c o m*/
public void onOpen(Session session, EndpointConfig config) {
    final String httpSessionId = session.getRequestParameterMap().get("httpSessionId").get(0);
    this.log.info("WebSocket connection opened. [id={},httpSessionId={},principle={}]", session.getId(),
            httpSessionId, session.getUserPrincipal());
    final SecurityContext securityCtx = WebSocketConfigurator.removeSecurityContext(config.getUserProperties(),
            httpSessionId);
    SecurityContextProducer.set(session, securityCtx);
    try (QuietClosable c = webSocketContext(this.beanManager).activate(session)) {
        this.registry.register(session);
        this.sessionEvent.select(cito.annotation.OnOpen.Literal.onOpen()).fire(session);
    }

    this.rttService.start(session);
}

From source file:com.ec2box.manage.socket.SecureShellWS.java

@OnOpen
public void onOpen(Session session, EndpointConfig config) {

    //set websocket timeout
    if (StringUtils.isNotEmpty(AppConfig.getProperty("websocketTimeout"))) {
        session.setMaxIdleTimeout(Long.parseLong(AppConfig.getProperty("websocketTimeout")) * 60000);
    } else {/*from   w w w. j a  v  a  2  s.c  om*/
        session.setMaxIdleTimeout(0);
    }

    this.httpSession = (HttpSession) config.getUserProperties().get(HttpSession.class.getName());
    this.sessionId = AuthUtil.getSessionId(httpSession);
    this.session = session;

    Runnable run = new SentOutputTask(sessionId, session, UserDB.getUser(AuthUtil.getUserId(httpSession)));
    Thread thread = new Thread(run);
    thread.start();

}

From source file:io.hops.hopsworks.api.zeppelin.socket.NotebookServer.java

@OnOpen
public void open(Session conn, EndpointConfig config, @PathParam("projectID") String projectId)
        throws GenericException {
    try {/*w w  w  . ja  v  a2  s  .  c  o m*/
        this.session = conn;
        this.sender = (String) config.getUserProperties().get("user");
        this.project = getProject(projectId);
        authenticateUser(conn, this.project, this.sender);
        if (this.userRole == null) {
            LOG.log(Level.INFO, "User not authorized for Zeppelin Access: {0}", this.sender);
            return;
        }
        if (project.getPaymentType().equals(PaymentType.PREPAID)) {
            YarnProjectsQuota projectQuota = yarnProjectsQuotaFacade.findByProjectName(project.getName());
            if (projectQuota == null || projectQuota.getQuotaRemaining() < 0) {
                session.close(new CloseReason(CloseReason.CloseCodes.NORMAL_CLOSURE,
                        "This project is out of credits."));
                return;
            }
        }
        this.impl = notebookServerImplFactory.getNotebookServerImps(project.getName(), conn);
        if (impl.getConf() == null) {
            impl.removeConnectedSockets(conn, notebookServerImplFactory);
            LOG.log(Level.INFO, "Could not create Zeppelin config for user: {0}, project: {1}",
                    new Object[] { this.sender, project.getName() });
            return;
        }
        addUserConnection(this.hdfsUsername, conn);
        addUserConnection(project.getProjectGenericUser(), conn);
        this.session.getUserProperties().put("projectID", this.project.getId());
        String httpHeader = (String) config.getUserProperties().get(WatcherSecurityKey.HTTP_HEADER);
        this.session.getUserProperties().put(WatcherSecurityKey.HTTP_HEADER, httpHeader);
        impl.unicast(new Message(OP.CREATED_SOCKET), conn);
    } catch (IOException | RepositoryException | TaskRunnerException ex) {
        throw new GenericException(RESTCodes.GenericErrorCode.UNKNOWN_ERROR, Level.SEVERE, null,
                ex.getMessage(), ex);
    }
}

From source file:org.dicen.recolnat.services.configuration.Authentication.java

public static String authenticate(EndpointConfig conf) {
    switch (Authentication.authenticationMethod) {
    case 0:/*from   www.j  a  v a  2  s .c o m*/
        log.error("Authentication not configured");
        return null;
    case 1:
        throw new NotImplementedException();
    case 2:
        return Authentication.authenticateWithCAS(conf.getUserProperties());
    default:
        log.error("Authentication method unknown " + authenticationMethod);
        return null;
    }
}

From source file:pt.webdetails.cda.push.CdaPushQueryEndpoint.java

/**
 * This method is called whenever a client creates a new websocket connection to the URL registered to
 * this endpoint./*  w ww.  jav a 2s .  co  m*/
 *
 * @param session the websocket session.
 * @param endpointConfig the endpoint configuration.
 */
@Override
public void onOpen(Session session, EndpointConfig endpointConfig) {
    PentahoRequestContextHolder.setRequestContext(() -> (String) endpointConfig.getUserProperties()
            .get(WebsocketEndpointConfig.getInstanceToReadProperties().getServletContextPathPropertyName()));
    IPentahoRequestContext requestContext = PentahoRequestContextHolder.getRequestContext();

    this.queryHandler = new CdaPushQueryMessageHandler(session, requestContext);
    this.queryHandler.getWebsocketJsonQueryEndpoint().onOpen(null);

    session.setMaxTextMessageBufferSize(Integer.parseInt(endpointConfig.getUserProperties()
            .get(WebsocketEndpointConfig.getInstanceToReadProperties().getMaxMessagePropertyName())
            .toString()));
    session.setMaxBinaryMessageBufferSize(Integer.parseInt(endpointConfig.getUserProperties()
            .get(WebsocketEndpointConfig.getInstanceToReadProperties().getMaxMessagePropertyName())
            .toString()));

    session.addMessageHandler(queryHandler);
}