mirror of https://github.com/apache/activemq.git
AMQ-4153: Fixed issue with ActiveMQWASInitialContextFactory
git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1404896 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
5e03927da7
commit
b6347ee6d3
|
@ -28,13 +28,10 @@ import javax.naming.NamingException;
|
|||
* when ActiveMQ is used as WebSphere Generic JMS Provider. It is proved that it
|
||||
* works on WebSphere 5.1. The reason for using this class is that custom
|
||||
* property defined for Generic JMS Provider are passed to InitialContextFactory
|
||||
* only if it begins with java.naming or javax.naming prefix. Additionaly
|
||||
* only if it begins with java.naming or javax.naming prefix. Additionally
|
||||
* provider url for the JMS provider can not contain ',' character that is
|
||||
* necessary when the list of nodes is provided. So the role of this class is to
|
||||
* transform properties before passing it to
|
||||
* <CODE>ActiveMQInitialContextFactory</CODE>.
|
||||
*
|
||||
* @author Pawel Tucholski
|
||||
* transform properties before passing it to <tt>ActiveMQInitialContextFactory</tt>.
|
||||
*/
|
||||
public class ActiveMQWASInitialContextFactory extends ActiveMQInitialContextFactory {
|
||||
|
||||
|
@ -42,7 +39,6 @@ public class ActiveMQWASInitialContextFactory extends ActiveMQInitialContextFact
|
|||
* @see javax.naming.spi.InitialContextFactory#getInitialContext(java.util.Hashtable)
|
||||
*/
|
||||
public Context getInitialContext(Hashtable environment) throws NamingException {
|
||||
|
||||
return super.getInitialContext(transformEnvironment(environment));
|
||||
}
|
||||
|
||||
|
@ -58,6 +54,7 @@ public class ActiveMQWASInitialContextFactory extends ActiveMQInitialContextFact
|
|||
* @param environment properties for transformation
|
||||
* @return environment after transformation
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
protected Hashtable transformEnvironment(Hashtable environment) {
|
||||
|
||||
Hashtable environment1 = new Hashtable();
|
||||
|
@ -70,11 +67,11 @@ public class ActiveMQWASInitialContextFactory extends ActiveMQInitialContextFact
|
|||
String key = (String)entry.getKey();
|
||||
String value = (String)entry.getValue();
|
||||
|
||||
if (key.startsWith("java.naming.queue")) {
|
||||
if (key.startsWith("java.naming.queue.")) {
|
||||
String key1 = key.substring("java.naming.queue.".length());
|
||||
key1 = key1.replace('.', '/');
|
||||
environment1.put("queue." + key1, value);
|
||||
} else if (key.startsWith("java.naming.topic")) {
|
||||
} else if (key.startsWith("java.naming.topic.")) {
|
||||
String key1 = key.substring("java.naming.topic.".length());
|
||||
key1 = key1.replace('.', '/');
|
||||
environment1.put("topic." + key1, value);
|
||||
|
@ -85,9 +82,8 @@ public class ActiveMQWASInitialContextFactory extends ActiveMQInitialContextFact
|
|||
String key1 = key.substring("java.naming.".length());
|
||||
environment1.put(key1, value);
|
||||
} else if (key.startsWith(Context.PROVIDER_URL)) {
|
||||
// websphere administration console does not accept the , character
|
||||
// in provider url, so ; must be used
|
||||
// all ; to ,
|
||||
// Websphere administration console does not accept the , character
|
||||
// in provider url, so ; must be used all ; to ,
|
||||
value = value.replace(';', ',');
|
||||
environment1.put(Context.PROVIDER_URL, value);
|
||||
} else {
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.activemq.jndi;
|
||||
|
||||
import java.util.Hashtable;
|
||||
|
@ -23,20 +22,22 @@ import javax.naming.Context;
|
|||
|
||||
public class ActiveMQWASInitialContextFactoryTest extends JNDITestSupport {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testTransformEnvironment() {
|
||||
|
||||
Hashtable<Object, Object> originalEnvironment = new Hashtable<Object, Object>();
|
||||
originalEnvironment.put("java.naming.connectionFactoryNames", "ConnectionFactory");
|
||||
originalEnvironment.put("java.naming.topic.jms.systemMessageTopic", "jms/systemMessageTopic");
|
||||
originalEnvironment.put(Context.PROVIDER_URL, "tcp://localhost:61616;tcp://localhost:61617");
|
||||
originalEnvironment.put("non-string", Integer.valueOf(43));
|
||||
originalEnvironment.put("java.naming.queue", "jms/systemMessageQueue");
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
Hashtable<Object, Object> transformedEnvironment = new ActiveMQWASInitialContextFactory().transformEnvironment(originalEnvironment);
|
||||
assertEquals("ConnectionFactory", "ConnectionFactory", transformedEnvironment.get("connectionFactoryNames"));
|
||||
assertEquals("topic.jm", "jms/systemMessageTopic", transformedEnvironment.get("topic.jms/systemMessageTopic"));
|
||||
assertEquals("java.naming.provider.url", "tcp://localhost:61616,tcp://localhost:61617", transformedEnvironment.get("java.naming.provider.url"));
|
||||
assertNull("non-string", transformedEnvironment.get("non-string"));
|
||||
|
||||
assertEquals("queue", "jms/systemMessageQueue", transformedEnvironment.get("java.naming.queue"));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue