Search in sources :

Example 66 with Destination

use of javax.jms.Destination in project hono by eclipse.

the class DeviceRegistrationIT method testOpenReceiverFailsForMalformedReplyToAddress.

/**
 * Verifies that a client must use a correct <em>reply-to</em> address when opening a link for receiving registration responses.
 *
 * @throws Exception if the test fails.
 */
@Test
public void testOpenReceiverFailsForMalformedReplyToAddress() throws Exception {
    // GIVEN a source address that does not contain a resourceId segment
    final Destination invalidSource = new JmsQueue("registration/" + JmsIntegrationTestSupport.TEST_TENANT_ID);
    // WHEN trying to open a receiver link using the malformed source address
    try {
        registration.createConsumerWithoutListener(invalidSource);
        fail("Should have failed to create consumer");
    } catch (JMSException e) {
    // THEN the attempt fails
    }
}
Also used : Destination(javax.jms.Destination) JmsQueue(org.apache.qpid.jms.JmsQueue) JMSException(javax.jms.JMSException) Test(org.junit.Test)

Example 67 with Destination

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

the class JMSUtils method getTransportHeaders.

/**
 * Extract transport level headers for JMS from the given message into a Map
 *
 * @param message the JMS message
 * @return a Map of the transport headers
 */
public static Map<String, Object> getTransportHeaders(Message message, MessageContext msgContext) {
    // create a Map to hold transport headers
    Map<String, Object> map = new HashMap<String, Object>();
    // correlation ID
    try {
        if (message.getJMSCorrelationID() != null) {
            map.put(JMSConstants.JMS_COORELATION_ID, message.getJMSCorrelationID());
        }
    } catch (JMSException ignore) {
    }
    // set the delivery mode as persistent or not
    try {
        map.put(JMSConstants.JMS_DELIVERY_MODE, Integer.toString(message.getJMSDeliveryMode()));
    } catch (JMSException ignore) {
    }
    // destination name
    try {
        if (message.getJMSDestination() != null) {
            Destination dest = message.getJMSDestination();
            map.put(JMSConstants.JMS_DESTINATION, dest instanceof Queue ? ((Queue) dest).getQueueName() : ((Topic) dest).getTopicName());
        }
    } catch (JMSException ignore) {
    }
    // expiration
    try {
        map.put(JMSConstants.JMS_EXPIRATION, Long.toString(message.getJMSExpiration()));
    } catch (JMSException ignore) {
    }
    // if a JMS message ID is found
    try {
        if (message.getJMSMessageID() != null) {
            map.put(JMSConstants.JMS_MESSAGE_ID, message.getJMSMessageID());
        }
    } catch (JMSException ignore) {
    }
    // priority
    try {
        map.put(JMSConstants.JMS_PRIORITY, Long.toString(message.getJMSPriority()));
    } catch (JMSException ignore) {
    }
    // redelivered
    try {
        map.put(JMSConstants.JMS_REDELIVERED, Boolean.toString(message.getJMSRedelivered()));
    } catch (JMSException ignore) {
    }
    // replyto destination name
    try {
        if (message.getJMSReplyTo() != null) {
            Destination dest = message.getJMSReplyTo();
            map.put(JMSConstants.JMS_REPLY_TO, dest instanceof Queue ? ((Queue) dest).getQueueName() : ((Topic) dest).getTopicName());
        }
    } catch (JMSException ignore) {
    }
    // priority
    try {
        map.put(JMSConstants.JMS_TIMESTAMP, Long.toString(message.getJMSTimestamp()));
    } catch (JMSException ignore) {
    }
    // message type
    try {
        if (message.getJMSType() != null) {
            map.put(JMSConstants.JMS_TYPE, message.getJMSType());
        }
    } catch (JMSException ignore) {
    }
    // any other transport properties / headers
    Enumeration<?> e = null;
    try {
        e = message.getPropertyNames();
    } catch (JMSException ignore) {
    }
    if (e != null) {
        while (e.hasMoreElements()) {
            String headerName = (String) e.nextElement();
            try {
                if (isHyphenReplaceMode(msgContext)) {
                    map.put(inverseTransformHyphenatedString(headerName), message.getStringProperty(headerName));
                } else {
                    map.put(headerName, message.getStringProperty(headerName));
                }
                continue;
            } catch (JMSException ignore) {
            }
            try {
                map.put(headerName, message.getBooleanProperty(headerName));
                continue;
            } catch (JMSException ignore) {
            }
            try {
                map.put(headerName, message.getIntProperty(headerName));
                continue;
            } catch (JMSException ignore) {
            }
            try {
                map.put(headerName, message.getLongProperty(headerName));
                continue;
            } catch (JMSException ignore) {
            }
            try {
                map.put(headerName, message.getDoubleProperty(headerName));
                continue;
            } catch (JMSException ignore) {
            }
            try {
                map.put(headerName, message.getFloatProperty(headerName));
            } catch (JMSException ignore) {
            }
        }
    }
    return map;
}
Also used : Destination(javax.jms.Destination) HashMap(java.util.HashMap) JMSException(javax.jms.JMSException) Topic(javax.jms.Topic) Queue(javax.jms.Queue)

Example 68 with Destination

use of javax.jms.Destination in project cxf by apache.

the class BackChannelConduit method send.

private void send(final Message outMessage, final Object replyObj, ResourceCloser closer) throws JMSException {
    Connection connection;
    if (persistentConnection == null) {
        connection = closer.register(JMSFactory.createConnection(jmsConfig));
    } else {
        connection = this.persistentConnection;
    }
    Session session = closer.register(connection.createSession(false, Session.AUTO_ACKNOWLEDGE));
    JMSMessageHeadersType outProps = (JMSMessageHeadersType) outMessage.get(JMS_SERVER_RESPONSE_HEADERS);
    JMSMessageHeadersType inProps = (JMSMessageHeadersType) inMessage.get(JMS_SERVER_REQUEST_HEADERS);
    initResponseMessageProperties(outProps, inProps);
    // setup the reply message
    final javax.jms.Message request = (javax.jms.Message) inMessage.get(JMS_REQUEST_MESSAGE);
    if (isTimedOut(request)) {
        return;
    }
    Destination replyTo = getReplyToDestination(session, inMessage);
    if (replyTo == null) {
        throw new RuntimeException("No replyTo destination set");
    }
    final String msgType = getMessageType(outMessage, request);
    String correlationId = determineCorrelationID(request);
    javax.jms.Message reply = JMSMessageUtils.asJMSMessage(jmsConfig, outMessage, replyObj, msgType, session, correlationId, JMS_SERVER_RESPONSE_HEADERS);
    JMSSender sender = JMSFactory.createJmsSender(jmsConfig, outProps);
    LOG.log(Level.FINE, "server sending reply: ", reply);
    sender.sendMessage(session, replyTo, reply);
}
Also used : Destination(javax.jms.Destination) TextMessage(javax.jms.TextMessage) Message(org.apache.cxf.message.Message) Connection(javax.jms.Connection) JMSSender(org.apache.cxf.transport.jms.util.JMSSender) Session(javax.jms.Session)

Example 69 with Destination

use of javax.jms.Destination in project cxf by apache.

the class JMSConduit method sendMessage.

private String sendMessage(final Object request, final Message outMessage, Destination replyToDestination, String correlationId, ResourceCloser closer, Session session) throws JMSException {
    JMSMessageHeadersType headers = getOrCreateJmsHeaders(outMessage);
    javax.jms.Message message = JMSMessageUtils.asJMSMessage(jmsConfig, outMessage, request, jmsConfig.getMessageType(), session, correlationId, JMSConstants.JMS_CLIENT_REQUEST_HEADERS);
    if (replyToDestination == null && headers.isSetJMSReplyTo()) {
        String replyTo = headers.getJMSReplyTo();
        replyToDestination = jmsConfig.getReplyDestination(session, replyTo);
    }
    if (replyToDestination != null) {
        message.setJMSReplyTo(replyToDestination);
    }
    JMSSender sender = JMSFactory.createJmsSender(jmsConfig, headers);
    Destination targetDest = jmsConfig.getTargetDestination(session);
    sender.sendMessage(session, targetDest, message);
    String jmsMessageID = message.getJMSMessageID();
    LOG.log(Level.FINE, "client sending request message " + jmsMessageID + " to " + targetDest);
    headers.setJMSMessageID(jmsMessageID);
    return jmsMessageID;
}
Also used : Destination(javax.jms.Destination) JMSSender(org.apache.cxf.transport.jms.util.JMSSender)

Example 70 with Destination

use of javax.jms.Destination in project cxf by apache.

the class JMSConfiguration method getReplyToDestination.

public Destination getReplyToDestination(Session session, String userDestination) throws JMSException {
    if (userDestination != null) {
        return destinationResolver.resolveDestinationName(session, userDestination, replyPubSubDomain);
    }
    if (replyToDestination == null) {
        return getReplyDestination(session);
    }
    Destination result = replyToDestinationDest;
    if (result == null) {
        synchronized (this) {
            result = replyToDestinationDest;
            if (result == null) {
                result = destinationResolver.resolveDestinationName(session, replyToDestination, replyPubSubDomain);
                replyToDestinationDest = result;
            }
        }
    }
    return result;
}
Also used : Destination(javax.jms.Destination)

Aggregations

Destination (javax.jms.Destination)178 Test (org.junit.Test)51 TextMessage (javax.jms.TextMessage)47 Session (javax.jms.Session)46 JMSException (javax.jms.JMSException)45 Connection (javax.jms.Connection)32 MessageProducer (javax.jms.MessageProducer)31 Message (javax.jms.Message)30 ConnectionFactory (javax.jms.ConnectionFactory)24 MessageConsumer (javax.jms.MessageConsumer)24 JMSContext (javax.jms.JMSContext)16 CountDownLatch (java.util.concurrent.CountDownLatch)15 ObjectMessage (javax.jms.ObjectMessage)12 StubTextMessage (org.springframework.jms.StubTextMessage)11 InitialContext (javax.naming.InitialContext)10 ActiveMQQueue (org.apache.activemq.command.ActiveMQQueue)10 Queue (javax.jms.Queue)8 ActiveMQConnectionFactory (org.apache.activemq.ActiveMQConnectionFactory)8 MapMessage (javax.jms.MapMessage)7 HashMap (java.util.HashMap)6