Skip to content
Permalink
Browse files
CXF-5543 Replacing JndiTemplate. Removing spring-context dependency
git-svn-id: https://svn.apache.org/repos/asf/cxf/trunk@1567565 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
cschneider committed Feb 12, 2014
1 parent dc9ae15 commit 65ad54cb421575b1eaf8cf25de0ae460ed79d07f
Show file tree
Hide file tree
Showing 14 changed files with 117 additions and 51 deletions.
@@ -106,10 +106,6 @@
<version>3.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
@@ -29,11 +29,10 @@
import org.apache.cxf.common.injection.NoJSR250Annotations;
import org.apache.cxf.transport.jms.util.DestinationResolver;
import org.apache.cxf.transport.jms.util.JMSDestinationResolver;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.jndi.JndiTemplate;
import org.apache.cxf.transport.jms.util.JndiHelper;

@NoJSR250Annotations
public class JMSConfiguration implements InitializingBean {
public class JMSConfiguration {
/**
* The use of -1 is to make easier to determine
* if the setCacheLevel has been called.
@@ -42,7 +41,7 @@ public class JMSConfiguration implements InitializingBean {

private boolean usingEndpointInfo = true;

private JndiTemplate jndiTemplate;
private JndiHelper jndiTemplate;
private ConnectionFactory connectionFactory;
private DestinationResolver destinationResolver = new JMSDestinationResolver();
private Executor taskExecutor;
@@ -384,11 +383,11 @@ public boolean isSetUseConduitIdSelector() {
return useConduitIdSelector != null;
}

public void setJndiTemplate(JndiTemplate jndiTemplate) {
public void setJndiTemplate(JndiHelper jndiTemplate) {
this.jndiTemplate = jndiTemplate;
}

public JndiTemplate getJndiTemplate() {
public JndiHelper getJndiTemplate() {
return jndiTemplate;
}

@@ -66,8 +66,8 @@ static ConnectionFactory getConnectionFactoryFromJndi(JMSConfiguration jmsConfig
String userName = jndiConfig.getConnectionUserName();
String password = jndiConfig.getConnectionPassword();
try {
ConnectionFactory cf = (ConnectionFactory)jmsConfig.getJndiTemplate().
lookup(connectionFactoryName);
ConnectionFactory cf = jmsConfig.getJndiTemplate().
lookup(connectionFactoryName, ConnectionFactory.class);
if (userName != null) {
UserCredentialsConnectionFactoryAdapter uccf = new UserCredentialsConnectionFactoryAdapter();
uccf.setUsername(userName);
@@ -40,6 +40,7 @@
import org.apache.cxf.transport.jms.uri.JMSEndpointParser;
import org.apache.cxf.transport.jms.uri.JMSURIConstants;
import org.apache.cxf.transport.jms.util.JMSDestinationResolver;
import org.apache.cxf.transport.jms.util.JndiHelper;
import org.apache.cxf.transport.jms.wsdl.DeliveryModeType;
import org.apache.cxf.transport.jms.wsdl.JndiConnectionFactoryNameType;
import org.apache.cxf.transport.jms.wsdl.JndiContextParameterType;
@@ -50,7 +51,6 @@
import org.apache.cxf.transport.jms.wsdl.TimeToLiveType;
import org.apache.cxf.transport.jms.wsdl.TopicReplyToNameType;
import org.apache.cxf.ws.addressing.EndpointReferenceType;
import org.springframework.jndi.JndiTemplate;

public class JMSOldConfigHolder {
private static final Logger LOG = LogUtils.getL7dLogger(JMSOldConfigHolder.class);
@@ -208,8 +208,7 @@ protected JMSConfiguration configureEndpoint(boolean isConduit, JMSEndpoint endp
}

if (jmsConfig.isUsingEndpointInfo()) {
JndiTemplate jt = new JndiTemplate();
jt.setEnvironment(JMSOldConfigHolder.getInitialContextEnv(endpoint));
JndiHelper jt = new JndiHelper(JMSOldConfigHolder.getInitialContextEnv(endpoint));
boolean pubSubDomain = endpoint.getJmsVariant().contains(JMSURIConstants.TOPIC);
JNDIConfiguration jndiConfig = new JNDIConfiguration();
jndiConfig.setJndiConnectionFactoryName(endpoint.getJndiConnectionFactoryName());
@@ -20,19 +20,16 @@

import java.util.Properties;

import org.springframework.jndi.JndiTemplate;

import org.apache.cxf.transport.jms.util.JndiHelper;

public class JNDIConfiguration {
private Properties environment;
private String jndiConnectionFactoryName;
private String connectionUserName;
private String connectionPassword;

public JndiTemplate createJndiTemple() {
JndiTemplate jt = new JndiTemplate();
jt.setEnvironment(environment);
return jt;
public JndiHelper createJndiTemple() {
return new JndiHelper(environment);
}

public String getJndiConnectionFactoryName() {
@@ -23,10 +23,8 @@
import javax.jms.Session;
import javax.naming.NamingException;

import org.springframework.jndi.JndiTemplate;

public class JMSDestinationResolver implements DestinationResolver {
JndiTemplate jndiTemplate;
JndiHelper jndiTemplate;

public Destination resolveDestinationName(Session session, String destinationName, boolean pubSubDomain)
throws JMSException {
@@ -44,7 +42,7 @@ public Destination resolveDestinationName(Session session, String destinationNam
}
}

public void setJndiTemplate(JndiTemplate jt) {
public void setJndiTemplate(JndiHelper jt) {
this.jndiTemplate = jt;
}

@@ -0,0 +1,71 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.cxf.transport.jms.util;

import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Properties;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NameNotFoundException;
import javax.naming.NamingException;

public class JndiHelper {

private Properties environment;

/**
* Create a new JndiTemplate instance, using the given environment.
*/
public JndiHelper(Properties environment) {
this.environment = environment;
}

@SuppressWarnings("rawtypes")
protected Context createInitialContext() throws NamingException {
//CHECKSTYLE:OFF
Hashtable<Object, Object> icEnv = new Hashtable<Object, Object>(environment.size());
//CHECKSTYLE:ON
for (Enumeration en = environment.propertyNames(); en.hasMoreElements();) {
String key = (String)en.nextElement();
Object value = environment.getProperty(key);
if (value == null) {
value = environment.get(key);
}
icEnv.put(key, value);
}
return new InitialContext(icEnv);
}

@SuppressWarnings("unchecked")
public <T> T lookup(final String name, Class<T> requiredType) throws NamingException {
Context ctx = createInitialContext();
try {
Object located = ctx.lookup(name);
if (located == null) {
throw new NameNotFoundException("JNDI object with [" + name + "] not found");
}
return (T)located;
} finally {
ResourceCloser.close(ctx);
}
}

}
@@ -27,6 +27,8 @@
import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.naming.Context;
import javax.naming.NamingException;

public class ResourceCloser implements Closeable {
private AbstractSequentialList<Object> resources;
@@ -66,11 +68,15 @@ public static void close(Object resource) {
((Session)resource).close();
} else if (resource instanceof Connection) {
((Connection)resource).close();
} else if (resource instanceof Context) {
((Context)resource).close();
} else {
throw new IllegalArgumentException("Can not handle resource " + resource.getClass());
}
} catch (JMSException e) {
// Ignore
} catch (NamingException e) {
// Ignore
}
}

