Example usage for javax.jms ObjectMessage getObject

List of usage examples for javax.jms ObjectMessage getObject

Introduction

In this page you can find the example usage for javax.jms ObjectMessage getObject.

Prototype


Serializable getObject() throws JMSException;

Source Link

Document

Gets the serializable object containing this message's data.

Usage

From source file:org.logicblaze.lingo.jms.marshall.DefaultMarshaller.java

public Object readMessage(Message message) throws JMSException {
    handleMessageHeaders(message);//  w  ww . j a  v a2  s  .  c  o  m
    if (message instanceof ObjectMessage) {
        ObjectMessage objectMessage = (ObjectMessage) message;
        return objectMessage.getObject();
    } else if (message instanceof TextMessage) {
        TextMessage textMessage = (TextMessage) message;
        return textMessage.getText();
    }
    return onInvalidMessage(message);
}

From source file:org.okj.commons.broker.SimpleMessageSubscriber.java

/** 
 * @see javax.jms.MessageListener#onMessage(javax.jms.Message)
 *///w  ww . jav a  2s  .c o  m
@Override
public void onMessage(Message message) {
    MessageEvent event = null;
    try {
        //?
        if (message instanceof ObjectMessage) {
            ObjectMessage msg = (ObjectMessage) message;
            if (msg.getObject() instanceof MessageEvent) {
                event = (MessageEvent) msg.getObject();
            }
        }

        //??
        if (event == null) {
            LogUtils.warn(LOGGER, "????, message={0}",
                    message);
            return;
        }

        if (this.executor != null) {
            //
            this.executor.execute(event);
        }
    } catch (JMSException ex) {
        LogUtils.error(LOGGER, "???", ex);
    } catch (Exception ex) {
        LogUtils.error(LOGGER, "?", ex);
    }
}

From source file:org.logicblaze.lingo.jms.marshall.DefaultMarshaller.java

public RemoteInvocationResult extractInvocationResult(Message message) throws JMSException {
    handleInvocationResultHeaders(message);
    if (message instanceof ObjectMessage) {
        ObjectMessage objectMessage = (ObjectMessage) message;
        Object body = objectMessage.getObject();
        if (body instanceof RemoteInvocationResult) {
            return (RemoteInvocationResult) body;
        }//from   w ww. ja va  2s  .c  om
    }
    return onInvalidClientMessage(message);
}

From source file:org.logicblaze.lingo.jms.marshall.DefaultMarshaller.java

public RemoteInvocation readRemoteInvocation(Message message) throws JMSException {
    handleInvocationHeaders(message);//from  ww w . j  a  v  a  2s .com
    if (message instanceof ObjectMessage) {
        ObjectMessage objectMessage = (ObjectMessage) message;
        Object body = objectMessage.getObject();
        if (body instanceof RemoteInvocation) {
            return (RemoteInvocation) body;
        }
    }
    return onInvalidMessage(message);
}

From source file:com.npower.dm.service.SmsSenderObserverImpl.java

public void onMessage(Message message) {
    try {/*  w  w  w  .  j  a  v  a  2  s . co  m*/
        SmsSenderObserverEvent event = null;
        if (message != null) {
            if (message instanceof ObjectMessage) {
                ObjectMessage m = (ObjectMessage) message;
                event = (SmsSenderObserverEvent) m.getObject();
            }
        }
        if (event == null) {
            log.error("unkonw sms observer event in queue: " + message);
            return;
        }
        if (log.isDebugEnabled()) {
            log.debug("processing sms observer event, type: " + event.getType() + ", id: "
                    + event.getTarget().getID());
        }

        this.setEvent(event);

        if (log.isDebugEnabled()) {
            log.debug("end processing sms observer event, type: " + event.getType() + ", id: "
                    + event.getTarget().getID());
        }
    } catch (Exception e) {
        log.error("failure to process sms message", e);
    } finally {
    }
}

