Example usage for javax.jms ObjectMessage getJMSMessageID

List of usage examples for javax.jms ObjectMessage getJMSMessageID

Introduction

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

Prototype


String getJMSMessageID() throws JMSException;

Source Link

Document

Gets the message ID.

Usage

From source file:dk.netarkivet.common.distribute.JMSConnection.java

/**
 * Sends an ObjectMessage on a queue destination.
 *
 * @param msg the NetarkivetMessage to be wrapped and send as an
 *            ObjectMessage./*  w  w w  .  ja  v  a2 s  .co m*/
 * @param to  the destination topic.
 *
 * @throws JMSException if message failed to be sent.
 */
private void doSend(NetarkivetMessage msg, ChannelID to) throws JMSException {
    connectionLock.readLock().lock();
    try {
        ObjectMessage message = getSession().createObjectMessage(msg);
        synchronized (msg) {
            getProducer(to.getName()).send(message);
            // Note: Id is only updated if the message does not already have
            // an id. This ensures that resent messages keep the same ID
            // TODO Is it always OK for resent messages to keep the same ID

            // FIXME Solution for NAS-2043 doesn't work; rolled back
            //String randomID = UUID.randomUUID().toString();
            //msg.updateId(randomID);
            msg.updateId(message.getJMSMessageID());

        }
    } finally {
        connectionLock.readLock().unlock();
    }
    log.trace("Sent message '" + msg.toString() + "'");
}

From source file:org.jbpm.bpel.integration.jms.RequestListener.java

public void onMessage(Message message) {
    if (!(message instanceof ObjectMessage)) {
        log.error("received non-object message: " + message);
        return;/*  www.j ava  2 s . c o  m*/
    }
    try {
        ObjectMessage request = (ObjectMessage) message;
        log.debug("delivering request: " + RequestListener.messageToString(request));
        /*
         * LEAK WARNING. This listener must be removed from the integration control before passing
         * control to the inbound message activity, because loop structures could execute the same
         * activity again and overwrite the entry in the integration control with a new listener. If
         * removeRequestListener() was invoked after passing control to the activity, the new listener
         * would get removed instead of this, leaving the listener open but unreachable from
         * application code. CODE ORDER NOTE. Removing this listener early in the process prevents any
         * other thread from closing it. This effect is desirable because the orderly shutdown
         * mechanism of JMS never stops a running listener anyway. Furthermore, the mechanism is
         * specified to *block* the other thread until this listener returns.
         */
        if (oneShot)
            integrationControl.removeRequestListener(this);

        deliverRequest((Map) request.getObject(), request.getJMSReplyTo(), request.getJMSMessageID());
        request.acknowledge();

        if (oneShot)
            close();
    } catch (JMSException e) {
        log.error("request delivery failed due to jms exception, giving up", e);
    } catch (RuntimeException e) {
        if (isRecoverable(e)) {
            log.warn("request delivery failed due to recoverable exception, attempting recovery");
            try {
                // recover the session manually
                jmsSession.recover();
            } catch (JMSException je) {
                log.error("request recovery failed, giving up", je);
            }
        } else
            log.error("request delivery failed due to non-recoverable exception, giving up", e);
    }
}

From source file:org.jbpm.bpel.integration.jms.StartListener.java

public void onMessage(Message message) {
    if (!(message instanceof ObjectMessage)) {
        log.error("received non-object jms message: " + message);
        return;/*  w  w w . ja  v  a 2 s  .  co m*/
    }

    try {
        ObjectMessage request = (ObjectMessage) message;
        log.debug("delivering request: " + RequestListener.messageToString(request));

        /*
         * CODE ORDER NOTE. Removing this listener early in the process prevents any other thread from
         * closing it. This effect is desirable because the orderly shutdown mechanism of JMS never
         * stops a running listener anyway. Furthermore, the mechanism is specified to *block* the
         * other thread until this listener returns.
         */
        integrationControl.removeStartListener(this);

        // BPEL-282 create new start listener to improve concurrency
        StartListener startListener = new StartListener(this);
        startListener.open();

        deliverRequest((Map) request.getObject(), request.getJMSReplyTo(), request.getJMSMessageID());
        request.acknowledge();

        close();
    } catch (JMSException e) {
        log.error("request delivery failed due to jms exception, giving up", e);
    } catch (RuntimeException e) {
        if (RequestListener.isRecoverable(e)) {
            log.warn("request delivery failed due to recoverable exception, attempting recovery");
            try {
                // recover the session manually
                jmsSession.recover();
            } catch (JMSException je) {
                log.error("request recovery failed, giving up", je);
            }
        } else
            log.error("request delivery failed due to non-recoverable exception, giving up", e);
    }
}

From source file:org.jbpm.bpel.integration.server.SoapHandler.java

