AMQ-5801: add error condition hint via the info map to signal the container-id was the invalid field

This commit is contained in:
Robert Gemmell 2015-05-27 18:08:40 +01:00
parent 5e7b70f11f
commit 138e52b08c
3 changed files with 35 additions and 3 deletions

View File

@ -45,6 +45,10 @@ public class AmqpSupport {
public static final Symbol TEMP_QUEUE_CAPABILITY = Symbol.valueOf("temporary-queue");
public static final Symbol TEMP_TOPIC_CAPABILITY = Symbol.valueOf("temporary-topic");
// Symbols used to announce connection information to remote peer.
public static final Symbol INVALID_FIELD = Symbol.valueOf("invalid-field");
public static final Symbol CONTAINER_ID = Symbol.valueOf("container-id");
// Symbols used to announce connection information to remote peer.
public static final Symbol ANONYMOUS_RELAY = Symbol.valueOf("ANONYMOUS-RELAY");
public static final Symbol QUEUE_PREFIX = Symbol.valueOf("queue-prefix");

View File

@ -18,6 +18,8 @@ package org.apache.activemq.transport.amqp.protocol;
import static org.apache.activemq.transport.amqp.AmqpSupport.ANONYMOUS_RELAY;
import static org.apache.activemq.transport.amqp.AmqpSupport.CONNECTION_OPEN_FAILED;
import static org.apache.activemq.transport.amqp.AmqpSupport.CONTAINER_ID;
import static org.apache.activemq.transport.amqp.AmqpSupport.INVALID_FIELD;
import static org.apache.activemq.transport.amqp.AmqpSupport.QUEUE_PREFIX;
import static org.apache.activemq.transport.amqp.AmqpSupport.TEMP_QUEUE_CAPABILITY;
import static org.apache.activemq.transport.amqp.AmqpSupport.TEMP_TOPIC_CAPABILITY;
@ -434,7 +436,13 @@ public class AmqpConnection implements AmqpProtocolConverter {
if (exception instanceof SecurityException) {
protonConnection.setCondition(new ErrorCondition(AmqpError.UNAUTHORIZED_ACCESS, exception.getMessage()));
} else if (exception instanceof InvalidClientIDException) {
protonConnection.setCondition(new ErrorCondition(AmqpError.INVALID_FIELD, exception.getMessage()));
ErrorCondition condition = new ErrorCondition(AmqpError.INVALID_FIELD, exception.getMessage());
Map<Symbol, Object> infoMap = new HashMap<Symbol, Object> ();
infoMap.put(INVALID_FIELD, CONTAINER_ID);
condition.setInfo(infoMap);
protonConnection.setCondition(condition);
} else {
protonConnection.setCondition(new ErrorCondition(AmqpError.ILLEGAL_STATE, exception.getMessage()));
}

View File

@ -23,6 +23,7 @@ import static org.junit.Assert.assertNotNull;
import java.util.Map;
import org.apache.activemq.transport.amqp.AmqpSupport;
import org.apache.activemq.transport.amqp.client.AmqpClient;
import org.apache.activemq.transport.amqp.client.AmqpClientTestSupport;
import org.apache.activemq.transport.amqp.client.AmqpConnection;
@ -145,11 +146,30 @@ public class AmqpConnectionsTest extends AmqpClientTestSupport {
public void inspectClosedResource(Connection connection) {
ErrorCondition remoteError = connection.getRemoteCondition();
if (remoteError == null) {
markAsInvalid("Broker dd not add error condition for duplicate client ID");
markAsInvalid("Broker did not add error condition for duplicate client ID");
}
if (!remoteError.getCondition().equals(AmqpError.INVALID_FIELD)) {
markAsInvalid("Broker dd not set condition to " + AmqpError.INVALID_FIELD);
markAsInvalid("Broker did not set condition to " + AmqpError.INVALID_FIELD);
}
if (!remoteError.getCondition().equals(AmqpError.INVALID_FIELD)) {
markAsInvalid("Broker did not set condition to " + AmqpError.INVALID_FIELD);
}
// Validate the info map contains a hint that the container/client id was the problem
Map<?, ?> infoMap = remoteError.getInfo();
if(infoMap == null) {
markAsInvalid("Broker did not set an info map on condition");
}
if(!infoMap.containsKey(AmqpSupport.INVALID_FIELD)) {
markAsInvalid("Info map does not contain expected key");
}
Object value = infoMap.get(AmqpSupport.INVALID_FIELD);
if(!AmqpSupport.CONTAINER_ID.equals(value)) {
markAsInvalid("Info map does not contain expected value: " + value);
}
}
});