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

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


        for (int i = 0; i < multipler; i++) {
          MessageBuildSendable sendable = MessageBuilder.createMessage()
                  .toSubject("StressTestService")
                  .withValue(messageValue)
                  .done()
                  .repliesTo(new MessageCallback() {
                    @Override
                    public void callback(Message message) {
                      stats.registerReceivedMessage(message);
                      statsPanel.updateStatsLabels(stats);
                    }
View Full Code Here


  public void execute(final BootstrapContext context) {
    final ServerMessageBus bus = context.getBus();
    final boolean authenticationConfigured =
        context.getConfig().getResource(AuthenticationAdapter.class) != null;

    bus.subscribe(ErraiService.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, ErraiService.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 {
                context.getConfig().getResource(AuthenticationAdapter.class)
                    .challenge(message);
              }
              catch (AuthenticationFailedException a) {
              }
            }
            break;

          case EndSession:
            if (authenticationConfigured) {
              context.getConfig().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(ErraiService.SERVER_ECHO_SERVICE, new MessageCallback() {
      public void callback(Message c) {
        MessageBuilder.createConversation(c)
            .subjectProvided().noErrorHandling()
            .sendNowWith(bus);
      }
    });

    bus.subscribe(ErraiService.AUTHORIZATION_SERVICE, 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

          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

  // 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

  void sendMessage() {
    MessageBuilder.createMessage()
        .toSubject("HelloWorldService")
        .withValue("Hello, There!")
        .done()
        .repliesTo(new MessageCallback() {
          public void callback(Message message) {
            System.out.println("Got a Response!");
            responseLabel.setText("Message from Server: " + message.get(String.class, MessageParts.Value));
          }
        })
View Full Code Here

  public static MessageInterceptor CONVERSATION_INTERCEPTOR = new ConversationInterceptor();

  public static void handleEvent(final Class<?> type, final EventHandler<Object> handler) {
    ErraiBus.get().subscribe("cdi.event:" + type.getName(), // by convention
            new MessageCallback() {
              public void callback(Message message) {
                Object response = message.get(type, CDIProtocol.OBJECT_REF);
                handler.handleEvent(response);
              }
            });
View Full Code Here

        CDI.fireEvent(new BusReadyEvent());
      }
    };


    bus.subscribe("cdi.event:ClientDispatcher", new MessageCallback() {
      public void callback(Message message) {
        switch (BusCommands.valueOf(message.getCommandType())) {
          case RemoteSubscribe:
            CDI.addRemoteEventTypes(message.get(String[].class, MessageParts.Value));
View Full Code Here

                  public boolean error(Message message, Throwable throwable) {
                    throwable.printStackTrace();
                    return true;
                  }
                })
                .repliesTo(new MessageCallback() {
                  public void callback(Message message) {
                    Window.alert("From Server: " + message.get(String.class, MessageParts.Value));
                  }
                })
                .sendNowWith(bus);
View Full Code Here

      final String receiverName = "RandomNumberReceiver" + i;

      final Style resultStyle = resultBox.getElement().getStyle();

      /**
       * Create a callback receiver to receive the data from the server.
       */
      final MessageCallback receiver = new MessageCallback() {
        public void callback(Message message) {
          counter.increment();
          Double value = message.get(Double.class, "Data");
          resultBox.setText(String.valueOf(value));

View Full Code Here


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

    MessageCallback cb = new MessageCallback() {
      @Override
      public void callback(Message message) {
        try {
          executeInterceptorStack(true, message);
          callback.callback(message);
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.