Search in sources :

Example 71 with TemporaryQueue

use of javax.jms.TemporaryQueue in project spring-integration by spring-projects.

the class JmsOutboundGateway method sendAndReceiveWithoutContainer.

private javax.jms.Message sendAndReceiveWithoutContainer(Message<?> requestMessage) throws JMSException {
    // NOSONAR - closed in ConnectionFactoryUtils.
    Connection connection = this.createConnection();
    Session session = null;
    Destination replyTo = null;
    try {
        session = this.createSession(connection);
        // convert to JMS Message
        Object objectToSend = requestMessage;
        if (this.extractRequestPayload) {
            objectToSend = requestMessage.getPayload();
        }
        javax.jms.Message jmsRequest = this.messageConverter.toMessage(objectToSend, session);
        // map headers
        this.headerMapper.fromHeaders(requestMessage.getHeaders(), jmsRequest);
        replyTo = this.determineReplyDestination(requestMessage, session);
        jmsRequest.setJMSReplyTo(replyTo);
        connection.start();
        if (logger.isDebugEnabled()) {
            logger.debug("ReplyTo: " + replyTo);
        }
        Integer priority = new IntegrationMessageHeaderAccessor(requestMessage).getPriority();
        if (priority == null) {
            priority = this.priority;
        }
        javax.jms.Message replyMessage = null;
        Destination requestDestination = this.determineRequestDestination(requestMessage, session);
        if (this.correlationKey != null) {
            replyMessage = doSendAndReceiveWithGeneratedCorrelationId(requestDestination, jmsRequest, replyTo, session, priority);
        } else if (replyTo instanceof TemporaryQueue || replyTo instanceof TemporaryTopic) {
            replyMessage = doSendAndReceiveWithTemporaryReplyToDestination(requestDestination, jmsRequest, replyTo, session, priority);
        } else {
            replyMessage = doSendAndReceiveWithMessageIdCorrelation(requestDestination, jmsRequest, replyTo, session, priority);
        }
        return replyMessage;
    } finally {
        JmsUtils.closeSession(session);
        this.deleteDestinationIfTemporary(replyTo);
        ConnectionFactoryUtils.releaseConnection(connection, this.connectionFactory, true);
    }
}
Also used : Destination(javax.jms.Destination) IntegrationMessageHeaderAccessor(org.springframework.integration.IntegrationMessageHeaderAccessor) Connection(javax.jms.Connection) TemporaryQueue(javax.jms.TemporaryQueue) Session(javax.jms.Session) TemporaryTopic(javax.jms.TemporaryTopic)

Example 72 with TemporaryQueue

use of javax.jms.TemporaryQueue in project wildfly by wildfly.

the class InjectedJMSContextTestCase method sendWith_REQUIRED_transaction.

private void sendWith_REQUIRED_transaction(boolean rollback) throws JMSException {
    String text = UUID.randomUUID().toString();
    try (JMSContext context = factory.createContext()) {
        TemporaryQueue tempQueue = context.createTemporaryQueue();
        producerBean.sendToDestination(tempQueue, text, rollback);
        assertMessageIsReceived(tempQueue, context, text, rollback);
    }
}
Also used : TemporaryQueue(javax.jms.TemporaryQueue) JMSContext(javax.jms.JMSContext)

Example 73 with TemporaryQueue

use of javax.jms.TemporaryQueue in project wildfly by wildfly.

the class InjectedJMSContextTestCase method sendAndReceiveFromMDB.

private void sendAndReceiveFromMDB(boolean rollback) throws JMSException {
    String text = "sendAndReceiveFromMDB " + rollback;
    try (JMSContext context = factory.createContext()) {
        TemporaryQueue replyTo = context.createTemporaryQueue();
        context.createProducer().setJMSReplyTo(replyTo).setProperty("rollback", rollback).send(queue, text);
        assertMessageIsReceived(replyTo, context, text, rollback);
    }
}
Also used : TemporaryQueue(javax.jms.TemporaryQueue) JMSContext(javax.jms.JMSContext)

