mirror of https://github.com/apache/activemq.git
Reject sender / receiver creation when the address is a temp destination prefixed value but the destination doesn't map down to a temp destination created using a dynamic link which means the orignal connection ID where the destination was created cannot be determined.
This commit is contained in:
parent
ff1a1c4985
commit
b313209aa2
|
@ -179,6 +179,12 @@ public class AmqpSession implements AmqpResource {
|
||||||
});
|
});
|
||||||
} else if (targetNodeName != null && !targetNodeName.isEmpty()) {
|
} else if (targetNodeName != null && !targetNodeName.isEmpty()) {
|
||||||
destination = createDestination(remoteTarget);
|
destination = createDestination(remoteTarget);
|
||||||
|
if (destination.isTemporary()) {
|
||||||
|
String connectionId = ((ActiveMQTempDestination) destination).getConnectionId();
|
||||||
|
if (connectionId == null) {
|
||||||
|
throw new AmqpProtocolException(AmqpError.PRECONDITION_FAILED.toString(), "Not a broker created temp destination");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
receiver.setDestination(destination);
|
receiver.setDestination(destination);
|
||||||
|
@ -276,6 +282,12 @@ public class AmqpSession implements AmqpResource {
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
destination = createDestination(source);
|
destination = createDestination(source);
|
||||||
|
if (destination.isTemporary()) {
|
||||||
|
String connectionId = ((ActiveMQTempDestination) destination).getConnectionId();
|
||||||
|
if (connectionId == null) {
|
||||||
|
throw new AmqpProtocolException(AmqpError.INVALID_FIELD.toString(), "Not a broker created temp destination");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
source.setFilter(supportedFilters.isEmpty() ? null : supportedFilters);
|
source.setFilter(supportedFilters.isEmpty() ? null : supportedFilters);
|
||||||
|
@ -359,11 +371,11 @@ public class AmqpSession implements AmqpResource {
|
||||||
|
|
||||||
//----- Internal Implementation ------------------------------------------//
|
//----- Internal Implementation ------------------------------------------//
|
||||||
|
|
||||||
protected ConsumerId getNextConsumerId() {
|
private ConsumerId getNextConsumerId() {
|
||||||
return new ConsumerId(sessionId, nextConsumerId++);
|
return new ConsumerId(sessionId, nextConsumerId++);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ProducerId getNextProducerId() {
|
private ProducerId getNextProducerId() {
|
||||||
return new ProducerId(sessionId, nextProducerId++);
|
return new ProducerId(sessionId, nextProducerId++);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@ import static org.apache.activemq.transport.amqp.AmqpSupport.TEMP_QUEUE_CAPABILI
|
||||||
import static org.apache.activemq.transport.amqp.AmqpSupport.TEMP_TOPIC_CAPABILITY;
|
import static org.apache.activemq.transport.amqp.AmqpSupport.TEMP_TOPIC_CAPABILITY;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -45,6 +46,68 @@ import org.junit.Test;
|
||||||
*/
|
*/
|
||||||
public class AmqpTempDestinationTest extends AmqpClientTestSupport {
|
public class AmqpTempDestinationTest extends AmqpClientTestSupport {
|
||||||
|
|
||||||
|
@Test(timeout = 60000)
|
||||||
|
public void testCannotCreateSenderWithNamedTempQueue() throws Exception {
|
||||||
|
doTestCannotCreateSenderWithNamedTempDestination(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(timeout = 60000)
|
||||||
|
public void testCannotCreateSenderWithNamedTempTopic() throws Exception {
|
||||||
|
doTestCannotCreateSenderWithNamedTempDestination(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void doTestCannotCreateSenderWithNamedTempDestination(boolean topic) throws Exception {
|
||||||
|
|
||||||
|
AmqpClient client = createAmqpClient();
|
||||||
|
AmqpConnection connection = client.connect();
|
||||||
|
AmqpSession session = connection.createSession();
|
||||||
|
|
||||||
|
String address = null;
|
||||||
|
if (topic) {
|
||||||
|
address = "temp-topic://" + getTestName();
|
||||||
|
} else {
|
||||||
|
address = "temp-queue://" + getTestName();
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
session.createSender(address);
|
||||||
|
fail("Should not be able to create sender to a temp destination that doesn't exist.");
|
||||||
|
} catch (Exception ex) {
|
||||||
|
LOG.info("Error creating sender: {}", ex.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(timeout = 60000)
|
||||||
|
public void testCanntCreateReceverWithNamedTempQueue() throws Exception {
|
||||||
|
doTestCannotCreateReceiverWithNamedTempDestination(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(timeout = 60000)
|
||||||
|
public void testCannotCreateReceiverWithNamedTempTopic() throws Exception {
|
||||||
|
doTestCannotCreateReceiverWithNamedTempDestination(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void doTestCannotCreateReceiverWithNamedTempDestination(boolean topic) throws Exception {
|
||||||
|
|
||||||
|
AmqpClient client = createAmqpClient();
|
||||||
|
AmqpConnection connection = client.connect();
|
||||||
|
AmqpSession session = connection.createSession();
|
||||||
|
|
||||||
|
String address = null;
|
||||||
|
if (topic) {
|
||||||
|
address = "temp-topic://" + getTestName();
|
||||||
|
} else {
|
||||||
|
address = "temp-queue://" + getTestName();
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
session.createReceiver(address);
|
||||||
|
fail("Should not be able to create sender to a temp destination that doesn't exist.");
|
||||||
|
} catch (Exception ex) {
|
||||||
|
LOG.info("Error creating sender: {}", ex.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test(timeout = 60000)
|
@Test(timeout = 60000)
|
||||||
public void testCreateDynamicSenderToTopic() throws Exception {
|
public void testCreateDynamicSenderToTopic() throws Exception {
|
||||||
doTestCreateDynamicSender(true);
|
doTestCreateDynamicSender(true);
|
||||||
|
|
Loading…
Reference in New Issue