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

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


      synchronized (queue) {
        if (deferredQueue.containsKey(queue)) {
          List<Message> deferredMessages = deferredQueue.get(queue);
          Iterator<Message> dmIter = deferredMessages.iterator();

          Message m;
          while (dmIter.hasNext()) {
            if ((m = dmIter.next()).hasPart(MessageParts.PriorityProcessing.toString())) {
              queue.offer(m);
              dmIter.remove();
            }
View Full Code Here


    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();

        if (subject != null) {
          reply.set(SecurityParts.Roles, subject.toRolesString());
          reply.set(SecurityParts.Name, subject.getUsername());
        }

        reply.sendNowWith(bus);
      }
    });


  }
View Full Code Here

        if (json.length() == 0) return null;

        Map<String, Object> parts = decodeToMap(json);
        parts.remove(MessageParts.SessionID.name());

        Message msg = createWithParts(parts)
                .setResource("Session", session);

        // experimental feature. does this need to be cleaned?
        // any chance this leaks the CL?
        //   msg.setResource("errai.experimental.classLoader", classLoader);

        msg.setFlag(RoutingFlags.FromRemote);

        return msg;

    }
View Full Code Here

        Map<String, Object> parts = (Map<String, Object>) JSONStreamDecoder.decode(stream);
        parts.remove(MessageParts.SessionID.name());

        // Expose session and session id
        // CDI ext makes use of it to manage conversation contexts
        Message msg = createWithParts(parts)
                .setResource("Session", session)
                .setResource("SessionID", session.getSessionId());

        // experimental feature. does this need to be cleaned?
        // any chance this leaks the CL?
        //   msg.setResource("errai.experimental.classLoader", classLoader);

        msg.setFlag(RoutingFlags.FromRemote);

        return msg;
    }
View Full Code Here

     * @return a <tt>MessageBuildSubject</tt> which essentially is a <tt>Message</tt>, but ensures that the user
     *         constructs messages properly
     */
    @SuppressWarnings({"unchecked"})
    public static MessageBuildSubject<MessageReplySendable> createConversation(Message message) {
        Message newMessage = provider.get();
        if (newMessage instanceof HasEncoded) {
            return new AbstractMessageBuilder<MessageReplySendable>(new HasEncodedConvMessageWrapper(message, newMessage)).start();
        } else {
            return new AbstractMessageBuilder<MessageReplySendable>(new ConversationMessageWrapper(message, newMessage)).start();
        }
View Full Code Here

    public void poll(final boolean wait, final OutputStream outstream) throws IOException {
        if (!queueRunning) {
            throw new QueueUnavailableException("queue is not available");
        }

        Message m = null;

        checkSession();

        outstream.write('[');

        if (lock.tryAcquire()) {
            int payLoadSize = 0;
            try {

                if (wait) {
                    m = queue.poll(45, TimeUnit.SECONDS);

                } else {
                    m = queue.poll();
                }

                if (m instanceof HasEncoded) {
                    outstream.write(((HasEncoded) m).getEncoded().getBytes());
                } else if (m != null) {
                    JSONStreamEncoder.encode(m.getParts(), outstream);
                }

                if (_windowPolling) {
                    windowPolling = true;
                    _windowPolling = false;
                } else if (windowPolling) {
                    while (!queue.isEmpty() && payLoadSize < MAXIMUM_PAYLOAD_SIZE
                            && !isWindowExceeded()) {
                        outstream.write(',');
                        if ((m = queue.poll()) instanceof HasEncoded) {
                            outstream.write(((HasEncoded) m).getEncoded().getBytes());
                        } else {
                            JSONStreamEncoder.encode(m.getParts(), outstream);
                        }
                        payLoadSize++;

                        try {
                            if (queue.isEmpty())
View Full Code Here

                sb.append(buffer.get());
            }
            buffer.rewind();
        }

        Message msg = createCommandMessage(session, sb.toString());
        if (msg != null) {
            service.store(msg);
        }

        pollQueue(service.getBus().getQueue(session), request, response);
View Full Code Here

        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();

                if (subject != null) {
                    reply.set(SecurityParts.Roles, subject.toRolesString());
                    reply.set(SecurityParts.Name, subject.getUsername());
                }

                reply.sendNowWith(bus);
            }
        });
    }
View Full Code Here

            /**
             * Prepare to send a message back to the client, informing it that a successful login has
             * been performed.
             */
            Message successfulMsg = MessageBuilder.createConversation(message)
                    .subjectProvided()
                    .command(SecurityCommands.SuccessfulAuth)
                    .with(SecurityParts.Roles, authSubject.toRolesString())
                    .with(SecurityParts.Name, name).getMessage();

            try {
                // TODO: Still used? Take a look at MetaDataScanner.getProperties() instead
                ResourceBundle bundle = ResourceBundle.getBundle("errai");
                String motdText = bundle.getString("errai.login_motd");

                /**
                 * If the MOTD is configured, then add it to the message.
                 */
                if (motdText != null) {
                    successfulMsg.set(MessageParts.MessageText, motdText);
                }
            }
            catch (Exception e) {
                // do nothing.
            }

            /**
             * Transmit the message back to the client.
             */
            successfulMsg.sendNowWith(bus);
        }
        catch (LoginException e) {
            /**
             * The login failed. How upsetting. Life must go on, and we must inform the client of the
             * unfortunate news.
View Full Code 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;
View Full Code Here

TOP

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

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.