Example 74 with TemporaryQueue

use of javax.jms.TemporaryQueue in project wildfly by wildfly.

the class VaultedInjectedJMSContextTestCase method sendMessage.

@Test
public void sendMessage() throws JMSException {
    String text = UUID.randomUUID().toString();
    try (JMSContext context = factory.createContext()) {
        TemporaryQueue tempQueue = context.createTemporaryQueue();
        producerBean.sendToDestination(tempQueue, text);
        JMSConsumer consumer = context.createConsumer(tempQueue);
        String reply = consumer.receiveBody(String.class, adjust(2000));
        assertEquals(text, reply);
    }
}
Also used : JMSConsumer(javax.jms.JMSConsumer) TemporaryQueue(javax.jms.TemporaryQueue) JMSContext(javax.jms.JMSContext) Test(org.junit.Test)

Example 75 with TemporaryQueue

use of javax.jms.TemporaryQueue in project wso2-axis2-transports by wso2.

the class JMSSender method sendMessage.

/**
 * Performs the actual sending of the JMS message
 */
@Override
public void sendMessage(MessageContext msgCtx, String targetAddress, OutTransportInfo outTransportInfo) throws AxisFault {
    JMSConnectionFactory jmsConnectionFactory = null;
    JMSOutTransportInfo jmsOut = null;
    JMSMessageSender messageSender = null;
    if (targetAddress != null) {
        jmsOut = new JMSOutTransportInfo(targetAddress);
        // do we have a definition for a connection factory to use for this address?
        jmsConnectionFactory = getJMSConnectionFactory(jmsOut);
        if (jmsConnectionFactory == null) {
            jmsConnectionFactory = connFacManager.getConnectionFactoryFromTargetEndpoint(targetAddress);
        }
        // It can be identified by looking at target url's transport.jms.TransactionCommand parameter.
        if ((targetAddress.contains(JMSConstants.JMS_TRANSACTION_COMMAND))) {
            try {
                messageSender = jmsOut.createJMSSender(msgCtx);
                Transaction transaction = (Transaction) msgCtx.getProperty(JMSConstants.JMS_XA_TRANSACTION);
                if (jmsMessageSenderMap.get(transaction) == null) {
                    ArrayList list = new ArrayList();
                    list.add(messageSender);
                    jmsMessageSenderMap.put(transaction, list);
                } else {
                    ArrayList list = jmsMessageSenderMap.get(transaction);
                    list.add(messageSender);
                    jmsMessageSenderMap.put(transaction, list);
                }
            } catch (JMSException e) {
                rollbackIfXATransaction(msgCtx);
                handleException("Unable to create a JMSMessageSender for : " + outTransportInfo, e);
            }
        } else {
            messageSender = new JMSMessageSender(jmsConnectionFactory, targetAddress);
        }
    } else if (outTransportInfo instanceof JMSOutTransportInfo) {
        jmsOut = (JMSOutTransportInfo) outTransportInfo;
        try {
            messageSender = jmsOut.createJMSSender(msgCtx);
        } catch (JMSException e) {
            handleException("Unable to create a JMSMessageSender for : " + outTransportInfo, e);
        }
    }
    // The message property to be used to send the content type is determined by
    // the out transport info, i.e. either from the EPR if we are sending a request,
    // or, if we are sending a response, from the configuration of the service that
    // received the request). The property can be defined globally in axis2.xml JMSSender section as well.
    // The property name can be overridden by a message context property.
    String contentTypeProperty = getContentTypeProperty(msgCtx, jmsOut, jmsConnectionFactory);
    // Fix for ESBJAVA-3687, retrieve JMS transport property transport.jms.MessagePropertyHyphens and set this
    // into the msgCtx
    String hyphenSupport = JMSConstants.DEFAULT_HYPHEN_SUPPORT;
    if (jmsConnectionFactory != null && jmsConnectionFactory.getParameters().get(JMSConstants.PARAM_JMS_HYPHEN_MODE) != null) {
        hyphenSupport = jmsConnectionFactory.getParameters().get(JMSConstants.PARAM_JMS_HYPHEN_MODE);
    } else if (jmsOut.getProperties() != null && jmsOut.getProperties().get(JMSConstants.PARAM_JMS_HYPHEN_MODE) != null) {
        if (jmsOut.getProperties().get(JMSConstants.PARAM_JMS_HYPHEN_MODE).equals(JMSConstants.HYPHEN_MODE_REPLACE)) {
            hyphenSupport = JMSConstants.HYPHEN_MODE_REPLACE;
        } else if (jmsOut.getProperties().get(JMSConstants.PARAM_JMS_HYPHEN_MODE).equals(JMSConstants.HYPHEN_MODE_DELETE)) {
            hyphenSupport = JMSConstants.HYPHEN_MODE_DELETE;
        }
    }
    msgCtx.setProperty(JMSConstants.PARAM_JMS_HYPHEN_MODE, hyphenSupport);
    JMSReplyMessage jmsReplyMessage = null;
    // Set the status of the SessionWrapper as busy
    if (messageSender.getSessionWrapper() != null) {
        if (log.isDebugEnabled()) {
            log.debug("Set the status of the session as busy for " + messageSender.getSessionWrapper().getSession());
        }
        messageSender.getSessionWrapper().setBusy(true);
    }
    // need to synchronize as Sessions are not thread safe
    synchronized (messageSender.getSession()) {
        try {
            jmsReplyMessage = sendOverJMS(msgCtx, messageSender, contentTypeProperty, jmsConnectionFactory, jmsOut);
        } finally {
            if (msgCtx.getProperty(JMSConstants.JMS_XA_TRANSACTION_MANAGER) == null) {
                messageSender.close();
                if (jmsReplyMessage != null && jmsReplyMessage.getReplyDestination() instanceof TemporaryQueue) {
                    String temporaryQueueName = "";
                    TemporaryQueue temporaryQueue = (TemporaryQueue) jmsReplyMessage.getReplyDestination();
                    try {
                        temporaryQueueName = temporaryQueue.getQueueName();
                        temporaryQueue.delete();
                    } catch (JMSException e) {
                        log.error("Error while deleting the temporary queue " + temporaryQueueName, e);
                    }
                }
            }
            // Set the status of the SessionWrapper as free
            if (messageSender.getSessionWrapper() != null) {
                if (log.isDebugEnabled()) {
                    log.debug("Set the status of the session as free for " + messageSender.getSessionWrapper().getSession());
                }
                messageSender.getSessionWrapper().setBusy(false);
            }
        }
    }
    // for other threads.
    if (jmsReplyMessage.getMsgctx() != null) {
        handleIncomingMessage(jmsReplyMessage.getMsgctx(), jmsReplyMessage.getTransportHeaders(), jmsReplyMessage.getSoapAction(), jmsReplyMessage.getContentType());
    }
}
Also used : Transaction(javax.transaction.Transaction) ArrayList(java.util.ArrayList) TemporaryQueue(javax.jms.TemporaryQueue) JMSException(javax.jms.JMSException)

Aggregations

TemporaryQueue (javax.jms.TemporaryQueue)91 Session (javax.jms.Session)56 Test (org.junit.Test)47 Connection (javax.jms.Connection)45 MessageProducer (javax.jms.MessageProducer)38 MessageConsumer (javax.jms.MessageConsumer)35 Message (javax.jms.Message)27 JMSException (javax.jms.JMSException)25 TextMessage (javax.jms.TextMessage)24 JMSContext (javax.jms.JMSContext)13 BytesMessage (javax.jms.BytesMessage)10 Destination (javax.jms.Destination)8 Queue (javax.jms.Queue)8 ConnectionFactory (javax.jms.ConnectionFactory)7 ObjectMessage (javax.jms.ObjectMessage)7 JMSConsumer (javax.jms.JMSConsumer)6 TemporaryTopic (javax.jms.TemporaryTopic)6 HashMap (java.util.HashMap)5 MapMessage (javax.jms.MapMessage)5 StreamMessage (javax.jms.StreamMessage)5