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

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


    // deferr notification of LoginClient in case
    // a workspace wants to override the authentication or authorization scheme
    private boolean deferredNotification;

    public SecurityService() {
        ErraiBus.get().subscribe(SUBJECT, new MessageCallback() {
            public void callback(Message msg) {

                switch (SecurityCommands.valueOf(msg.getCommandType())) {
                    case AuthenticationScheme:
                        if (authHandler == null) {
                            //               msg.toSubject("LoginClient").sendNowWith(ErraiBus.get());
                            return;
                        }

                        String credentialsRequired = msg.get(String.class, CredentialsRequired);
                        String[] credentialNames = credentialsRequired.split(",");
                        Credential[] credentials = new Credential[credentialNames.length];

                        for (int i = 0; i < credentialNames.length; i++) {
                            switch (CredentialTypes.valueOf(credentialNames[i])) {
                                case Name:
                                    credentials[i] = new NameCredential();
                                    break;
                                case Password:
                                    credentials[i] = new PasswordCredential();
                                    break;

                                default:
                                    //todo: throw a massive error here.
                            }
                        }

                        // callback on externally provided login form
                        // asking for the required credentials specified on the server side.
                        authHandler.doLogin(credentials);

                        // Create an authentication request and send the credentials
                        Message challenge = createMessage()
                                .toSubject("AuthenticationService")
                                .command(SecurityCommands.AuthRequest)
                                .with(MessageParts.ReplyTo, SUBJECT)
                                .getMessage();

                        for (int i = 0; i < credentialNames.length; i++) {
                            switch (CredentialTypes.valueOf(credentialNames[i])) {
                                case Name:
                                    challenge.set(CredentialTypes.Name, credentials[i].getValue());
                                    break;
                                case Password:
                                    challenge.set(CredentialTypes.Password, credentials[i].getValue());
                                    break;
                            }
                        }

                        challenge.sendNowWith(ErraiBus.get());

                        break;
                    case AuthenticationNotRequired:
                        notifyLoginClient(msg);
                        break;

                    case FailedAuth:
                        notifyLoginClient(msg);
                        break;
                    case SuccessfulAuth:
                        if (authenticationContext != null && authenticationContext.isValid()) return;
                        authenticationContext = createAuthContext(msg);
                        notifyLoginClient(msg);

                        break;
                }
            }
        });


        // listener for the authorization assignment
        ErraiBus.get().subscribe("AuthorizationListener",
                new MessageCallback() {
                    public void callback(Message message) {

                        authenticationContext = createAuthContext(message);

                        if (!deferredNotification) {
View Full Code Here


                if (remoteCallback != null) {
                    final String replyTo = message.getSubject() + "." + message.getCommandType() + ":RespondTo:" + uniqueNumber();

                    if (remoteCallback != null) {
                        bus.subscribe(replyTo,
                                new MessageCallback() {
                                    @SuppressWarnings({"unchecked"})
                                    public void callback(Message message) {
                                        bus.unsubscribeAll(replyTo);
                                        remoteCallback.callback(message.get(responseType, "MethodReply"));
                                    }
View Full Code Here


  private boolean directSubscribe(final String subject, final MessageCallback callback, final boolean local) {
    final boolean isNew = !isSubscribed(subject);

    final MessageCallback cb = new MessageCallback() {
      @Override
      public void callback(Message message) {
        try {
          callback.callback(message);
        }
View Full Code Here

    if (isRemoteCommunicationEnabled()) {
      remoteSubscribe(BuiltInServices.ServerEchoService.name());
    }

    directSubscribe(BuiltInServices.ClientBus.name(), new MessageCallback() {
      @Override
      @SuppressWarnings({"unchecked"})
      public void callback(final Message message) {
        switch (BusCommands.valueOf(message.getCommandType())) {
          case RemoteSubscribe:
            if (message.hasPart(MessageParts.SubjectsList)) {
              LogUtil.log("remote services available: " + message.get(List.class, MessageParts.SubjectsList));

              for (String subject : (List<String>) message.get(List.class, MessageParts.SubjectsList)) {
                remoteSubscribe(subject);
              }
            }
            else {
              remoteSubscribe(message.get(String.class, Subject));
            }
            break;

          case RemoteUnsubscribe:
            unsubscribeAll(message.get(String.class, Subject));
            break;

          case CapabilitiesNotice:
            LogUtil.log("received capabilities notice from server. supported capabilities of remote: "
                    + message.get(String.class, MessageParts.CapabilitiesFlags));

            final String[] capabilites = message.get(String.class, MessageParts.CapabilitiesFlags).split(",");

            for (String capability : capabilites) {
              switch (Capabilities.valueOf(capability)) {
                case WebSockets:
                  webSocketUrl = message.get(String.class, MessageParts.WebSocketURL);
                  webSocketToken = message.get(String.class, MessageParts.WebSocketToken);
                  webSocketUpgradeAvailable = true;
                  break;
                case LongPollAvailable:

                  LogUtil.log("initializing long poll subsystem");
                  receiveCommCallback = new LongPollRequestCallback();
                  break;
                case NoLongPollAvailable:
                  receiveCommCallback = new ShortPollRequestCallback();
                  if (message.hasPart(MessageParts.PollFrequency)) {
                    POLL_FREQUENCY = message.get(Integer.class, MessageParts.PollFrequency);
                  }
                  else {
                    POLL_FREQUENCY = 500;
                  }
                  break;
              }
            }

            break;

          case RemoteMonitorAttach:
            break;

          case FinishStateSync:
            if (isInitialized()) {
              return;
            }

            new Timer() {
              @Override
              public void run() {
                LogUtil.log("received FinishStateSync message. preparing to bring up the federation");

                List<String> subjects = new ArrayList<String>();
                for (String s : subscriptions.keySet()) {
                  if (s.startsWith("local:")) continue;
                  if (!remotes.containsKey(s)) subjects.add(s);
                }

                sessionId = message.get(String.class, MessageParts.ConnectionSessionKey);

                remoteSubscribe(BuiltInServices.ServerBus.name());

                encodeAndTransmit(CommandMessage.createWithParts(new HashMap<String, Object>())
                        .toSubject(BuiltInServices.ServerBus.name())
                        .command(RemoteSubscribe)
                        .set(MessageParts.SubjectsList, subjects)
                        .set(PriorityProcessing, "1"));

                encodeAndTransmit(CommandMessage.createWithParts(new HashMap<String, Object>())
                        .toSubject(BuiltInServices.ServerBus.name())
                        .command(BusCommands.FinishStateSync)
                        .set(PriorityProcessing, "1"));

                /**
                 * ... also send RemoteUnsubscribe signals.
                 */
                addSubscribeListener(new SubscribeListener() {
                  @Override
                  public void onSubscribe(SubscriptionEvent event) {
                    if (event.isLocalOnly() || event.getSubject().startsWith("local:")
                            || remotes.containsKey(event.getSubject())) {
                      return;
                    }

                    if (event.isNew()) {
                      encodeAndTransmit(CommandMessage.createWithParts(new HashMap<String, Object>())
                              .toSubject(BuiltInServices.ServerBus.name())
                              .command(RemoteSubscribe)
                              .set(Subject, event.getSubject())
                              .set(PriorityProcessing, "1"));
                    }
                  }
                });

                addUnsubscribeListener(new UnsubscribeListener() {
                  @Override
                  public void onUnsubscribe(SubscriptionEvent event) {
                    encodeAndTransmit(CommandMessage.createWithParts(new HashMap<String, Object>())
                            .toSubject(BuiltInServices.ServerBus.name())
                            .command(RemoteUnsubscribe)
                            .set(Subject, event.getSubject())
                            .set(PriorityProcessing, "1"));
                  }
                });

                subscribe(DefaultErrorCallback.CLIENT_ERROR_SUBJECT, new MessageCallback() {
                  @Override
                  public void callback(Message message) {
                    String errorTo = message.get(String.class, MessageParts.ErrorTo);
                    if (errorTo == null) {
                      logError(message.get(String.class, MessageParts.ErrorMessage),
View Full Code Here

          final String replyTo = message.getSubject() + "." + message.getCommandType() +
            ":RespondTo:" + (id = uniqueNumber());

          if (remoteCallback != null) {
            bus.subscribe(replyTo,
                    new MessageCallback() {
                      @SuppressWarnings({"unchecked"})
                      public void callback(Message message) {
                        bus.unsubscribeAll(replyTo);
                        remoteCallback.callback(message.get(responseType, "MethodReply"));
                      }
                    });
            message.set(MessageParts.ReplyTo, replyTo);
          }
        }
       
        if (message.getErrorCallback() != null) {
          final String errorTo = message.getSubject() + "." + message.getCommandType() +
            ":Errors:" + ((id == null) ? uniqueNumber() : id);
         
            bus.subscribe(errorTo,
              new MessageCallback() {
                @SuppressWarnings({"unchecked"})
                public void callback(Message m) {
                  bus.unsubscribeAll(errorTo);
                  message.getErrorCallback().error(message, m.get(Throwable.class, MessageParts.Throwable));
                }
View Full Code Here

    transmissionbuffer = buffer;

    /**
     * Define the default ServerBus service used for intrabus communication.
     */
    subscribe(BuiltInServices.ServerBus.name(), new MessageCallback() {
      @Override
      @SuppressWarnings({"unchecked", "SynchronizationOnLocalVariableOrMethodParameter"})
      public void callback(final Message message) {
        try {
          final QueueSession session = getSession(message);
View Full Code Here

        VerticalPanel p = new VerticalPanel();

        final FlexTable table = new FlexTable();

        bus.subscribe("ClientEndpoint",
                new MessageCallback() {
                    public void callback(Message message) {
                        List<Record> records = message.get(List.class, "Records");
                     
                        int row = 0;
                        for (Record r : records) {
View Full Code Here

        init();
    }

    private void init() {
        //todo: this all needs sendNowWith be refactored at some point.
        bus.subscribe(AUTHORIZATION_SVC_SUBJECT, new MessageCallback() {
            public void callback(Message message) {
                switch (SecurityCommands.valueOf(message.getCommandType())) {
                    case AuthenticationScheme:
                        if (authenticationConfigured()) {

                            /**
                             * Respond with what credentials the authentication system requires.
                             */
                            //todo: we only support login/password for now

                            createConversation(message)
                                    .subjectProvided()
                                    .command(SecurityCommands.AuthenticationScheme)
                                    .with(SecurityParts.CredentialsRequired, "Name,Password")
                                    .with(MessageParts.ReplyTo, AUTHORIZATION_SVC_SUBJECT)
                                    .noErrorHandling().sendNowWith(bus);
                        } else {
                            createConversation(message)
                                    .subjectProvided()
                                    .command(SecurityCommands.AuthenticationNotRequired)
                                    .noErrorHandling().sendNowWith(bus);
                        }

                        break;

                    case AuthRequest:
                        /**
                         * Receive a challenge.
                         */

                        if (authenticationConfigured()) {
                            try {
                                configurator.getResource(AuthenticationAdapter.class)
                                        .challenge(message);
                            }
                            catch (AuthenticationFailedException a) {
                            }
                        }
                        break;

                    case EndSession:
                        if (authenticationConfigured()) {
                            configurator.getResource(AuthenticationAdapter.class)
                                    .endSession(message);
                        }

                      // reply in any case
                      createConversation(message)
                          .toSubject("LoginClient")
                          .command(SecurityCommands.EndSession)
                          .noErrorHandling()
                          .sendNowWith(bus);

                        break;
                }
            }
        });

        /**
         * The standard ServerEchoService.
         */
        bus.subscribe("ServerEchoService", new MessageCallback() {
            public void callback(Message c) {
                MessageBuilder.createConversation(c)
                        .subjectProvided().signalling().noErrorHandling()
                        .sendNowWith(bus);
            }
        });

        bus.subscribe("AuthorizationService", new MessageCallback() {
            public void callback(Message message) {
                AuthSubject subject = message.getResource(QueueSession.class, "Session")
                        .getAttribute(AuthSubject.class, ErraiService.SESSION_AUTH_DATA);

                Message reply = MessageBuilder.createConversation(message).getMessage();
View Full Code Here

    /**
     * Declare a local service to receive messages on the subject
     * "BroadCastReceiver".
     */
    bus.subscribe("BroadcastReceiver", new MessageCallback() {
      public void callback(Message message) {
        /**
         * When a message arrives, extract the "BroadcastText" field and
         * update the broadcastReceive Label widget with the contents.
         */
 
View Full Code Here

        .noErrorHandling()
        .sendNowWith(bus);
  }

  private void setupListener() {
    bus.subscribe("SourceViewClient", new MessageCallback() {
      public void callback(Message message) {
        String source = message.get(String.class, "source");
        formatted.setSource(source);
      }
    });
View Full Code Here

TOP

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

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.