@@ -195,12 +195,6 @@
<scope>test</scope>
<version>${cxf.spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jms</artifactId>
<scope>test</scope>
<version>${cxf.spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
@@ -45,7 +45,7 @@
import org.apache.cxf.transport.jms.uri.JMSEndpointParser;
import org.apache.cxf.transport.jms.uri.JMSURIConstants;
import org.apache.cxf.transport.jms.util.JMSDestinationResolver;
import org.springframework.jndi.JndiTemplate;
import org.apache.cxf.transport.jms.util.JndiHelper;

/**
*
@@ -127,8 +127,7 @@ public static JMSConfiguration getInitJMSConfiguration(String address) throws Ex
}

if (jmsConfig.isUsingEndpointInfo()) {
JndiTemplate jt = new JndiTemplate();
jt.setEnvironment(JMSOldConfigHolder.getInitialContextEnv(endpoint));
JndiHelper jt = new JndiHelper(JMSOldConfigHolder.getInitialContextEnv(endpoint));
boolean pubSubDomain = false;
pubSubDomain = endpoint.getJmsVariant().equals(JMSURIConstants.TOPIC);
JNDIConfiguration jndiConfig = new JNDIConfiguration();
@@ -76,6 +76,7 @@
import org.apache.cxf.transport.jms.JNDIConfiguration;
import org.apache.cxf.transport.jms.spec.JMSSpecConstants;
import org.apache.cxf.transport.jms.uri.JMSEndpoint;
import org.apache.cxf.transport.jms.util.JndiHelper;
import org.apache.cxf.transport.jms.util.TestReceiver;
import org.apache.hello_world_doc_lit.Greeter;
import org.apache.hello_world_doc_lit.PingMeFault;
@@ -85,7 +86,6 @@
import org.junit.Ignore;
import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.jndi.JndiTemplate;

public class JMSClientServerTest extends AbstractBusClientServerTestBase {
private static final String BROKER_URI = "vm://JMSClientServerTest"
@@ -888,8 +888,7 @@ public void testReplyToConfig() throws Exception {
endpoint.setJndiConnectionFactoryName("ConnectionFactory");

final JMSConfiguration jmsConfig = new JMSConfiguration();
JndiTemplate jt = new JndiTemplate();
jt.setEnvironment(JMSOldConfigHolder.getInitialContextEnv(endpoint));
JndiHelper jt = new JndiHelper(JMSOldConfigHolder.getInitialContextEnv(endpoint));

JNDIConfiguration jndiConfig = new JNDIConfiguration();
jndiConfig.setJndiConnectionFactoryName(endpoint.getJndiConnectionFactoryName());
@@ -27,17 +27,24 @@
</jms:address>
<jms:jmsConfig-ref>jmsConf1</jms:jmsConfig-ref>
</jms:conduit>
<bean id="jmsConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory" p:brokerURL="${EmbeddedBrokerURL}"/>
<bean id="singleConnectionFactory" class="org.springframework.jms.connection.SingleConnectionFactory" destroy-method="destroy">
<property name="targetConnectionFactory" ref="jmsConnectionFactory"/>
</bean>
<bean id="jmsConf1" class="org.apache.cxf.transport.jms.JMSConfiguration" p:connectionFactory-ref="singleConnectionFactory" p:concurrentConsumers="1" p:maxConcurrentConsumers="1"/>
<bean id="jmsConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory"
p:brokerURL="${EmbeddedBrokerURL}"/>
<bean id="jmsConf1" class="org.apache.cxf.transport.jms.JMSConfiguration"
p:connectionFactory-ref="jmsConnectionFactory"
p:concurrentConsumers="1"
p:maxConcurrentConsumers="1"/>
<jms:destination name="{http://cxf.apache.org/systest/jaxws}HelloContinuationPort.jms-destination">
<jms:address jndiConnectionFactoryName="ConnectionFactory" jndiDestinationName="dynamicQueues/test.jmstransport.text">
<jms:JMSNamingProperty name="java.naming.factory.initial" value="org.apache.activemq.jndi.ActiveMQInitialContextFactory"/>
<jms:JMSNamingProperty name="java.naming.provider.url" value="${EmbeddedBrokerURL}"/>
</jms:address>
<jms:jmsConfig-ref>jmsConf2</jms:jmsConfig-ref>
</jms:destination>
<bean id="jmsConf2" class="org.apache.cxf.transport.jms.JMSConfiguration" p:connectionFactory-ref="jmsConnectionFactory" p:timeToLive="10000" p:concurrentConsumers="1" p:maxConcurrentConsumers="1" p:maxSuspendedContinuations="1" p:cacheLevel="2"/>
<bean id="jmsConf2" class="org.apache.cxf.transport.jms.JMSConfiguration"
p:connectionFactory-ref="jmsConnectionFactory"
p:timeToLive="10000"
p:concurrentConsumers="1"
p:maxConcurrentConsumers="1"
p:maxSuspendedContinuations="1"
p:cacheLevel="2"/>
</beans>
@@ -35,11 +35,7 @@
</bean>
</cxf:features>
</cxf:bus>
<bean id="jmsConnectionFactory" class="org.springframework.jms.connection.SingleConnectionFactory">
<property name="targetConnectionFactory">
<bean class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="vm://JMSClientServerSoap12Test"/>
</bean>
</property>
<bean id="jmsConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="vm://JMSClientServerSoap12Test"/>
</bean>
</beans>
@@ -27,15 +27,17 @@
<bean id="jmsConnectionFactory" class="org.apache.activemq.pool.PooledConnectionFactory">
<constructor-arg value="${EmbeddedBrokerURL}"/>
</bean>
<!--
<bean id="singleConnectionFactory" class="org.springframework.jms.connection.SingleConnectionFactory" destroy-method="destroy">
<property name="targetConnectionFactory" ref="jmsConnectionFactory"/>
</bean>
<bean id="jmsTransactionManager" class="org.springframework.jms.connection.JmsTransactionManager">
<property name="connectionFactory" ref="singleConnectionFactory"/>
</bean>
-->
<bean id="implementor" class="org.apache.cxf.systest.jms.tx.GreeterImplWithTransaction"/>
<bean id="transactionalImplementor" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager" ref="jmsTransactionManager"/>
<!-- <property name="transactionManager" ref="jmsTransactionManager"/> -->
<property name="target" ref="implementor"/>
<property name="transactionAttributes">
<props>
@@ -45,5 +47,8 @@
</props>
</property>
</bean>
<bean id="jmsConf" class="org.apache.cxf.transport.jms.JMSConfiguration" p:connectionFactory-ref="singleConnectionFactory" p:sessionTransacted="true" p:transactionManager-ref="jmsTransactionManager" p:usingEndpointInfo="true"/>
<bean id="jmsConf" class="org.apache.cxf.transport.jms.JMSConfiguration"
p:connectionFactory-ref="jmsConnectionFactory"
p:sessionTransacted="true"
p:usingEndpointInfo="true"/>
</beans>

0 comments on commit 65ad54c

Please sign in to comment.