diff options
author | Alex Rudyy <orudyy@apache.org> | 2013-01-14 18:27:46 +0000 |
---|---|---|
committer | Alex Rudyy <orudyy@apache.org> | 2013-01-14 18:27:46 +0000 |
commit | 96135b02b4a0bf8a0a4f634f91de2607b92d3b90 (patch) | |
tree | f8c58b13a3b0d7fedbbeb9b2f9d9ff4c7c205ec5 | |
parent | c26462b01199f95a7a27b82a54d956b1c793cc58 (diff) | |
download | qpid-python-96135b02b4a0bf8a0a4f634f91de2607b92d3b90.tar.gz |
QPID-4390: Add port defaults
git-svn-id: https://svn.apache.org/repos/asf/qpid/branches/java-broker-config-qpid-4390@1433025 13f79535-47bb-0310-9956-ffa450edef68
15 files changed, 342 insertions, 406 deletions
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/BrokerProperties.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/BrokerProperties.java index 4cee3b7026..40af0bd23a 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/BrokerProperties.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/BrokerProperties.java @@ -32,6 +32,8 @@ public class BrokerProperties public static final String PROPERTY_DISABLED_FEATURES = "qpid.broker_disabled_features"; public static final int DEFAULT_FRAME_SIZE = Integer.getInteger(PROPERTY_FRAME_SIZE, 65535); + public static final String PROPERTY_BROKER_DEFAULT_AMQP_PROTOCOL_EXCLUDES = "qpid.broker_default_amqp_protocol_excludes"; + public static final String PROPERTY_BROKER_DEFAULT_AMQP_PROTOCOL_INCLUDES = "qpid.broker_default_amqp_protocol_includes"; private BrokerProperties() { diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/BrokerRecoverer.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/BrokerRecoverer.java index 29dd3a603f..d6392f6d57 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/BrokerRecoverer.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/BrokerRecoverer.java @@ -105,7 +105,7 @@ public class BrokerRecoverer implements ConfiguredObjectRecoverer<Broker> Collection<Port> ports = broker.getPorts(); for (Port port : ports) { - String authenticationProviderName = port.getAuthenticationManagerName(); + String authenticationProviderName = (String)port.getAttribute(Port.AUTHENTICATION_MANAGER); AuthenticationProvider provider = null; if (authenticationProviderName != null) { diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/Port.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/Port.java index 30e9ebf082..2f94c3cab7 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/Port.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/Port.java @@ -105,18 +105,6 @@ public interface Port extends ConfiguredObject Collection<VirtualHostAlias> getVirtualHostBindings(); Collection<Connection> getConnections(); - boolean isTcpNoDelay(); - - int getReceiveBufferSize(); - - int getSendBufferSize(); - - boolean isNeedClientAuth(); - - boolean isWantClientAuth(); - - String getAuthenticationManagerName(); - AuthenticationProvider getAuthenticationProvider(); void setAuthenticationProvider(AuthenticationProvider authenticationProvider); diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/AbstractAdapter.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/AbstractAdapter.java index 1e14704987..f277de8ca1 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/AbstractAdapter.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/AbstractAdapter.java @@ -43,15 +43,24 @@ abstract class AbstractAdapter implements ConfiguredObject private final UUID _id; private final Map<String, Object> _defaultAttributes = new HashMap<String, Object>(); - protected AbstractAdapter(UUID id, Map<String, Object> defaults) + protected AbstractAdapter(UUID id, Map<String, Object> defaults, Map<String, Object> attributes) { _id = id; + if (attributes != null) + { + _attributes.putAll(attributes); + } if (defaults != null) { _defaultAttributes.putAll(defaults); } } + protected AbstractAdapter(UUID id, Map<String, Object> defaults) + { + this(id, defaults, null); + } + public final UUID getId() { return _id; diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/PortAdapter.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/PortAdapter.java index 9b6f6ba9fa..bd60f154da 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/PortAdapter.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/PortAdapter.java @@ -21,15 +21,12 @@ package org.apache.qpid.server.model.adapter; -import java.net.InetSocketAddress; import java.security.AccessControlException; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.List; import java.util.Map; -import java.util.Set; -import java.util.TreeSet; import java.util.UUID; import org.apache.qpid.server.model.AuthenticationProvider; @@ -44,22 +41,12 @@ import org.apache.qpid.server.model.Statistics; import org.apache.qpid.server.model.Transport; import org.apache.qpid.server.model.VirtualHost; import org.apache.qpid.server.model.VirtualHostAlias; -import org.apache.qpid.server.util.MapValueConverter; public class PortAdapter extends AbstractAdapter implements Port { private final String _name; private final Broker _broker; - private final Set<Protocol> _protocols; - private final Set<Transport> _transports; - private final InetSocketAddress _bindingSocketAddress; - private final boolean _tcpNoDelay; - private final int _receiveBufferSize; - private final int _sendBufferSize; - private final boolean _needClientAuth; - private final boolean _wantClientAuth; - private final String _authenticationManager; private AuthenticationProvider _authenticationProvider; /* @@ -74,40 +61,42 @@ public class PortAdapter extends AbstractAdapter implements Port addParent(Broker.class, broker); - String bindingAddress = MapValueConverter.getStringAttribute(BINDING_ADDRESS, attributes, null); - int portNumber = MapValueConverter.getIntegerAttribute(PORT, attributes, null); - - final Set<Protocol> protocolSet = MapValueConverter.getSetAttribute(PROTOCOLS, attributes); - final Set<Transport> transportSet = MapValueConverter.getSetAttribute(TRANSPORTS, attributes); - - _bindingSocketAddress = determineBindingAddress(bindingAddress, portNumber); - _name = MapValueConverter.getStringAttribute(NAME, attributes, _bindingSocketAddress.getHostName() + ":" + portNumber); - _protocols = Collections.unmodifiableSet(new TreeSet<Protocol>(protocolSet)); - _transports = Collections.unmodifiableSet(new TreeSet<Transport>(transportSet)); - _tcpNoDelay = MapValueConverter.getBooleanAttribute(TCP_NO_DELAY, attributes); - _receiveBufferSize = MapValueConverter.getIntegerAttribute(RECEIVE_BUFFER_SIZE, attributes); - _sendBufferSize = MapValueConverter.getIntegerAttribute(SEND_BUFFER_SIZE, attributes); - _needClientAuth = MapValueConverter.getBooleanAttribute(NEED_CLIENT_AUTH, attributes); - _wantClientAuth = MapValueConverter.getBooleanAttribute(WANT_CLIENT_AUTH, attributes); - _authenticationManager = MapValueConverter.getStringAttribute(AUTHENTICATION_MANAGER, attributes, null); + Collection<String> names = getAttributeNames(); + for (String name : names) + { + if (attributes.containsKey(name)) + { + setAttribute(name, defaults.get(name), attributes.get(name)); + } + } + + String name = (String)getAttribute(NAME); + if (name == null) + { + Integer port = getPort(); + String bindingAddress = getBindingAddress(); + name = bindingAddress == null? port + "" : bindingAddress + ":" + port; + } + _name = name; } @Override public String getBindingAddress() { - return _bindingSocketAddress.getAddress().getHostAddress(); + return (String)getAttribute(BINDING_ADDRESS); } @Override public int getPort() { - return _bindingSocketAddress.getPort(); + return (Integer)getAttribute(PORT); } + @SuppressWarnings("unchecked") @Override public Collection<Transport> getTransports() { - return _transports; + return (Collection<Transport>)getAttribute(TRANSPORTS); } @Override @@ -124,10 +113,11 @@ public class PortAdapter extends AbstractAdapter implements Port throw new IllegalStateException(); } + @SuppressWarnings("unchecked") @Override public Collection<Protocol> getProtocols() { - return _protocols; + return (Collection<Protocol>)getAttribute(PROTOCOLS); } @Override @@ -284,46 +274,6 @@ public class PortAdapter extends AbstractAdapter implements Port { } - else if(BINDING_ADDRESS.equals(name)) - { - return getBindingAddress(); - } - else if(PORT.equals(name)) - { - return getPort(); - } - else if(PROTOCOLS.equals(name)) - { - return getProtocols(); - } - else if(TRANSPORTS.equals(name)) - { - return getTransports(); - } - else if(TCP_NO_DELAY.equals(name)) - { - return isTcpNoDelay(); - } - else if(SEND_BUFFER_SIZE.equals(name)) - { - return getSendBufferSize(); - } - else if(RECEIVE_BUFFER_SIZE.equals(name)) - { - return getReceiveBufferSize(); - } - else if(NEED_CLIENT_AUTH.equals(name)) - { - return isNeedClientAuth(); - } - else if(WANT_CLIENT_AUTH.equals(name)) - { - return isWantClientAuth(); - } - else if(AUTHENTICATION_MANAGER.equals(name)) - { - return getAuthenticationManagerName(); - } return super.getAttribute(name); } @@ -370,47 +320,6 @@ public class PortAdapter extends AbstractAdapter implements Port // no-op: expected to be overridden by subclass } - private InetSocketAddress determineBindingAddress(String bindingAddress, int portNumber) - { - return bindingAddress == null ? new InetSocketAddress(portNumber) : new InetSocketAddress(bindingAddress, portNumber); - } - - @Override - public boolean isTcpNoDelay() - { - return _tcpNoDelay; - } - - @Override - public int getReceiveBufferSize() - { - return _receiveBufferSize; - } - - @Override - public int getSendBufferSize() - { - return _sendBufferSize; - } - - @Override - public boolean isNeedClientAuth() - { - return _needClientAuth; - } - - @Override - public boolean isWantClientAuth() - { - return _wantClientAuth; - } - - @Override - public String getAuthenticationManagerName() - { - return _authenticationManager; - } - @Override public AuthenticationProvider getAuthenticationProvider() { diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/PortAttributeDestringifier.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/PortAttributeDestringifier.java deleted file mode 100644 index bb5ac32bbb..0000000000 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/PortAttributeDestringifier.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -package org.apache.qpid.server.model.adapter; - -import java.util.HashMap; -import java.util.Map; -import java.util.Set; - -import org.apache.qpid.server.model.Port; -import org.apache.qpid.server.model.Protocol; -import org.apache.qpid.server.model.Transport; -import org.apache.qpid.server.util.MapValueConverter; - -public class PortAttributeDestringifier -{ - private static final int DEFAULT_BUFFER_SIZE = 262144; - private static final boolean DEFAULT_TCP_NO_DELAY = true; - private static final boolean DEFAULT_WANT_CLIENT_AUTH = false; - private static final boolean DEFAULT_NEED_CLIENT_AUTH = false; - - // TODO : implement a generic functionality to convert string attribute values into corresponding java types - public Map<String, Object> destringify(Map<String, Object> attributes) - { - Map<String, Object> destringifiedAttributes = new HashMap<String, Object>(attributes); - - final Set<Protocol> protocolSet = MapValueConverter.getEnumSetAttribute(Port.PROTOCOLS, attributes, Protocol.class); - destringifiedAttributes.put(Port.PROTOCOLS, protocolSet); - - final Set<Transport> transportSet = MapValueConverter.getEnumSetAttribute(Port.TRANSPORTS, attributes, Transport.class); - destringifiedAttributes.put(Port.TRANSPORTS, transportSet); - - Integer port = MapValueConverter.getIntegerAttribute(Port.PORT, attributes); - destringifiedAttributes.put(Port.PORT, port); - - boolean tcpNoDelay = MapValueConverter.getBooleanAttribute(Port.TCP_NO_DELAY, attributes, DEFAULT_TCP_NO_DELAY); - int receiveBufferSize = MapValueConverter.getIntegerAttribute(Port.RECEIVE_BUFFER_SIZE, attributes, - DEFAULT_BUFFER_SIZE); - int sendBufferSize = MapValueConverter.getIntegerAttribute(Port.SEND_BUFFER_SIZE, attributes, DEFAULT_BUFFER_SIZE); - boolean needClientAuth = MapValueConverter.getBooleanAttribute(Port.NEED_CLIENT_AUTH, attributes, - DEFAULT_NEED_CLIENT_AUTH); - boolean wantClientAuth = MapValueConverter.getBooleanAttribute(Port.WANT_CLIENT_AUTH, attributes, - DEFAULT_WANT_CLIENT_AUTH); - - destringifiedAttributes.put(Port.TCP_NO_DELAY, tcpNoDelay); - destringifiedAttributes.put(Port.RECEIVE_BUFFER_SIZE, receiveBufferSize); - destringifiedAttributes.put(Port.SEND_BUFFER_SIZE, sendBufferSize); - destringifiedAttributes.put(Port.NEED_CLIENT_AUTH, needClientAuth); - destringifiedAttributes.put(Port.WANT_CLIENT_AUTH, wantClientAuth); - return destringifiedAttributes; - } -} diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/PortFactory.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/PortFactory.java index fcd30586d7..8c2ac664fa 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/PortFactory.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/PortFactory.java @@ -20,64 +20,186 @@ */ package org.apache.qpid.server.model.adapter; +import java.util.Collection; +import java.util.Collections; +import java.util.EnumSet; +import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; import java.util.UUID; +import org.apache.qpid.server.configuration.BrokerProperties; import org.apache.qpid.server.configuration.IllegalConfigurationException; import org.apache.qpid.server.model.Broker; import org.apache.qpid.server.model.Port; import org.apache.qpid.server.model.Protocol; import org.apache.qpid.server.model.Protocol.ProtocolType; +import org.apache.qpid.server.model.Transport; import org.apache.qpid.server.transport.AmqpPortAdapter; import org.apache.qpid.server.util.MapValueConverter; public class PortFactory { - private final PortAttributeDestringifier _portAttributeDestringifier = new PortAttributeDestringifier(); + public static final int DEFAULT_AMQP_SEND_BUFFER_SIZE = 262144; + + public static final int DEFAULT_AMQP_RECEIVE_BUFFER_SIZE = 262144; + + public static final boolean DEFAULT_AMQP_NEED_CLIENT_AUTH = false; + + public static final boolean DEFAULT_AMQP_WANT_CLIENT_AUTH = false; + + public static final boolean DEFAULT_AMQP_TCP_NO_DELAY = true; + + public static final int DEFAULT_AMQP_PORT = 5672; + + public static final String DEFAULT_AMQP_BINDING = "*"; + + public static final Transport DEFAULT_TRANSPORT = Transport.TCP; + + private final Collection<Protocol> _defaultProtocols; public PortFactory() { + Set<Protocol> defaultProtocols = EnumSet.of(Protocol.AMQP_0_8, Protocol.AMQP_0_9, Protocol.AMQP_0_9_1, + Protocol.AMQP_0_10, Protocol.AMQP_1_0); + String excludedProtocols = System.getProperty(BrokerProperties.PROPERTY_BROKER_DEFAULT_AMQP_PROTOCOL_EXCLUDES); + if (excludedProtocols != null) + { + String[] excludes = excludedProtocols.split(","); + for (String exclude : excludes) + { + Protocol protocol = Protocol.valueOf(exclude); + defaultProtocols.remove(protocol); + } + } + String includedProtocols = System.getProperty(BrokerProperties.PROPERTY_BROKER_DEFAULT_AMQP_PROTOCOL_INCLUDES); + if (includedProtocols != null) + { + String[] includes = includedProtocols.split(","); + for (String include : includes) + { + Protocol protocol = Protocol.valueOf(include); + defaultProtocols.add(protocol); + } + } + _defaultProtocols = Collections.unmodifiableCollection(defaultProtocols); } - /** - * @param attributes the port attributes, where the values are strings, either singly or in collections. - */ - public Port createPort(UUID id, Broker broker, Map<String, Object> attributesAsStrings) + public Port createPort(UUID id, Broker broker, Map<String, Object> objectAttributes) { - Map<String, Object> attributes = _portAttributeDestringifier.destringify(attributesAsStrings); + Map<String, Object> attributes = retrieveAttributes(objectAttributes); + final Port port; + Map<String, Object> defaults = new HashMap<String, Object>(); + defaults.put(Port.TRANSPORTS, Collections.singleton(DEFAULT_TRANSPORT)); if (isAmqpProtocol(attributes)) { - //TODO: create defaults - Map<String, Object> defaults = null; + defaults.put(Port.PROTOCOLS, _defaultProtocols); + defaults.put(Port.PORT, DEFAULT_AMQP_PORT); + defaults.put(Port.TCP_NO_DELAY, DEFAULT_AMQP_TCP_NO_DELAY); + defaults.put(Port.WANT_CLIENT_AUTH, DEFAULT_AMQP_WANT_CLIENT_AUTH); + defaults.put(Port.NEED_CLIENT_AUTH, DEFAULT_AMQP_NEED_CLIENT_AUTH); + defaults.put(Port.RECEIVE_BUFFER_SIZE, DEFAULT_AMQP_RECEIVE_BUFFER_SIZE); + defaults.put(Port.SEND_BUFFER_SIZE, DEFAULT_AMQP_SEND_BUFFER_SIZE); + defaults.put(Port.BINDING_ADDRESS, DEFAULT_AMQP_BINDING); port = new AmqpPortAdapter(id, broker, attributes, defaults); } else { - //TODO: create defaults - Map<String, Object> defaults = null; port = new PortAdapter(id, broker, attributes, defaults); } return port; } + private Map<String, Object> retrieveAttributes(Map<String, Object> objectAttributes) + { + Map<String, Object> attributes = new HashMap<String, Object>(objectAttributes); + + if (objectAttributes.containsKey(Port.PROTOCOLS)) + { + final Set<Protocol> protocolSet = MapValueConverter.getEnumSetAttribute(Port.PROTOCOLS, objectAttributes, Protocol.class); + attributes.put(Port.PROTOCOLS, protocolSet); + } + + if (objectAttributes.containsKey(Port.TRANSPORTS)) + { + final Set<Transport> transportSet = MapValueConverter.getEnumSetAttribute(Port.TRANSPORTS, objectAttributes, + Transport.class); + attributes.put(Port.TRANSPORTS, transportSet); + } + + if (objectAttributes.containsKey(Port.PORT)) + { + Integer port = MapValueConverter.getIntegerAttribute(Port.PORT, objectAttributes); + attributes.put(Port.PORT, port); + } + + if (objectAttributes.containsKey(Port.TCP_NO_DELAY)) + { + boolean tcpNoDelay = MapValueConverter.getBooleanAttribute(Port.TCP_NO_DELAY, objectAttributes); + attributes.put(Port.TCP_NO_DELAY, tcpNoDelay); + } + + if (objectAttributes.containsKey(Port.RECEIVE_BUFFER_SIZE)) + { + int receiveBufferSize = MapValueConverter.getIntegerAttribute(Port.RECEIVE_BUFFER_SIZE, objectAttributes); + attributes.put(Port.RECEIVE_BUFFER_SIZE, receiveBufferSize); + } + + if (objectAttributes.containsKey(Port.SEND_BUFFER_SIZE)) + { + int sendBufferSize = MapValueConverter.getIntegerAttribute(Port.SEND_BUFFER_SIZE, objectAttributes); + attributes.put(Port.SEND_BUFFER_SIZE, sendBufferSize); + } + + if (objectAttributes.containsKey(Port.NEED_CLIENT_AUTH)) + { + boolean needClientAuth = MapValueConverter.getBooleanAttribute(Port.NEED_CLIENT_AUTH, objectAttributes); + attributes.put(Port.NEED_CLIENT_AUTH, needClientAuth); + } + + if (objectAttributes.containsKey(Port.WANT_CLIENT_AUTH)) + { + boolean wantClientAuth = MapValueConverter.getBooleanAttribute(Port.WANT_CLIENT_AUTH, objectAttributes); + attributes.put(Port.WANT_CLIENT_AUTH, wantClientAuth); + } + + if (objectAttributes.containsKey(Port.BINDING_ADDRESS)) + { + String binding = MapValueConverter.getStringAttribute(Port.BINDING_ADDRESS, objectAttributes); + attributes.put(Port.BINDING_ADDRESS, binding); + } + return attributes; + } + private boolean isAmqpProtocol(Map<String, Object> portAttributes) { - Set<Object> protocolStrings = MapValueConverter.getSetAttribute(Port.PROTOCOLS, portAttributes); + @SuppressWarnings("unchecked") + Set<Protocol> protocols = (Set<Protocol>) portAttributes.get(Port.PROTOCOLS); + if (protocols == null || protocols.isEmpty()) + { + return true; + } + Set<ProtocolType> protocolTypes = new HashSet<ProtocolType>(); - for (Object protocolObject : protocolStrings) + for (Protocol protocolObject : protocols) { - Protocol protocol = Protocol.valueOfObject(protocolObject); - protocolTypes.add(protocol.getProtocolType()); + protocolTypes.add(protocolObject.getProtocolType()); } if (protocolTypes.size() > 1) { - throw new IllegalConfigurationException("Found different protocol types '" + protocolTypes + "' on port configuration: " + portAttributes); + throw new IllegalConfigurationException("Found different protocol types '" + protocolTypes + + "' on port configuration: " + portAttributes); } return protocolTypes.contains(ProtocolType.AMQP); } + + public Collection<Protocol> getDefaultProtocols() + { + return _defaultProtocols; + } + } diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/transport/AmqpPortAdapter.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/transport/AmqpPortAdapter.java index 9abfd3ddcd..9d4b770df2 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/transport/AmqpPortAdapter.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/transport/AmqpPortAdapter.java @@ -19,6 +19,8 @@ */ package org.apache.qpid.server.transport; +import static org.apache.qpid.transport.ConnectionSettings.WILDCARD_ADDRESS; + import java.io.IOException; import java.net.InetSocketAddress; import java.security.GeneralSecurityException; @@ -36,6 +38,7 @@ import org.apache.qpid.server.logging.actors.CurrentActor; import org.apache.qpid.server.logging.messages.BrokerMessages; import org.apache.qpid.server.model.Broker; import org.apache.qpid.server.model.KeyStore; +import org.apache.qpid.server.model.Port; import org.apache.qpid.server.model.Protocol; import org.apache.qpid.server.model.Transport; import org.apache.qpid.server.model.TrustStore; @@ -70,12 +73,27 @@ public class AmqpPortAdapter extends PortAdapter } AmqpProtocolVersion defaultSupportedProtocolReply = getDefaultAmqpSupportedReply(); - InetSocketAddress bindingSocketAddress = new InetSocketAddress(getBindingAddress(), getPort()); + + String bindingAddress = (String) getAttribute(Port.BINDING_ADDRESS); + if (WILDCARD_ADDRESS.equals(bindingAddress)) + { + bindingAddress = null; + } + Integer port = (Integer) getAttribute(Port.PORT); + InetSocketAddress bindingSocketAddress = null; + if ( bindingAddress == null ) + { + bindingSocketAddress = new InetSocketAddress(port); + } + else + { + bindingSocketAddress = new InetSocketAddress(bindingAddress, port); + } final NetworkTransportConfiguration settings = new ServerNetworkTransportConfiguration( - bindingSocketAddress, isTcpNoDelay(), - getSendBufferSize(), getReceiveBufferSize(), - isNeedClientAuth(), isWantClientAuth()); + bindingSocketAddress, (Boolean)getAttribute(TCP_NO_DELAY), + (Integer)getAttribute(SEND_BUFFER_SIZE), (Integer)getAttribute(RECEIVE_BUFFER_SIZE), + (Boolean)getAttribute(NEED_CLIENT_AUTH), (Boolean)getAttribute(WANT_CLIENT_AUTH)); _transport = org.apache.qpid.transport.network.Transport.getIncomingTransportInstance(); final MultiVersionProtocolEngineFactory protocolEngineFactory = new MultiVersionProtocolEngineFactory( diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/BrokerRecovererTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/BrokerRecovererTest.java index 633070fa65..eacc904b25 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/BrokerRecovererTest.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/BrokerRecovererTest.java @@ -242,7 +242,7 @@ public class BrokerRecovererTest extends TestCase Port port1 = mock(Port.class); when(port1.getName()).thenReturn("port1"); when(port1.getPort()).thenReturn(5671); - when(port1.getAuthenticationManagerName()).thenReturn("authenticationProvider1"); + when(port1.getAttribute(Port.AUTHENTICATION_MANAGER)).thenReturn("authenticationProvider1"); ConfigurationEntry portEntry2 = mock(ConfigurationEntry.class); Port port2 = mock(Port.class); when(port2.getName()).thenReturn("port2"); diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/model/adapter/PortAttributeDestringifierTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/model/adapter/PortAttributeDestringifierTest.java deleted file mode 100644 index a8a198303d..0000000000 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/model/adapter/PortAttributeDestringifierTest.java +++ /dev/null @@ -1,164 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -package org.apache.qpid.server.model.adapter; - -import static org.apache.qpid.server.model.Port.NEED_CLIENT_AUTH; -import static org.apache.qpid.server.model.Port.PORT; -import static org.apache.qpid.server.model.Port.PROTOCOLS; -import static org.apache.qpid.server.model.Port.RECEIVE_BUFFER_SIZE; -import static org.apache.qpid.server.model.Port.SEND_BUFFER_SIZE; -import static org.apache.qpid.server.model.Port.TCP_NO_DELAY; -import static org.apache.qpid.server.model.Port.TRANSPORTS; -import static org.apache.qpid.server.model.Port.WANT_CLIENT_AUTH; - -import java.util.Arrays; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - -import junit.framework.TestCase; - -import org.apache.qpid.server.model.Protocol; -import org.apache.qpid.server.model.Transport; -import org.apache.qpid.server.model.adapter.PortAttributeDestringifier; - -public class PortAttributeDestringifierTest extends TestCase -{ - public void testDestringify() - { - // values are non defaults to test the destringifier - AttributeTestData[] attributes = new AttributeTestData[] { - new AttributeTestData(PORT, "1234", 1234), - new AttributeTestData(NEED_CLIENT_AUTH, "true", true), - new AttributeTestData(WANT_CLIENT_AUTH, "true", true), - new AttributeTestData(SEND_BUFFER_SIZE, "2345", 2345), - new AttributeTestData(RECEIVE_BUFFER_SIZE, "3456", 3456), - new AttributeTestData(TCP_NO_DELAY, "false", false), - new AttributeTestData(TRANSPORTS, buildStringSetFromArray(Transport.TCP.name(), Transport.SSL.name()), - buildEnumSetFromArray(Transport.TCP, Transport.SSL)), - new AttributeTestData(PROTOCOLS, buildStringSetFromArray(Protocol.AMQP_0_10.name(), Protocol.HTTP.name()), - buildEnumSetFromArray(Protocol.AMQP_0_10, Protocol.HTTP)), }; - - Map<String, Object> attributesMap = new HashMap<String, Object>(); - for (AttributeTestData attributeTestData : attributes) - { - attributesMap.put(attributeTestData.name, attributeTestData.value); - } - - PortAttributeDestringifier portAttributeDestringifier = new PortAttributeDestringifier(); - Map<String, Object> destringifiedAttributesMap = portAttributeDestringifier.destringify(attributesMap); - - for (AttributeTestData attributeTestData : attributes) - { - Object value = destringifiedAttributesMap.get(attributeTestData.name); - assertEquals("Unexpected attribute " + attributeTestData.name + " value ", attributeTestData.destringifiedValue, - value); - } - } - - public void testDestringifyWithoutMandatoryAttributesThrowsException() - { - AttributeTestData[] attributesWithoutPort = new AttributeTestData[] { - new AttributeTestData(NEED_CLIENT_AUTH, "true", true), - new AttributeTestData(WANT_CLIENT_AUTH, "true", true), - new AttributeTestData(SEND_BUFFER_SIZE, "2345", 2345), - new AttributeTestData(RECEIVE_BUFFER_SIZE, "3456", 3456), - new AttributeTestData(TCP_NO_DELAY, "false", false), - new AttributeTestData(TRANSPORTS, buildStringSetFromArray(Transport.TCP.name(), Transport.SSL.name()), - buildEnumSetFromArray(Transport.TCP, Transport.SSL)), - new AttributeTestData(PROTOCOLS, buildStringSetFromArray(Protocol.AMQP_0_10.name(), Protocol.HTTP.name()), - buildEnumSetFromArray(Protocol.AMQP_0_10, Protocol.HTTP)), }; - - Map<String, Object> attributesMap = new HashMap<String, Object>(); - for (AttributeTestData attributeTestData : attributesWithoutPort) - { - attributesMap.put(attributeTestData.name, attributeTestData.value); - } - - PortAttributeDestringifier portAttributeDestringifier = new PortAttributeDestringifier(); - try - { - portAttributeDestringifier.destringify(attributesMap); - fail("For non existing port attribute an exception should be thrown"); - } - catch (IllegalArgumentException e) - { - // pass - } - } - - public void testDestringifyWithUnsupportedProtocolThrowsException() - { - AttributeTestData[] attributesWithoutPort = new AttributeTestData[] { - new AttributeTestData(NEED_CLIENT_AUTH, "true", true), - new AttributeTestData(WANT_CLIENT_AUTH, "true", true), - new AttributeTestData(SEND_BUFFER_SIZE, "2345", 2345), - new AttributeTestData(RECEIVE_BUFFER_SIZE, "3456", 3456), - new AttributeTestData(TCP_NO_DELAY, "false", false), - new AttributeTestData(TRANSPORTS, buildStringSetFromArray(Transport.TCP.name(), Transport.SSL.name()), - buildEnumSetFromArray(Transport.TCP, Transport.SSL)), - new AttributeTestData(PROTOCOLS, buildStringSetFromArray("UNSUPPORTED_PROTOCOL", Protocol.HTTP.name()), - buildEnumSetFromArray(null, Protocol.HTTP)), }; - - Map<String, Object> attributesMap = new HashMap<String, Object>(); - for (AttributeTestData attributeTestData : attributesWithoutPort) - { - attributesMap.put(attributeTestData.name, attributeTestData.value); - } - - PortAttributeDestringifier portAttributeDestringifier = new PortAttributeDestringifier(); - try - { - portAttributeDestringifier.destringify(attributesMap); - fail("For non supported protocol an exception should be thrown"); - } - catch (IllegalArgumentException e) - { - // pass - } - } - - private Set<String> buildStringSetFromArray(String... values) - { - return new HashSet<String>(Arrays.asList(values)); - } - - private Set<?> buildEnumSetFromArray(Enum<?>... values) - { - return new HashSet<Enum<?>>(Arrays.asList(values)); - } - - private class AttributeTestData - { - String name; - Object value; - Object destringifiedValue; - - public AttributeTestData(String name, Object value, Object destringifiedValue) - { - super(); - this.name = name; - this.value = value; - this.destringifiedValue = destringifiedValue; - } - } -} diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/model/adapter/PortFactoryTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/model/adapter/PortFactoryTest.java index 2998272e9a..cf70e78bb5 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/model/adapter/PortFactoryTest.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/model/adapter/PortFactoryTest.java @@ -23,28 +23,30 @@ package org.apache.qpid.server.model.adapter; import static org.mockito.Mockito.mock; import java.util.Arrays; +import java.util.Collection; import java.util.Collections; +import java.util.EnumSet; import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; import java.util.UUID; -import junit.framework.TestCase; - +import org.apache.qpid.server.configuration.BrokerProperties; import org.apache.qpid.server.configuration.IllegalConfigurationException; import org.apache.qpid.server.model.Broker; import org.apache.qpid.server.model.Port; import org.apache.qpid.server.model.Protocol; import org.apache.qpid.server.model.Transport; import org.apache.qpid.server.transport.AmqpPortAdapter; +import org.apache.qpid.test.utils.QpidTestCase; -public class PortFactoryTest extends TestCase +public class PortFactoryTest extends QpidTestCase { private UUID _portId = UUID.randomUUID(); private int _portNumber = 123; - private Set<String> _tcpStringSet = Collections.singleton(Transport.TCP.name()); - private Set<Transport> _tcpTransportSet = Collections.singleton(Transport.TCP); + private Set<String> _tcpStringSet = Collections.singleton(Transport.SSL.name()); + private Set<Transport> _tcpTransportSet = Collections.singleton(Transport.SSL); private Map<String, Object> _attributes = new HashMap<String, Object>(); @@ -62,6 +64,58 @@ public class PortFactoryTest extends TestCase _attributes.put(Port.SEND_BUFFER_SIZE, "2"); _attributes.put(Port.NEED_CLIENT_AUTH, "true"); _attributes.put(Port.WANT_CLIENT_AUTH, "true"); + _attributes.put(Port.BINDING_ADDRESS, "127.0.0.1"); + } + + public void testDefaultProtocols() + { + Collection<Protocol> protocols = _portFactory.getDefaultProtocols(); + EnumSet<Protocol> expected = EnumSet.of(Protocol.AMQP_0_8, Protocol.AMQP_0_9, Protocol.AMQP_0_9_1, Protocol.AMQP_0_10, + Protocol.AMQP_1_0); + assertEquals("Unexpected protocols", new HashSet<Protocol>(expected), new HashSet<Protocol>(protocols)); + } + + public void testDefaultProtocolsWhenProtocolExcludeSystemPropertyIsSet() + { + setTestSystemProperty(BrokerProperties.PROPERTY_BROKER_DEFAULT_AMQP_PROTOCOL_EXCLUDES, Protocol.AMQP_1_0.name() + "," + + Protocol.AMQP_0_10.name()); + _portFactory = new PortFactory(); + Collection<Protocol> protocols = _portFactory.getDefaultProtocols(); + EnumSet<Protocol> expected = EnumSet.of(Protocol.AMQP_0_8, Protocol.AMQP_0_9, Protocol.AMQP_0_9_1); + assertEquals("Unexpected protocols", new HashSet<Protocol>(expected), new HashSet<Protocol>(protocols)); + } + + public void testDefaultProtocolsWhenProtocolIncludeSystemPropertyIsSet() + { + setTestSystemProperty(BrokerProperties.PROPERTY_BROKER_DEFAULT_AMQP_PROTOCOL_EXCLUDES, Protocol.AMQP_1_0.name() + "," + + Protocol.AMQP_0_10.name() + "," + Protocol.AMQP_0_9_1.name()); + setTestSystemProperty(BrokerProperties.PROPERTY_BROKER_DEFAULT_AMQP_PROTOCOL_INCLUDES, Protocol.AMQP_0_10.name() + "," + + Protocol.AMQP_0_9_1.name()); + _portFactory = new PortFactory(); + Collection<Protocol> protocols = _portFactory.getDefaultProtocols(); + EnumSet<Protocol> expected = EnumSet.of(Protocol.AMQP_0_8, Protocol.AMQP_0_9, Protocol.AMQP_0_9_1, Protocol.AMQP_0_10); + assertEquals("Unexpected protocols", new HashSet<Protocol>(expected), new HashSet<Protocol>(protocols)); + } + + public void testCreatePortWithEmptyAttributes() + { + Port port = _portFactory.createPort(_portId, _broker, Collections.<String, Object> emptyMap()); + + assertNotNull(port); + assertTrue(port instanceof AmqpPortAdapter); + assertEquals("Unexpected port", PortFactory.DEFAULT_AMQP_PORT, port.getPort()); + assertEquals("Unexpected transports", Collections.singleton(PortFactory.DEFAULT_TRANSPORT), port.getTransports()); + assertEquals("Unexpected protocols", _portFactory.getDefaultProtocols(), port.getProtocols()); + assertEquals("Unexpected send buffer size", PortFactory.DEFAULT_AMQP_SEND_BUFFER_SIZE, + port.getAttribute(Port.SEND_BUFFER_SIZE)); + assertEquals("Unexpected receive buffer size", PortFactory.DEFAULT_AMQP_RECEIVE_BUFFER_SIZE, + port.getAttribute(Port.RECEIVE_BUFFER_SIZE)); + assertEquals("Unexpected need client auth", PortFactory.DEFAULT_AMQP_NEED_CLIENT_AUTH, + port.getAttribute(Port.NEED_CLIENT_AUTH)); + assertEquals("Unexpected want client auth", PortFactory.DEFAULT_AMQP_WANT_CLIENT_AUTH, + port.getAttribute(Port.WANT_CLIENT_AUTH)); + assertEquals("Unexpected tcp no delay", PortFactory.DEFAULT_AMQP_TCP_NO_DELAY, port.getAttribute(Port.TCP_NO_DELAY)); + assertEquals("Unexpected binding", PortFactory.DEFAULT_AMQP_BINDING, port.getAttribute(Port.BINDING_ADDRESS)); } public void testCreateAmqpPort() @@ -78,13 +132,22 @@ public class PortFactoryTest extends TestCase assertEquals(_portNumber, port.getPort()); assertEquals(_tcpTransportSet, port.getTransports()); assertEquals(amqp010ProtocolSet, port.getProtocols()); + assertEquals("Unexpected send buffer size", 2, port.getAttribute(Port.SEND_BUFFER_SIZE)); + assertEquals("Unexpected receive buffer size", 1, port.getAttribute(Port.RECEIVE_BUFFER_SIZE)); + assertEquals("Unexpected need client auth", true, port.getAttribute(Port.NEED_CLIENT_AUTH)); + assertEquals("Unexpected want client auth", true, port.getAttribute(Port.WANT_CLIENT_AUTH)); + assertEquals("Unexpected tcp no delay", true, port.getAttribute(Port.TCP_NO_DELAY)); + assertEquals("Unexpected binding", "127.0.0.1", port.getAttribute(Port.BINDING_ADDRESS)); } public void testCreateNonAmqpPort() { Set<Protocol> nonAmqpProtocolSet = Collections.singleton(Protocol.JMX_RMI); Set<String> nonAmqpStringSet = Collections.singleton(Protocol.JMX_RMI.name()); + _attributes = new HashMap<String, Object>(); _attributes.put(Port.PROTOCOLS, nonAmqpStringSet); + _attributes.put(Port.PORT, _portNumber); + _attributes.put(Port.TRANSPORTS, _tcpStringSet); Port port = _portFactory.createPort(_portId, _broker, _attributes); @@ -94,6 +157,36 @@ public class PortFactoryTest extends TestCase assertEquals(_portNumber, port.getPort()); assertEquals(_tcpTransportSet, port.getTransports()); assertEquals(nonAmqpProtocolSet, port.getProtocols()); + assertNull("Unexpected send buffer size", port.getAttribute(Port.SEND_BUFFER_SIZE)); + assertNull("Unexpected receive buffer size", port.getAttribute(Port.RECEIVE_BUFFER_SIZE)); + assertNull("Unexpected need client auth", port.getAttribute(Port.NEED_CLIENT_AUTH)); + assertNull("Unexpected want client auth", port.getAttribute(Port.WANT_CLIENT_AUTH)); + assertNull("Unexpected tcp no delay", port.getAttribute(Port.TCP_NO_DELAY)); + assertNull("Unexpected binding", port.getAttribute(Port.BINDING_ADDRESS)); + } + + public void testCreateNonAmqpPortWithPartiallySetAttributes() + { + Set<Protocol> nonAmqpProtocolSet = Collections.singleton(Protocol.JMX_RMI); + Set<String> nonAmqpStringSet = Collections.singleton(Protocol.JMX_RMI.name()); + _attributes = new HashMap<String, Object>(); + _attributes.put(Port.PROTOCOLS, nonAmqpStringSet); + _attributes.put(Port.PORT, _portNumber); + + Port port = _portFactory.createPort(_portId, _broker, _attributes); + + assertNotNull(port); + assertFalse("Port should be a PortAdapter, not its AMQP-specific subclass", port instanceof AmqpPortAdapter); + assertEquals(_portId, port.getId()); + assertEquals(_portNumber, port.getPort()); + assertEquals(Collections.singleton(PortFactory.DEFAULT_TRANSPORT), port.getTransports()); + assertEquals(nonAmqpProtocolSet, port.getProtocols()); + assertNull("Unexpected send buffer size", port.getAttribute(Port.SEND_BUFFER_SIZE)); + assertNull("Unexpected receive buffer size", port.getAttribute(Port.RECEIVE_BUFFER_SIZE)); + assertNull("Unexpected need client auth", port.getAttribute(Port.NEED_CLIENT_AUTH)); + assertNull("Unexpected want client auth", port.getAttribute(Port.WANT_CLIENT_AUTH)); + assertNull("Unexpected tcp no delay", port.getAttribute(Port.TCP_NO_DELAY)); + assertNull("Unexpected binding", port.getAttribute(Port.BINDING_ADDRESS)); } public void testCreateMixedAmqpAndNonAmqpThrowsException() diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/Asserts.java b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/Asserts.java index f51e730d22..f8b9117606 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/Asserts.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/Asserts.java @@ -37,6 +37,7 @@ import org.apache.qpid.server.model.Connection; import org.apache.qpid.server.model.Exchange; import org.apache.qpid.server.model.LifetimePolicy; import org.apache.qpid.server.model.Port; +import org.apache.qpid.server.model.Protocol; import org.apache.qpid.server.model.Queue; import org.apache.qpid.server.model.State; import org.apache.qpid.server.model.VirtualHost; @@ -181,7 +182,6 @@ public class Asserts public static void assertPortAttributes(Map<String, Object> port) { - assertAttributesPresent(port, Port.AVAILABLE_ATTRIBUTES, Port.CREATED, Port.UPDATED, Port.AUTHENTICATION_MANAGER); assertNotNull("Unexpected value of attribute " + Port.ID, port.get(Port.ID)); assertEquals("Unexpected value of attribute " + Port.DURABLE, Boolean.FALSE, port.get(Port.DURABLE)); @@ -189,8 +189,30 @@ public class Asserts port.get(Broker.LIFETIME_POLICY)); assertEquals("Unexpected value of attribute " + Port.STATE, State.ACTIVE.name(), port.get(Port.STATE)); assertEquals("Unexpected value of attribute " + Port.TIME_TO_LIVE, 0, port.get(Port.TIME_TO_LIVE)); - assertNotNull("Unexpected value of attribute " + Port.BINDING_ADDRESS, port.get(Port.BINDING_ADDRESS)); - assertNotNull("Unexpected value of attribute " + Port.PROTOCOLS, port.get(Port.PROTOCOLS)); + + @SuppressWarnings("unchecked") + Collection<String> protocols = (Collection<String>) port.get(Port.PROTOCOLS); + assertNotNull("Unexpected value of attribute " + Port.PROTOCOLS, protocols); + boolean isAMQPPort = false; + for (String protocolName : protocols) + { + if (Protocol.valueOf(protocolName).isAMQP()) + { + isAMQPPort = true; + break; + } + } + if (isAMQPPort) + { + assertAttributesPresent(port, Port.AVAILABLE_ATTRIBUTES, Port.CREATED, Port.UPDATED, Port.AUTHENTICATION_MANAGER); + assertNotNull("Unexpected value of attribute " + Port.BINDING_ADDRESS, port.get(Port.BINDING_ADDRESS)); + } + else + { + assertAttributesPresent(port, Port.AVAILABLE_ATTRIBUTES, Port.CREATED, Port.UPDATED, Port.AUTHENTICATION_MANAGER, + Port.BINDING_ADDRESS, Port.TCP_NO_DELAY, Port.SEND_BUFFER_SIZE, Port.RECEIVE_BUFFER_SIZE, + Port.NEED_CLIENT_AUTH, Port.WANT_CLIENT_AUTH); + } assertNotNull("Unexpected value of attribute " + Port.NAME, port.get(Port.NAME)); @SuppressWarnings("unchecked") diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/BrokerRestTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/BrokerRestTest.java index 6a9261bb7f..2e2ce7de5d 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/BrokerRestTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/BrokerRestTest.java @@ -71,7 +71,7 @@ public class BrokerRestTest extends QpidRestTestCase String bindingAddress = (String)ports.get(0).get(Port.BINDING_ADDRESS); Map<String, Object> amqpPort = getRestTestHelper().find(Port.NAME, bindingAddress + ":" + getPort(), ports); - Map<String, Object> httpPort = getRestTestHelper().find(Port.NAME, bindingAddress + ":" + getRestTestHelper().getHttpPort(), ports); + Map<String, Object> httpPort = getRestTestHelper().find(Port.NAME, "" + getRestTestHelper().getHttpPort(), ports); assertNotNull("Cannot find AMQP port", amqpPort); assertNotNull("Cannot find HTTP port", httpPort); diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/PortRestTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/PortRestTest.java index d5a8c31010..bbc034c754 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/PortRestTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/PortRestTest.java @@ -33,14 +33,16 @@ public class PortRestTest extends QpidRestTestCase List<Map<String, Object>> ports = getRestTestHelper().getJsonAsList("/rest/port/"); assertNotNull("Port data cannot be null", ports); assertEquals("Unexpected number of ports", 2, ports.size()); - int[] expectedPorts = { getPort(), getRestTestHelper().getHttpPort() }; - for (int port : expectedPorts) - { - String portName = "0.0.0.0:" + port; - Map<String, Object> portData = getRestTestHelper().find(Port.NAME, portName, ports); - assertNotNull("Port " + portName + " is not found", portData); - Asserts.assertPortAttributes(portData); - } + + String httpPortName = "" + getRestTestHelper().getHttpPort(); + Map<String, Object> portData = getRestTestHelper().find(Port.NAME, httpPortName, ports); + assertNotNull("Http port " + httpPortName + " is not found", portData); + Asserts.assertPortAttributes(portData); + + String amqpPortName = "*:" + getPort(); + Map<String, Object> amqpPortData = getRestTestHelper().find(Port.NAME, amqpPortName, ports); + assertNotNull("Amqp port " + amqpPortName + " is not found", amqpPortData); + Asserts.assertPortAttributes(amqpPortData); } public void testGetPort() throws Exception diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/StructureRestTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/StructureRestTest.java index 1f5e33fe25..a021d33d4b 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/StructureRestTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/StructureRestTest.java @@ -23,6 +23,8 @@ package org.apache.qpid.systest.rest; import java.util.List; import java.util.Map; +import org.apache.qpid.server.model.Port; + public class StructureRestTest extends QpidRestTestCase { @@ -99,14 +101,16 @@ public class StructureRestTest extends QpidRestTestCase */ } - int[] expectedPorts = { getPort(), getRestTestHelper().getHttpPort() }; - for (int port : expectedPorts) - { - String portName = "0.0.0.0:" + port; - Map<String, Object> portData = getRestTestHelper().find("name", portName, ports); - assertNotNull("Port " + portName + " is not found ", portData); - assertNode(portData, portName); - } + + String httpPortName = "" + getRestTestHelper().getHttpPort(); + Map<String, Object> portData = getRestTestHelper().find(Port.NAME, httpPortName, ports); + assertNotNull("Http Port " + httpPortName + " is not found", portData); + assertNode(portData, httpPortName); + + String amqpPortName = "*:" + getPort(); + Map<String, Object> amqpPortData = getRestTestHelper().find(Port.NAME, amqpPortName, ports); + assertNotNull("Amqp port " + amqpPortName + " is not found", amqpPortData); + assertNode(amqpPortData, amqpPortName); } private void assertNode(Map<String, Object> node, String name) |