From source file:org.yestech.publish.service.JmsQueuePublishConsumer.java

public void onMessage(Message message) {
    if (message instanceof ObjectMessage) {
        ObjectMessage objMessage = (ObjectMessage) message;
        String fileLocation = "";
        try {/*  www. j  a  v  a  2 s . c  o m*/
            IArtifact artifact = translateArtifact((IArtifact) objMessage.getObject());
            if (PublishUtils.isFileArtifact(artifact)) {
                IFileArtifact fileArtifact = (IFileArtifact) artifact;
                String url = objMessage.getStringProperty(IPublishConstant.URL);
                String fileName = objMessage.getStringProperty(IPublishConstant.FILE_NAME);
                fileLocation = url + fileName;
                URL artifactUrl = new URL(fileLocation);
                String fqn = PublishUtils.saveTempFile(tempDirectory, artifactUrl.openStream(), fileArtifact);
                recieve(fileArtifact);
                PublishUtils.removeTempFile(fqn);
            } else {
                recieve(artifact);
            }
        } catch (Exception e) {
            logger.error("error retrieving artifact...", e);
        }
    }

}

From source file:nz.net.orcon.kanban.automation.ClusterManagerImpl.java

public Long getId(String path, String field) throws Exception {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Generating ID from " + path + "." + field);
    }//from ww  w .ja  v  a 2s  .  c  o  m

    Message message = requestId(path, field);

    if (message == null) {
        executeChallenge();
        message = requestId(path, field);
    }

    ObjectMessage objectMessage = (ObjectMessage) message;
    IdResponse idResponse = (IdResponse) objectMessage.getObject();
    return idResponse.getId();
}

From source file:nz.net.orcon.kanban.controllers.CardsLockCache.java

@Override
public void onMessage(Message message) {

    try {//w ww .j  ava  2 s.c  o m
        ObjectMessage objectMessage = (ObjectMessage) message;
        CardLock cardLock = (CardLock) objectMessage.getObject();
        actualLock(cardLock);
    } catch (Exception e) {
        logger.error("JMS Exception on Card Locking Reception ", e);
    }
}

From source file:com.alliander.osgp.signing.server.infra.messaging.SigningServerRequestMessageListener.java

@Override
public void onMessage(final Message message) {
    try {//from w  ww.j a v a 2  s. c  o m
        final ObjectMessage objectMessage = (ObjectMessage) message;
        final Destination replyToQueue = objectMessage.getJMSReplyTo();
        final RequestMessage requestMessage = (RequestMessage) objectMessage.getObject();
        final UnsignedOslpEnvelopeDto unsignedOslpEnvelopeDto = (UnsignedOslpEnvelopeDto) requestMessage
                .getRequest();
        final String correlationUid = objectMessage.getJMSCorrelationID();
        final String deviceIdentification = objectMessage.getStringProperty(Constants.DEVICE_IDENTIFICATION);

        LOGGER.info("Received message of type: {}, for device: {} with correlationId: {} and replyToQueue: {}",
                objectMessage.getJMSType(), deviceIdentification, correlationUid, replyToQueue.toString());

        LOGGER.debug("-----------------------------------------------------------------------------");
        LOGGER.debug("unsignedOslpEnvelopeDto.getCorrelationUid() : {}",
                unsignedOslpEnvelopeDto.getCorrelationUid());
        LOGGER.debug("unsignedOslpEnvelopeDto.getDeviceId() : {}", unsignedOslpEnvelopeDto.getDeviceId());
        LOGGER.debug("unsignedOslpEnvelopeDto.getDomain() : {}", unsignedOslpEnvelopeDto.getDomain());
        LOGGER.debug("unsignedOslpEnvelopeDto.getDomainVersion() : {}",
                unsignedOslpEnvelopeDto.getDomainVersion());
        LOGGER.debug("unsignedOslpEnvelopeDto.getIpAddress() : {}", unsignedOslpEnvelopeDto.getIpAddress());
        LOGGER.debug("unsignedOslpEnvelopeDto.getMessageType() : {}", unsignedOslpEnvelopeDto.getMessageType());
        LOGGER.debug("unsignedOslpEnvelopeDto.getOrganisationIdentification() : {}",
                unsignedOslpEnvelopeDto.getOrganisationIdentification());
        LOGGER.debug("unsignedOslpEnvelopeDto.getPayloadMessage() : {}",
                unsignedOslpEnvelopeDto.getPayloadMessage().toString());
        LOGGER.debug("unsignedOslpEnvelopeDto.getRetryCount() : {}", unsignedOslpEnvelopeDto.getRetryCount());
        LOGGER.debug("unsignedOslpEnvelopeDto.getSequenceNumber() : {}",
                unsignedOslpEnvelopeDto.getSequenceNumber());
        LOGGER.debug("unsignedOslpEnvelopeDto.isScheduled() : {}", unsignedOslpEnvelopeDto.isScheduled());
        LOGGER.debug("-----------------------------------------------------------------------------");

        this.signingService.sign(unsignedOslpEnvelopeDto, correlationUid, deviceIdentification, replyToQueue);

    } catch (final JMSException ex) {
        LOGGER.error("Exception: {} ", ex.getMessage(), ex);
    }
}

