Commit a3fe94c3 authored by Andre Freyssinet's avatar Andre Freyssinet

Prevent issues with JNDI names including '/' (JORAM-356).

parent 0bc97db4
/*
* JORAM: Java(TM) Open Reliable Asynchronous Messaging
* Copyright (C) 2017 - 2019 ScalAgent Distributed Technologies
* Copyright (C) 2017 - 2020 ScalAgent Distributed Technologies
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
......@@ -24,8 +24,10 @@ package com.scalagent.joram.mom.dest.rest;
import java.io.ByteArrayOutputStream;
import java.io.ObjectOutputStream;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Constructor;
import java.net.URI;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
......@@ -94,7 +96,7 @@ public class RestAcquisitionAsync implements AcquisitionDaemon {
this.transmitter = transmitter;
initFromProperties();
if (destName == null) {
logger.log(BasicLevel.ERROR,
"Missing Destination JNDI name, should fixed property " + DestinationConstants.DESTINATION_NAME_PROP);
......@@ -144,6 +146,12 @@ public class RestAcquisitionAsync implements AcquisitionDaemon {
if (destName == null) {
logger.log(BasicLevel.ERROR,
"Missing Destination JNDI name, should fixed property " + DestinationConstants.DESTINATION_NAME_PROP);
} else {
try {
destName = URLEncoder.encode(destName, "UTF-8");
} catch (UnsupportedEncodingException exc) {
// Should never happened
}
}
if (properties.containsKey(DestinationConstants.MEDIA_TYPE_JSON_PROP)) {
......@@ -256,7 +264,7 @@ public class RestAcquisitionAsync implements AcquisitionDaemon {
"RestAcquisitionAsync.createConsumer(): cannot create consumer", exc);
throw exc;
}
if (response.getStatus() == 201) {
if (logger.isLoggable(BasicLevel.DEBUG))
logger.log(BasicLevel.DEBUG,
......
......@@ -45,6 +45,7 @@ import framework.TestCase;
/**
* Test: Test the behavior of BridgeAcquisitionQueue during stop / restart of Foreign server.
* This test also verifies the behavior with '/' in JNDI names (JORAM-356).
*/
public class BridgeRestTest1 extends TestCase implements MessageListener {
public static void main(String[] args) {
......@@ -81,6 +82,9 @@ public class BridgeRestTest1 extends TestCase implements MessageListener {
}
}
private final static String foreignQueueName = "foreignQueue";
private final static String acqQueueName = "acqQueue";
private void admin() throws Exception {
javax.jms.ConnectionFactory bridgeCF = TcpConnectionFactory.create("localhost", 16010);
......@@ -91,7 +95,7 @@ public class BridgeRestTest1 extends TestCase implements MessageListener {
User.create("anonymous", "anonymous", 1);
// create The foreign destination and connectionFactory on server 1
Queue foreignQueue = Queue.create(1, "foreignQueue");
Queue foreignQueue = Queue.create(1, foreignQueueName);
foreignQueue.setFreeReading();
foreignQueue.setFreeWriting();
System.out.println("foreign queue = " + foreignQueue);
......@@ -99,7 +103,8 @@ public class BridgeRestTest1 extends TestCase implements MessageListener {
javax.jms.ConnectionFactory foreignCF = TcpConnectionFactory.create("localhost", 16011);
// bind foreign destination and connectionFactory
jndiCtx.rebind("foreignQueue", foreignQueue);
Context tmpCtx = jndiCtx.createSubcontext("tmp");
tmpCtx.rebind(foreignQueueName, foreignQueue);
jndiCtx.rebind("foreignCF", foreignCF);
// Create a REST acquisition queue on server.
......@@ -107,11 +112,11 @@ public class BridgeRestTest1 extends TestCase implements MessageListener {
.setMediaTypeJson(true)
.setTimeout(5000)
.setIdleTimeout(10)
.create(0, "acqQueue", "foreignQueue");
.create(0, acqQueueName, "tmp/" + foreignQueueName);
acqQueue.setFreeReading();
System.out.println("joram acquisition queue = " + acqQueue);
jndiCtx.bind("acqQueue", acqQueue);
jndiCtx.bind(acqQueueName, acqQueue);
jndiCtx.rebind("bridgeCF", bridgeCF);
jndiCtx.close();
......@@ -127,9 +132,9 @@ public class BridgeRestTest1 extends TestCase implements MessageListener {
public void test() throws Exception {
Context jndiCtx = new InitialContext();
ConnectionFactory bridgeCF = (ConnectionFactory) jndiCtx.lookup("bridgeCF");
Destination acqQueue = (Destination) jndiCtx.lookup("acqQueue");
Destination acqQueue = (Destination) jndiCtx.lookup(acqQueueName);
ConnectionFactory foreignCF = (ConnectionFactory) jndiCtx.lookup("foreignCF");
Destination foreignQueue = (Destination) jndiCtx.lookup("foreignQueue");
Destination foreignQueue = (Destination) jndiCtx.lookup("tmp/" + foreignQueueName);
jndiCtx.close();
Connection bridgeCnx = bridgeCF.createConnection();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment