Search in sources :

Example 1 with JMSEndpoint

use of org.apache.cxf.transport.jms.uri.JMSEndpoint in project cxf by apache.

the class JMSConfigFactory method createFromEndpoint.

/**
 * @param bus
 * @param endpointInfo
 * @return
 */
public static JMSConfiguration createFromEndpoint(Bus bus, JMSEndpoint endpoint) {
    JMSConfiguration jmsConfig = new JMSConfiguration();
    int deliveryMode = endpoint.getDeliveryMode() == org.apache.cxf.transport.jms.uri.JMSEndpoint.DeliveryModeType.PERSISTENT ? DeliveryMode.PERSISTENT : DeliveryMode.NON_PERSISTENT;
    jmsConfig.setDeliveryMode(deliveryMode);
    jmsConfig.setPriority(endpoint.getPriority());
    jmsConfig.setExplicitQosEnabled(true);
    jmsConfig.setMessageType(endpoint.getMessageType().value());
    boolean pubSubDomain = endpoint.getJmsVariant().contains(JMSEndpoint.TOPIC);
    jmsConfig.setPubSubDomain(pubSubDomain);
    jmsConfig.setDurableSubscriptionName(endpoint.getDurableSubscriptionName());
    jmsConfig.setDurableSubscriptionClientId(endpoint.getDurableSubscriptionClientId());
    jmsConfig.setReceiveTimeout(endpoint.getReceiveTimeout());
    jmsConfig.setTimeToLive(endpoint.getTimeToLive());
    jmsConfig.setSessionTransacted(endpoint.isSessionTransacted());
    if (!endpoint.isUseConduitIdSelector()) {
        jmsConfig.setUseConduitIdSelector(endpoint.isUseConduitIdSelector());
    }
    jmsConfig.setConduitSelectorPrefix(endpoint.getConduitIdSelectorPrefix());
    jmsConfig.setUserName(endpoint.getUsername());
    jmsConfig.setPassword(endpoint.getPassword());
    jmsConfig.setConcurrentConsumers(endpoint.getConcurrentConsumers());
    jmsConfig.setOneSessionPerConnection(endpoint.isOneSessionPerConnection());
    jmsConfig.setMessageSelector(endpoint.getMessageSelector());
    TransactionManager tm = getTransactionManager(bus, endpoint);
    jmsConfig.setTransactionManager(tm);
    if (endpoint.getJndiURL() != null) {
        // Configure Connection Factory using jndi
        jmsConfig.setJndiEnvironment(JMSConfigFactory.getInitialContextEnv(endpoint));
        jmsConfig.setConnectionFactoryName(endpoint.getJndiConnectionFactoryName());
    } else {
        ConfiguredBeanLocator locator = bus.getExtension(ConfiguredBeanLocator.class);
        if (endpoint.getConnectionFactory() != null) {
            jmsConfig.setConnectionFactory(endpoint.getConnectionFactory());
        } else if (locator != null) {
            // Configure ConnectionFactory using locator
            // Lookup connectionFactory in context like blueprint
            ConnectionFactory cf = locator.getBeanOfType(endpoint.getJndiConnectionFactoryName(), ConnectionFactory.class);
            if (cf != null) {
                jmsConfig.setConnectionFactory(cf);
            }
        }
    }
    boolean resolveUsingJndi = endpoint.getJmsVariant().contains(JMSEndpoint.JNDI);
    if (resolveUsingJndi) {
        // Setup Destination jndi destination resolver
        JndiHelper jt = new JndiHelper(JMSConfigFactory.getInitialContextEnv(endpoint));
        final JMSDestinationResolver jndiDestinationResolver = new JMSDestinationResolver();
        jndiDestinationResolver.setJndiTemplate(jt);
        jmsConfig.setDestinationResolver(jndiDestinationResolver);
        jmsConfig.setTargetDestination(endpoint.getDestinationName());
        setReplyDestination(jmsConfig, endpoint);
    } else {
        // Use the default dynamic destination resolver
        jmsConfig.setTargetDestination(endpoint.getDestinationName());
        setReplyDestination(jmsConfig, endpoint);
    }
    String requestURI = endpoint.getRequestURI();
    jmsConfig.setRequestURI(requestURI);
    String targetService = endpoint.getTargetService();
    jmsConfig.setTargetService(targetService);
    jmsConfig.setMessageSelector(endpoint.getMessageSelector());
    int retryInterval = endpoint.getRetryInterval();
    jmsConfig.setRetryInterval(retryInterval);
    return jmsConfig;
}
Also used : ConnectionFactory(javax.jms.ConnectionFactory) JndiHelper(org.apache.cxf.transport.jms.util.JndiHelper) ConfiguredBeanLocator(org.apache.cxf.configuration.ConfiguredBeanLocator) TransactionManager(javax.transaction.TransactionManager) JMSDestinationResolver(org.apache.cxf.transport.jms.util.JMSDestinationResolver) JMSEndpoint(org.apache.cxf.transport.jms.uri.JMSEndpoint)

Example 2 with JMSEndpoint

use of org.apache.cxf.transport.jms.uri.JMSEndpoint in project cxf by apache.

the class JMSMessageUtils method populateIncomingContext.

