Examples of LocalContext


Examples of org.jboss.errai.bus.server.util.LocalContext

          case WebsocketChannelVerify:
            if (message.hasPart(MessageParts.WebSocketToken)) {
              if (verifyOneTimeToken(session, message.get(String.class, MessageParts.WebSocketToken))) {
                final String reconnectionToken = getNewOneTimeToken(session);

                final LocalContext localContext = LocalContext.get(session);

                localContext.setAttribute(WebSocketServerHandler.SESSION_ATTR_WS_STATUS,
                    WebSocketServerHandler.WEBSOCKET_ACTIVE);

                createConversation(message)
                    .toSubject(BuiltInServices.ClientBus.name())
                    .command(BusCommand.WebsocketChannelOpen)
View Full Code Here

Examples of org.jboss.errai.bus.server.util.LocalContext

  public void callback(final Message message) {
    if (!message.isFlagSet(RoutingFlag.FromRemote))
      return;

    try {
      final LocalContext localContext = LocalContext.get(message);
      final String typeName = message.get(String.class, CDIProtocol.BeanType);
      final Set<String> annotationTypes = message.get(Set.class, CDIProtocol.Qualifiers);

      switch (CDICommands.valueOf(message.getCommandType())) {
      case RemoteSubscribe:
        final Class<?> type = Class.forName(typeName);
        final ClientObserverMetadata clientObserver = new ClientObserverMetadata(type, annotationTypes);

        if (!clientObservers.contains(clientObserver)) {
          if (type == null || !EnvUtil.isPortableType(type)) {
            log.warn("client tried to register a non-portable type: " + type);
            return;
          }
          clientObservers.add(clientObserver);
        }
        eventRoutingTable.activateRoute(typeName, annotationTypes, message.getResource(QueueSession.class, "Session"));
        break;

      case RemoteUnsubscribe:
        eventRoutingTable.deactivateRoute(typeName, annotationTypes, message.getResource(QueueSession.class, "Session"));
        break;

      case CDIEvent:
        if (!isRoutable(localContext, message)) {
          return;
        }

        final Object o = message.get(Object.class, CDIProtocol.BeanReference);
        EventConversationContext.activate(o, CDIServerUtil.getSession(message));
        try {
          final Set<String> qualifierNames = message.get(Set.class, CDIProtocol.Qualifiers);
          List<Annotation> qualifiers = new ArrayList<Annotation>();

          if (qualifierNames != null) {
            for (final String qualifierName : qualifierNames) {
              final Annotation qualifier = allQualifiers.get(qualifierName);
              if (qualifier != null) {
                qualifiers.add(qualifier);
              }
            }
          }
          // Fire event to all local observers
          Annotation[] qualArray = qualifiers.toArray(new Annotation[qualifiers.size()]);
          Set<ObserverMethod<? super Object>> observerMethods = beanManager.resolveObserverMethods(o, qualArray);
          for (ObserverMethod<? super Object> observer : observerMethods) {
            // Don't mirror the event back to the clients
            if (!(AnyEventObserver.class.equals(observer.getBeanClass()))) {
              observer.notify(o);
            }
          }
        } finally {
          EventConversationContext.deactivate();
        }

        break;

      case AttachRemote:
        if (observedEvents.size() > 0) {
          MessageBuilder.createConversation(message).toSubject(CDI.CLIENT_DISPATCHER_SUBJECT)
                  .command(CDICommands.AttachRemote).with(MessageParts.RemoteServices, getEventTypes()).done().reply();
        }
        else {
          MessageBuilder.createConversation(message).toSubject(CDI.CLIENT_DISPATCHER_SUBJECT)
                  .command(CDICommands.AttachRemote).with(MessageParts.RemoteServices, "").done().reply();
        }

        localContext.setAttribute(CDI_EVENT_CHANNEL_OPEN, "1");
        break;

      default:
        throw new IllegalArgumentException("Unknown command type " + message.getCommandType());
      }
View Full Code Here

Examples of org.jboss.errai.bus.server.util.LocalContext

  @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

Examples of org.jboss.errai.bus.server.util.LocalContext

    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.
          final EJString activationKey = val.get(MessageParts.WebSocketToken.name()).isString();
          if (activationKey == null || !WebSocketTokenManager.verifyOneTimeToken(cometSession, activationKey.stringValue())) {

            // nope. go away!
            sendMessage(new SimpleEventChannelWrapped(socket), getFailedNegotiation("bad negotiation key"));
          }
          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(cometSession);
            localCometSession.setAttribute(WebSocketServerHandler.SESSION_ATTR_WS_STATUS, WebSocketServerHandler.WEBSOCKET_AWAIT_ACTIVATION);

            // send the challenge.
            sendMessage(new SimpleEventChannelWrapped(socket), getReverseChallenge(reverseToken));
            return;
          }
View Full Code Here

Examples of org.jboss.errai.bus.server.util.LocalContext

      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));
View Full Code Here

Examples of org.jboss.errai.bus.server.util.LocalContext

      if (BusCommands.ConnectToQueue.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 && (session = svc.getBus().getSessionBySessionId(sessionKey)) != null) {
          final LocalContext localContext = LocalContext.get(session);

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

            // open the channel
            activeChannels.put(ctx.getChannel(), session);

            // set the session queue into direct channel mode.
            svc.getBus().getQueueBySession(sessionKey).setDirectSocketChannel(new NettyQueueChannel(ctx.getChannel()));

            // remove the web socket token so it cannot be re-used for authentication.
            localContext.removeAttribute(MessageParts.WebSocketToken.name());
            localContext.removeAttribute(SESSION_ATTR_WS_STATUS);

            return;
          }

          // check the activation key matches.
          final EJString activationKey = val.get(MessageParts.WebSocketToken.name()).isString();
          if (activationKey == null || !WebSocketTokenManager.verifyOneTimeToken(session, activationKey.stringValue())) {
            // nope. go away!
            sendMessage(ctx, getFailedNegotiation("bad negotiation key"));
          }
          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);
            localContext.setAttribute(MessageParts.WebSocketToken.name(), reverseToken);
            localContext.setAttribute(SESSION_ATTR_WS_STATUS, WEBSOCKET_AWAIT_ACTIVATION);

            // send the challenge.
            sendMessage(ctx, getReverseChallenge(reverseToken));
            return;
          }
