Package org.jboss.errai.bus.client.api

Examples of org.jboss.errai.bus.client.api.QueueSession


  public static class SessionsContainer implements Serializable {
    private transient final Map<String, Object> sharedAttributes = new HashMap<String, Object>();
    private transient final Map<String, QueueSession> queueSessions = new HashMap<String, QueueSession>();

    public QueueSession createSession(final String httpSessionId, final String remoteQueueId) {
      final QueueSession qs = new HttpSessionWrapper(this, httpSessionId, remoteQueueId);
      queueSessions.put(remoteQueueId, qs);
      return qs;
    }
View Full Code Here


  protected void onSocketOpened(final WebSocket socket) throws IOException {
  }

  @Override
  protected void onSocketClosed(final WebSocket socket) throws IOException {
    final QueueSession session = sessionProvider.createOrGetSession(socket.getHttpSession(),
            socket.getSocketID());

    final LocalContext localSessionContext = LocalContext.get(session);
    final QueueSession cometSession = localSessionContext.getAttribute(QueueSession.class, WEBSOCKET_SESSION_ALIAS);

    service.getBus().getQueue(cometSession).setDeliveryHandlerToDefault();
  }
View Full Code Here

        }
    }

    final String text = ((TextFrame) frame).getText();

    final QueueSession session = sessionProvider.createOrGetSession(socket.getHttpSession(),
            socket.getSocketID());

    if (text.length() == 0) return;

    @SuppressWarnings("unchecked") final EJObject val = JSONDecoder.decode(text).isObject();

    final LocalContext localSessionContext = LocalContext.get(session);

    QueueSession cometSession = localSessionContext.getAttribute(QueueSession.class, WEBSOCKET_SESSION_ALIAS);

    // this is not an active channel.
    if (cometSession == null) {
      final String commandType = val.get(MessageParts.CommandType.name()).isString().stringValue();

      // this client apparently wants to connect.
      if (BusCommand.Associate.name().equals(commandType)) {
        final String sessionKey = val.get(MessageParts.ConnectionSessionKey.name()).isString().stringValue();

        // has this client already attempted a connection, and is in a wait verify state
        if (sessionKey != null && (cometSession = service.getBus().getSessionBySessionId(sessionKey)) != null) {
          final LocalContext localCometSession = LocalContext.get(cometSession);

          if (localCometSession.hasAttribute(WebSocketServerHandler.SESSION_ATTR_WS_STATUS) &&
                  WebSocketServerHandler.WEBSOCKET_ACTIVE.equals(localCometSession.getAttribute(String.class, WebSocketServerHandler.SESSION_ATTR_WS_STATUS))) {

            // set the session queue into direct channel mode.

            final MessageQueue queue = service.getBus().getQueue(cometSession);
            queue.setDeliveryHandler(DirectDeliveryHandler.createFor(new SimpleEventChannelWrapped(socket)));

            localSessionContext.setAttribute(WEBSOCKET_SESSION_ALIAS, cometSession);
            cometSession.removeAttribute(WebSocketServerHandler.SESSION_ATTR_WS_STATUS);

            return;
          }

          // check the activation key matches.
View Full Code Here

  @SuppressWarnings("rawtypes")
  public static QueueSession establishNegotiation(EJValue val, QueueChannel queueChannel, ErraiService service)
          throws IOException {

    QueueSession session = null;
    final EJObject ejObject = val.isObject();
    if (ejObject == null) {
      return null;
    }

    final String commandType = ejObject.get(MessageParts.CommandType.name()).isString().stringValue();

    // this client apparently wants to connect.
    if (BusCommand.Associate.name().equals(commandType)) {
      final String sessionKey = ejObject.get(MessageParts.ConnectionSessionKey.name()).isString().stringValue();

      // has this client already attempted a connection, and is in a wait verify
      // state
      if (sessionKey != null && (session = service.getBus().getSessionBySessionId(sessionKey)) != null) {
        final LocalContext localCometSession = LocalContext.get(session);

        if (localCometSession.hasAttribute(WebSocketServerHandler.SESSION_ATTR_WS_STATUS)
                && WebSocketServerHandler.WEBSOCKET_ACTIVE.equals(localCometSession.getAttribute(String.class,
                        WebSocketServerHandler.SESSION_ATTR_WS_STATUS))) {

          // set the session queue into direct channel mode.
          final MessageQueue queue = service.getBus().getQueueBySession(sessionKey);
          queue.setDeliveryHandler(DirectDeliveryHandler.createFor(queueChannel));
          LOGGER.debug("set direct delivery handler on session: {}", session.getSessionId());
          return session;
        }

        // check the activation key matches.
        final EJString activationKey = ejObject.get(MessageParts.WebSocketToken.name()).isString();
        if (activationKey == null || !WebSocketTokenManager.verifyOneTimeToken(session, activationKey.stringValue())) {

          // nope. go away!
          final String error = "bad negotiation key";
          LOGGER.debug("activation key not match for session: {}", session.getSessionId());
          sendMessage(queueChannel, WebSocketNegotiationMessage.getFailedNegotiation(error));
        }
        else {
          // the key matches. now we send the reverse challenge to prove this
          // client is actually
          // already talking to the bus over the COMET channel.
          final String reverseToken = WebSocketTokenManager.getNewOneTimeToken(session);
          localCometSession.setAttribute(WebSocketServerHandler.SESSION_ATTR_WS_STATUS,
                  WebSocketServerHandler.WEBSOCKET_AWAIT_ACTIVATION);

          // send the challenge.
          LOGGER.debug("reverse challange for session: {}", session.getSessionId());
          sendMessage(queueChannel, WebSocketNegotiationMessage.getReverseChallenge(reverseToken));
          return null;
        }
        sendMessage(queueChannel, WebSocketNegotiationMessage.getSuccessfulNegotiation());
      }
View Full Code Here

          .getName()));
    }

    @SuppressWarnings("unchecked") final EJObject val = JSONDecoder.decode(((TextWebSocketFrame) frame).getText()).isObject();

    final QueueSession session;

    // this is not an active channel.
    if (!activeChannels.containsKey(ctx.getChannel())) {
      final String commandType = val.get(MessageParts.CommandType.name()).isString().stringValue();
View Full Code Here

   * @throws ServletException - if the request for the POST could not be handled
   */
  @Override
  protected void doPost(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse)
          throws ServletException, IOException {
    final QueueSession session = sessionProvider.createOrGetSession(httpServletRequest.getSession(true),
            httpServletRequest.getHeader(ClientMessageBus.REMOTE_QUEUE_ID_HEADER));

    service.store(createCommandMessage(session, httpServletRequest));

    pollForMessages(session, httpServletRequest, httpServletResponse, false);
View Full Code Here

  private static final Logger log = getLogger(StandardAsyncServlet.class);
  private static final long serialVersionUID = 1L;

  @Override
  protected void doGet(final HttpServletRequest request, final HttpServletResponse response) throws ServletException {
    final QueueSession session = sessionProvider.createOrGetSession(request.getSession(), getClientId(request));
    session.setAttribute("NoSSE", Boolean.TRUE);
   
    final MessageQueue queue = service.getBus().getQueue(session);
    if (queue == null) {
      switch (getConnectionPhase(request)) {
        case CONNECTING:
View Full Code Here

    }
  }

  @Override
  protected void doPost(final HttpServletRequest request, final HttpServletResponse response) throws ServletException {
    final QueueSession session = sessionProvider.createOrGetSession(request.getSession(), getClientId(request));
    session.setAttribute("NoSSE", Boolean.TRUE);
    try {
      try {
        service.store(createCommandMessage(session, request));
      }
      catch (QueueUnavailableException e) {
View Full Code Here

   * Reads resources from the provided {@link Message} and stores them in {@link ThreadLocal}s.
   *
   * @param message
   */
  public static void set(final Message message) {
    final QueueSession queueSession = message.getResource(QueueSession.class, "Session");
    if (queueSession != null) {
      final HttpSession session =
            queueSession.getAttribute(HttpSession.class, HttpSession.class.getName());

      if (session != null) {
        threadLocalHttpSession.set(session);
      }
    }
View Full Code Here

          .getName()));
    }

    @SuppressWarnings("unchecked") EJObject val = JSONDecoder.decode(((TextWebSocketFrame) frame).getText()).isObject();

    QueueSession session;

    // this is not an active channel.
    if (!activeChannels.containsKey(ctx.getChannel())) {
      String commandType = val.get(MessageParts.CommandType.name()).isString().stringValue();
View Full Code Here

TOP

Related Classes of org.jboss.errai.bus.client.api.QueueSession

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.