From source file:be.fedict.eid.pkira.blm.model.mail.MailHandlerBean.java

@Override
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void onMessage(Message arg0) {
    ObjectMessage objectMessage = (ObjectMessage) arg0;
    try {/*from   ww w .java2  s  .  co  m*/
        Mail mail = (Mail) objectMessage.getObject();

        // Get properties
        String mailProtocol = getMailProtocol();
        String mailServer = getSmtpServer();
        String mailUser = getSmtpUser();
        String mailPort = getSmtpPort();
        String mailPassword = getSmtpPassword();

        // Initialize a mail session
        Properties props = new Properties();
        props.put("mail." + mailProtocol + ".host", mailServer);
        props.put("mail." + mailProtocol + ".port", mailPort);
        Session session = Session.getInstance(props);

        // Create the message
        MimeMessage msg = new MimeMessage(session);
        msg.setFrom(new InternetAddress(mail.getSender()));
        for (String recipient : mail.getRecipients()) {
            msg.addRecipient(RecipientType.TO, new InternetAddress(recipient));
        }
        msg.setSubject(mail.getSubject(), "UTF-8");

        Multipart multipart = new MimeMultipart();
        msg.setContent(multipart);

        // Set the email message text and attachment
        MimeBodyPart messagePart = new MimeBodyPart();
        messagePart.setContent(mail.getBody(), mail.getContentType());
        multipart.addBodyPart(messagePart);

        if (mail.getAttachmentData() != null) {
            ByteArrayDataSource byteArrayDataSource = new ByteArrayDataSource(mail.getAttachmentData(),
                    mail.getAttachmentContentType());
            DataHandler dataHandler = new DataHandler(byteArrayDataSource);
            MimeBodyPart attachmentPart = new MimeBodyPart();
            attachmentPart.setDataHandler(dataHandler);
            attachmentPart.setFileName(mail.getAttachmentFileName());

            multipart.addBodyPart(attachmentPart);
        }

        // Open transport and send message
        Transport transport = session.getTransport(mailProtocol);
        if (StringUtils.isNotBlank(mailUser)) {
            transport.connect(mailUser, mailPassword);
        } else {
            transport.connect();
        }
        msg.saveChanges();
        transport.sendMessage(msg, msg.getAllRecipients());
    } catch (JMSException e) {
        errorLogger.logError(ApplicationComponent.MAIL, "Cannot handle the object message from the queue", e);
        throw new RuntimeException(e);
    } catch (MessagingException e) {
        errorLogger.logError(ApplicationComponent.MAIL, "Cannot send a mail message", e);
        throw new RuntimeException(e);
    }
}