View Full Code Here

Examples of org.jboss.errai.bus.server.util.LocalContext

            case WebsocketChannelVerify:
              if (message.hasPart(MessageParts.WebSocketToken)) {
                if (verifyOneTimeToken(session, message.get(String.class, MessageParts.WebSocketToken))) {

                  final LocalContext localContext = LocalContext.get(session);

                  localContext.setAttribute(WebSocketServerHandler.SESSION_ATTR_WS_STATUS,
                      WebSocketServerHandler.WEBSOCKET_ACTIVE);

                  createConversation(message)
                      .toSubject(BuiltInServices.ClientBus.name())
                      .command(BusCommands.WebsocketChannelOpen)
View Full Code Here

Examples of org.jboss.errai.bus.server.util.LocalContext

      if (BusCommands.ConnectToQueue.name().equals(commandType)) {
        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 && (session = svc.getBus().getSessionBySessionId(sessionKey)) != null) {
          LocalContext localContext = LocalContext.get(session);

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

            // open the channel
            activeChannels.put(ctx.getChannel(), session);

            // set the session queue into direct channel mode.
            svc.getBus().getQueueBySession(sessionKey).setDirectSocketChannel(new NettyQueueChannel(ctx.getChannel()));

            // remove the web socket token so it cannot be re-used for authentication.
            localContext.removeAttribute(MessageParts.WebSocketToken.name());
            localContext.removeAttribute(SESSION_ATTR_WS_STATUS);

            return;
          }

          // check the activation key matches.
          EJString activationKey = val.get(MessageParts.WebSocketToken.name()).isString();
          if (activationKey == null || !WebSocketTokenManager.verifyOneTimeToken(session, activationKey.stringValue())) {
            // nope. go away!
            sendMessage(ctx, getFailedNegotiation("bad negotiation key"));
          }
          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.
            String reverseToken = WebSocketTokenManager.getNewOneTimeToken(session);
            localContext.setAttribute(MessageParts.WebSocketToken.name(), reverseToken);
            localContext.setAttribute(SESSION_ATTR_WS_STATUS, WEBSOCKET_AWAIT_ACTIVATION);

            // send the challenge.
            sendMessage(ctx, getReverseChallenge(reverseToken));
            return;
          }
View Full Code Here

Examples of org.jboss.errai.bus.server.util.LocalContext

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

    final LocalContext localSessionContext = LocalContext.get(session);
    QueueSession cometSession = localSessionContext.getAttribute(QueueSession.class, WEBSOCKET_SESSION_ALIAS);
    service.getBus().getQueue(cometSession).setDirectSocketChannel(null);
  }
View Full Code Here

Examples of org.jboss.errai.bus.server.util.LocalContext

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

    @SuppressWarnings("unchecked") 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) {
      String commandType = val.get(MessageParts.CommandType.name()).isString().stringValue();

      // this client apparently wants to connect.
      if (BusCommands.ConnectToQueue.name().equals(commandType)) {
        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) {
          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.
            service.getBus().getQueue(cometSession).setDirectSocketChannel(new SimpleEventChannelWrapped(socket));

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

            return;
          }

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

            // nope. go away!
            sendMessage(new SimpleEventChannelWrapped(socket), getFailedNegotiation("bad negotiation key"));
          }
          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.
            String reverseToken = WebSocketTokenManager.getNewOneTimeToken(cometSession);
            localCometSession.setAttribute(WebSocketServerHandler.SESSION_ATTR_WS_STATUS, WebSocketServerHandler.WEBSOCKET_AWAIT_ACTIVATION);

            // send the challenge.
            sendMessage(new SimpleEventChannelWrapped(socket), getReverseChallenge(reverseToken));
            return;
          }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.