public boolean handleRequest(MessageContext messageContext) throws JAXRPCException, SOAPFaultException {
    /*//from  w w w  .j a  v  a  2s.  c  om
     * WSEE 1.1 section 6.2.2.1: If Handler instances are pooled, they must be pooled by Port
     * component. This is because Handlers may retain non-client specific state across method calls
     * that are specific to the Port component.
     */
    if (integrationControl == null) {
        /*
         * COMPLIANCE NOTE: the state initialized in this call is port-component specific, but
         * non-client specific
         */
        lookupEndpointMetadata(messageContext);
    }

    JbpmContext jbpmContext = integrationControl.getIntegrationServiceFactory().getJbpmConfiguration()
            .createJbpmContext();
    try {
        Session jmsSession = integrationControl.createJmsSession();
        try {
            SOAPMessage soapMessage = ((SOAPMessageContext) messageContext).getMessage();
            ObjectMessage jmsRequest = sendRequest(soapMessage, jmsSession, jbpmContext);

            Destination replyTo = jmsRequest.getJMSReplyTo();
            if (replyTo != null) {
                ObjectMessage jmsResponse = receiveResponse(jmsSession, replyTo, jmsRequest.getJMSMessageID(),
                        jbpmContext);

                // remember operation name and message parts for handling response
                messageContext.setProperty(OPERATION_NAME_PROP,
                        jmsRequest.getStringProperty(IntegrationConstants.OPERATION_NAME_PROP));
                messageContext.setProperty(MESSAGE_PARTS_PROP, jmsResponse.getObject());

                // is response a fault?
                String faultName = jmsResponse.getStringProperty(IntegrationConstants.FAULT_NAME_PROP);
                if (faultName != null) {
                    // remember fault name for handling fault
                    messageContext.setProperty(FAULT_NAME_PROP, faultName);
                    throw new SOAPFaultException(SoapBindConstants.CLIENT_FAULTCODE,
                            SoapBindConstants.BUSINESS_FAULTSTRING, null, null);
                }
            }
        } finally {
            jmsSession.close();
        }
    }
    /*
     * NO need to set jbpm context as rollback only for any exception, since operations in try-block
     * only read definitions from database
     */
    catch (SOAPFaultException e) {
        log.debug("request caused a fault", e);
        messageContext.setProperty(FAULT_EXCEPTION_PROP, e);
    } catch (SOAPException e) {
        /*
         * BP 1.2 R2724: If an INSTANCE receives an envelope that is inconsistent with its WSDL
         * description, it SHOULD generate a soap:Fault with a faultcode of "Client", unless a
         * "MustUnderstand" or "VersionMismatch" fault is generated.
         */
        log.debug("incoming soap message carries invalid content", e);
        messageContext.setProperty(FAULT_EXCEPTION_PROP,
                new SOAPFaultException(SoapBindConstants.CLIENT_FAULTCODE, e.getMessage(), null, null));
    } catch (JMSException e) {
        throw new JAXRPCException("message delivery failed", e);
    } finally {
        jbpmContext.close();
    }
    return true;
}

From source file:org.socraticgrid.taskmanager.TaskManagerImpl.java

/**
 * Queue the message to the task handler.
 *
 * @param msgObject//from w  w  w .  j  a  va2  s .c om
 * @return
 */
private QueueResponse queueMessage(java.io.Serializable msgObject) {
    QueueResponse response = new QueueResponse();
    String taskQ = null;
    QueueConnection queueConnection = null;

    try {
        //Get task queue name & queue factory
        taskQ = PropertyAccessor.getProperty(TASKMANAGER_PROPERTY_FILE, PROPERTY_TASK_QUEUE);
        String taskQFactory = PropertyAccessor.getProperty(TASKMANAGER_PROPERTY_FILE,
                PROPERTY_TASK_QUEUE_FACTORY);

        //Get queue connection
        Context jndiContext = new InitialContext();
        QueueConnectionFactory queueConnectionFactory = (QueueConnectionFactory) jndiContext
                .lookup(taskQFactory);
        Queue queue = (Queue) jndiContext.lookup(taskQ);

        //Create connection session
        queueConnection = queueConnectionFactory.createQueueConnection();
        QueueSession queueSession = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
        QueueSender queueSender = queueSession.createSender(queue);

        //Create message
        ObjectMessage message = queueSession.createObjectMessage(msgObject);

        //Send message
        queueSender.send(message);

        //Set response info
        response.ticket = message.getJMSMessageID();
        response.detail = TASK_MESSAGE_SUCCESS;
    } catch (PropertyAccessException pae) {
        String msg = TASK_MESSAGE_FAILURE + ": error accessing task properties in file:"
                + TASKMANAGER_PROPERTY_FILE + ".";
        log.error(msg, pae);
        response.ticket = TASK_MESSAGE_FAILURE_ID;
        response.detail = msg;
    } catch (NamingException ne) {
        String msg = TASK_MESSAGE_FAILURE + ": error creating connection to queue: " + taskQ + ".";
        log.error(msg, ne);
        response.ticket = TASK_MESSAGE_FAILURE_ID;
        response.detail = msg;
    } catch (JMSException jmse) {
        String msg = TASK_MESSAGE_FAILURE + ": error occurred trying to send notificaiton to task queue: "
                + taskQ + ".";
        log.error(msg, jmse);
        response.ticket = TASK_MESSAGE_FAILURE_ID;
        response.detail = msg;
    } finally {
        //Close queue
        if (queueConnection != null) {
            try {
                queueConnection.close();
            } catch (JMSException e) {
            }
        }
    }

    return response;
}