private static void populateIncomingContext(JMSMessageHeadersType messageHeaders, org.apache.cxf.message.Message inMessage) throws UnsupportedEncodingException {
    String contentType = messageHeaders.getContentType();
    if (contentType != null) {
        inMessage.put(org.apache.cxf.message.Message.CONTENT_TYPE, contentType);
        inMessage.put(org.apache.cxf.message.Message.ENCODING, getEncoding(contentType));
    }
    String responseCode = (String) messageHeaders.getProperty(org.apache.cxf.message.Message.RESPONSE_CODE);
    if (responseCode != null) {
        inMessage.put(org.apache.cxf.message.Message.RESPONSE_CODE, Integer.valueOf(responseCode));
    }
    Map<String, List<String>> protHeaders = new TreeMap<String, List<String>>();
    for (String name : messageHeaders.getPropertyKeys()) {
        String val = (String) messageHeaders.getProperty(name);
        protHeaders.put(name, Collections.singletonList(val));
    }
    String requestURI = messageHeaders.getSOAPJMSRequestURI();
    if (requestURI != null) {
        try {
            JMSEndpoint endpoint = new JMSEndpoint(requestURI);
            if (endpoint.getTargetService() != null) {
                protHeaders.put(JMSConstants.TARGET_SERVICE_IN_REQUESTURI, Collections.singletonList("true"));
            }
            inMessage.put(org.apache.cxf.message.Message.REQUEST_URI, requestURI);
        } catch (Exception e) {
            protHeaders.put(JMSConstants.MALFORMED_REQUESTURI, Collections.singletonList("true"));
        }
    }
    inMessage.put(org.apache.cxf.message.Message.PROTOCOL_HEADERS, protHeaders);
}
Also used : JMSEndpoint(org.apache.cxf.transport.jms.uri.JMSEndpoint) List(java.util.List) TreeMap(java.util.TreeMap) JMSException(javax.jms.JMSException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 3 with JMSEndpoint

use of org.apache.cxf.transport.jms.uri.JMSEndpoint in project cxf by apache.

the class JMSConfigFactoryTest method testConcurrentConsumers.

@Test
public void testConcurrentConsumers() {
    JMSEndpoint endpoint = new JMSEndpoint("jms:queue:Foo.Bar?concurrentConsumers=4");
    JMSConfiguration jmsConfig = JMSConfigFactory.createFromEndpoint(bus, endpoint);
    Assert.assertEquals(4, jmsConfig.getConcurrentConsumers());
}
Also used : JMSEndpoint(org.apache.cxf.transport.jms.uri.JMSEndpoint) Test(org.junit.Test)

Example 4 with JMSEndpoint

use of org.apache.cxf.transport.jms.uri.JMSEndpoint in project cxf by apache.

the class JMSConfigFactoryTest method tmByClass.

private void tmByClass(Bus bus, TransactionManager tmExpected) {
    JMSEndpoint endpoint = new JMSEndpoint("jms:queue:Foo.Bar");
    JMSConfiguration jmsConfig = JMSConfigFactory.createFromEndpoint(bus, endpoint);
    TransactionManager tm = jmsConfig.getTransactionManager();
    Assert.assertEquals(tmExpected, tm);
}
Also used : JMSEndpoint(org.apache.cxf.transport.jms.uri.JMSEndpoint) GeronimoTransactionManager(org.apache.geronimo.transaction.manager.GeronimoTransactionManager) TransactionManager(javax.transaction.TransactionManager)

Example 5 with JMSEndpoint

use of org.apache.cxf.transport.jms.uri.JMSEndpoint in project cxf by apache.

the class JMSConfigFactoryTest method tmByName.

private void tmByName(Bus bus, TransactionManager tmExpected) {
    JMSEndpoint endpoint = new JMSEndpoint("jms:queue:Foo.Bar?jndiTransactionManagerName=tm");
    Assert.assertEquals("tm", endpoint.getJndiTransactionManagerName());
    JMSConfiguration jmsConfig = JMSConfigFactory.createFromEndpoint(bus, endpoint);
    TransactionManager tm = jmsConfig.getTransactionManager();
    Assert.assertEquals(tmExpected, tm);
}
Also used : JMSEndpoint(org.apache.cxf.transport.jms.uri.JMSEndpoint) GeronimoTransactionManager(org.apache.geronimo.transaction.manager.GeronimoTransactionManager) TransactionManager(javax.transaction.TransactionManager)

Aggregations

JMSEndpoint (org.apache.cxf.transport.jms.uri.JMSEndpoint)6 TransactionManager (javax.transaction.TransactionManager)3 GeronimoTransactionManager (org.apache.geronimo.transaction.manager.GeronimoTransactionManager)2 Test (org.junit.Test)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 List (java.util.List)1 TreeMap (java.util.TreeMap)1 ConnectionFactory (javax.jms.ConnectionFactory)1 JMSException (javax.jms.JMSException)1 ConfiguredBeanLocator (org.apache.cxf.configuration.ConfiguredBeanLocator)1 JMSDestinationResolver (org.apache.cxf.transport.jms.util.JMSDestinationResolver)1 JndiHelper (org.apache.cxf.transport.jms.util.JndiHelper)1