use of org.apache.qpid.server.protocol.v1_0.type.extensions.soleconn.SoleConnectionConnectionProperties.SOLE_CONNECTION_ENFORCEMENT_POLICY in project qpid-broker-j by apache.
the class CloseExistingPolicy method basicNegotiation.
@Test
public void basicNegotiation() throws Exception {
try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
Open responseOpen = transport.newInteraction().negotiateProtocol().consumeResponse().openContainerId("testContainerId").openDesiredCapabilities(SOLE_CONNECTION_FOR_CONTAINER).openProperties(Collections.singletonMap(SOLE_CONNECTION_ENFORCEMENT_POLICY, CLOSE_EXISTING)).open().consumeResponse().getLatestResponse(Open.class);
assertThat(Arrays.asList(responseOpen.getOfferedCapabilities()), hasItem(SOLE_CONNECTION_FOR_CONTAINER));
if (responseOpen.getProperties().containsKey(SOLE_CONNECTION_DETECTION_POLICY)) {
assertThat(responseOpen.getProperties().get(SOLE_CONNECTION_DETECTION_POLICY), isIn(new UnsignedInteger[] { SoleConnectionDetectionPolicy.STRONG.getValue(), SoleConnectionDetectionPolicy.WEAK.getValue() }));
}
}
}
use of org.apache.qpid.server.protocol.v1_0.type.extensions.soleconn.SoleConnectionConnectionProperties.SOLE_CONNECTION_ENFORCEMENT_POLICY in project qpid-broker-j by apache.
the class MixedPolicy method firstRefuseThenClose.
@Test
public void firstRefuseThenClose() throws Exception {
try (FrameTransport transport1 = new FrameTransport(_brokerAddress).connect()) {
final Interaction interaction1 = transport1.newInteraction();
interaction1.negotiateProtocol().consumeResponse().openContainerId("testContainerId").openDesiredCapabilities(SOLE_CONNECTION_FOR_CONTAINER).openProperties(Collections.singletonMap(SOLE_CONNECTION_ENFORCEMENT_POLICY, REFUSE_CONNECTION)).open().consumeResponse(Open.class);
try (FrameTransport transport2 = new FrameTransport(_brokerAddress).connect()) {
final Interaction interaction2 = transport2.newInteraction();
interaction2.negotiateProtocol().consumeResponse().openContainerId("testContainerId").openDesiredCapabilities(SOLE_CONNECTION_FOR_CONTAINER).openProperties(Collections.singletonMap(SOLE_CONNECTION_ENFORCEMENT_POLICY, CLOSE_EXISTING)).open().consumeResponse(Open.class).consumeResponse(Close.class);
}
}
}
use of org.apache.qpid.server.protocol.v1_0.type.extensions.soleconn.SoleConnectionConnectionProperties.SOLE_CONNECTION_ENFORCEMENT_POLICY in project qpid-broker-j by apache.
the class RefuseConnectionPolicy method strongDetection.
@Test
public void strongDetection() throws Exception {
try (FrameTransport transport1 = new FrameTransport(_brokerAddress).connect()) {
final Interaction interaction1 = transport1.newInteraction();
final Open responseOpen = interaction1.negotiateProtocol().consumeResponse().openContainerId("testContainerId").openDesiredCapabilities(SOLE_CONNECTION_FOR_CONTAINER).openProperties(Collections.singletonMap(SOLE_CONNECTION_ENFORCEMENT_POLICY, REFUSE_CONNECTION)).open().consumeResponse().getLatestResponse(Open.class);
assertThat(Arrays.asList(responseOpen.getOfferedCapabilities()), hasItem(SOLE_CONNECTION_FOR_CONTAINER));
if (responseOpen.getProperties().containsKey(SOLE_CONNECTION_DETECTION_POLICY)) {
assumeThat(responseOpen.getProperties().get(SOLE_CONNECTION_DETECTION_POLICY), is(equalTo(SoleConnectionDetectionPolicy.STRONG.getValue())));
}
try (FrameTransport transport2 = new FrameTransport(_brokerAddress).connect()) {
final Interaction interaction2 = transport2.newInteraction();
// Omit setting the desired capability to test strong detection
final Open responseOpen2 = interaction2.negotiateProtocol().consumeResponse().openContainerId("testContainerId").open().consumeResponse().getLatestResponse(Open.class);
assertThat(Arrays.asList(responseOpen2.getOfferedCapabilities()), hasItem(SOLE_CONNECTION_FOR_CONTAINER));
assertThat(responseOpen2.getProperties(), hasKey(Symbol.valueOf("amqp:connection-establishment-failed")));
assertThat(responseOpen2.getProperties().get(Symbol.valueOf("amqp:connection-establishment-failed")), is(true));
final Close close2 = interaction2.consumeResponse().getLatestResponse(Close.class);
assertThat(close2.getError(), is(notNullValue()));
assertThat(close2.getError().getCondition(), is(equalTo(AmqpError.INVALID_FIELD)));
assertThat(close2.getError().getInfo(), is(equalTo(Collections.singletonMap(Symbol.valueOf("invalid-field"), Symbol.valueOf("container-id")))));
}
}
}
use of org.apache.qpid.server.protocol.v1_0.type.extensions.soleconn.SoleConnectionConnectionProperties.SOLE_CONNECTION_ENFORCEMENT_POLICY in project qpid-broker-j by apache.
the class RefuseConnectionPolicy method newConnectionRefused.
@Test
public void newConnectionRefused() throws Exception {
try (FrameTransport transport1 = new FrameTransport(_brokerAddress).connect()) {
final Interaction interaction1 = transport1.newInteraction();
interaction1.negotiateProtocol().consumeResponse().openContainerId("testContainerId").openDesiredCapabilities(SOLE_CONNECTION_FOR_CONTAINER).openProperties(Collections.singletonMap(SOLE_CONNECTION_ENFORCEMENT_POLICY, REFUSE_CONNECTION)).open().consumeResponse(Open.class);
try (FrameTransport transport2 = new FrameTransport(_brokerAddress).connect()) {
final Interaction interaction2 = transport2.newInteraction();
final Open responseOpen2 = interaction2.negotiateProtocol().consumeResponse().openContainerId("testContainerId").openDesiredCapabilities(SOLE_CONNECTION_FOR_CONTAINER).openProperties(Collections.singletonMap(SOLE_CONNECTION_ENFORCEMENT_POLICY, REFUSE_CONNECTION)).open().consumeResponse().getLatestResponse(Open.class);
assertThat(Arrays.asList(responseOpen2.getOfferedCapabilities()), hasItem(SOLE_CONNECTION_FOR_CONTAINER));
assertThat(responseOpen2.getProperties(), hasKey(Symbol.valueOf("amqp:connection-establishment-failed")));
assertThat(responseOpen2.getProperties().get(Symbol.valueOf("amqp:connection-establishment-failed")), is(true));
final Close close2 = interaction2.consumeResponse().getLatestResponse(Close.class);
assertThat(close2.getError(), is(notNullValue()));
assertThat(close2.getError().getCondition(), is(equalTo(AmqpError.INVALID_FIELD)));
assertThat(close2.getError().getInfo(), is(equalTo(Collections.singletonMap(Symbol.valueOf("invalid-field"), Symbol.valueOf("container-id")))));
}
}
}
use of org.apache.qpid.server.protocol.v1_0.type.extensions.soleconn.SoleConnectionConnectionProperties.SOLE_CONNECTION_ENFORCEMENT_POLICY in project qpid-broker-j by apache.
the class AMQPConnection_1_0Impl method receiveOpen.
@Override
public void receiveOpen(final int channel, final Open open) {
assertState(ConnectionState.AWAIT_OPEN);
int channelMax = getPort().getSessionCountLimit() - 1;
_channelMax = open.getChannelMax() == null ? channelMax : open.getChannelMax().intValue() < channelMax ? open.getChannelMax().intValue() : channelMax;
if (_receivingSessions == null) {
_receivingSessions = new Session_1_0[_channelMax + 1];
_sendingSessions = new Session_1_0[_channelMax + 1];
}
_maxFrameSize = open.getMaxFrameSize() == null || open.getMaxFrameSize().longValue() > getBroker().getNetworkBufferSize() ? getBroker().getNetworkBufferSize() : open.getMaxFrameSize().intValue();
_remoteContainerId = open.getContainerId();
if (open.getHostname() != null && !"".equals(open.getHostname().trim())) {
_localHostname = open.getHostname();
}
if (_localHostname == null || "".equals(_localHostname.trim()) && getNetwork().getSelectedHost() != null) {
_localHostname = getNetwork().getSelectedHost();
}
if (open.getIdleTimeOut() != null) {
_outgoingIdleTimeout = open.getIdleTimeOut().longValue();
}
final Map<Symbol, Object> remoteProperties = open.getProperties() == null ? Collections.emptyMap() : Collections.unmodifiableMap(new LinkedHashMap<>(open.getProperties()));
_remoteDesiredCapabilities = open.getDesiredCapabilities() == null ? Collections.emptySet() : Sets.newHashSet(open.getDesiredCapabilities());
if (remoteProperties.containsKey(Symbol.valueOf("product"))) {
setClientProduct(remoteProperties.get(Symbol.valueOf("product")).toString());
}
if (remoteProperties.containsKey(Symbol.valueOf("version"))) {
setClientVersion(remoteProperties.get(Symbol.valueOf("version")).toString());
}
setClientId(_remoteContainerId);
if (_remoteDesiredCapabilities.contains(SoleConnectionConnectionProperties.SOLE_CONNECTION_FOR_CONTAINER)) {
if (remoteProperties != null && remoteProperties.containsKey(SOLE_CONNECTION_ENFORCEMENT_POLICY)) {
try {
_soleConnectionEnforcementPolicy = SoleConnectionEnforcementPolicy.valueOf(remoteProperties.get(SOLE_CONNECTION_ENFORCEMENT_POLICY));
} catch (IllegalArgumentException e) {
closeConnection(AmqpError.INVALID_FIELD, e.getMessage());
return;
}
} else {
_soleConnectionEnforcementPolicy = SoleConnectionEnforcementPolicy.REFUSE_CONNECTION;
}
}
if (_outgoingIdleTimeout != 0L && _outgoingIdleTimeout < MINIMUM_SUPPORTED_IDLE_TIMEOUT) {
closeConnection(ConnectionError.CONNECTION_FORCED, "Requested idle timeout of " + _outgoingIdleTimeout + " is too low. The minimum supported timeout is" + MINIMUM_SUPPORTED_IDLE_TIMEOUT);
} else {
initialiseHeartbeating(_outgoingIdleTimeout / 2L, _incomingIdleTimeout);
final NamedAddressSpace addressSpace = getPort().getAddressSpace(_localHostname);
if (addressSpace == null) {
closeConnection(AmqpError.NOT_FOUND, "Unknown hostname in connection open: '" + _localHostname + "'");
} else {
receiveOpenInternal(addressSpace);
}
}
}
Aggregations