diff options
| author | Robert Godfrey <rgodfrey@apache.org> | 2014-04-28 16:32:02 +0000 |
|---|---|---|
| committer | Robert Godfrey <rgodfrey@apache.org> | 2014-04-28 16:32:02 +0000 |
| commit | 6125de2e1aa8779d7fd1e59f378ce0a2225d453f (patch) | |
| tree | 76e38fbd0e88bc9a5813fda0527d8d2ca7d701b8 /qpid/java | |
| parent | b5aa0bafee0acbf7684f2ae6918949b2b4ec791a (diff) | |
| download | qpid-python-6125de2e1aa8779d7fd1e59f378ce0a2225d453f.tar.gz | |
QPID-5578 : Address Review comment from Keith Wall re: r1589912
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1590699 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/java')
9 files changed, 132 insertions, 78 deletions
diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/ConfiguredObjectFactoryImpl.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/ConfiguredObjectFactoryImpl.java index 5ac25cce57..440a790fc8 100644 --- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/ConfiguredObjectFactoryImpl.java +++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/ConfiguredObjectFactoryImpl.java @@ -44,49 +44,42 @@ public class ConfiguredObjectFactoryImpl implements ConfiguredObjectFactory public ConfiguredObjectFactoryImpl(Model model) { _model = model; - try + QpidServiceLoader<ConfiguredObjectTypeFactory> serviceLoader = + new QpidServiceLoader<ConfiguredObjectTypeFactory>(); + Iterable<ConfiguredObjectTypeFactory> allFactories = + serviceLoader.instancesOf(ConfiguredObjectTypeFactory.class); + for (ConfiguredObjectTypeFactory factory : allFactories) { - QpidServiceLoader<ConfiguredObjectTypeFactory> serviceLoader = - new QpidServiceLoader<ConfiguredObjectTypeFactory>(); - Iterable<ConfiguredObjectTypeFactory> allFactories = - serviceLoader.instancesOf(ConfiguredObjectTypeFactory.class); - for (ConfiguredObjectTypeFactory factory : allFactories) - { - final Class<? extends ConfiguredObject> categoryClass = factory.getCategoryClass(); - final String categoryName = categoryClass.getSimpleName(); - - Map<String, ConfiguredObjectTypeFactory> categoryFactories = _allFactories.get(categoryName); - if (categoryFactories == null) - { - categoryFactories = new HashMap<String, ConfiguredObjectTypeFactory>(); - _allFactories.put(categoryName, categoryFactories); - _supportedTypes.put(categoryName, new ArrayList<String>()); - ManagedObject annotation = categoryClass.getAnnotation(ManagedObject.class); - if (annotation != null && !"".equals(annotation.defaultType())) - { - _defaultTypes.put(categoryName, annotation.defaultType()); - } - else - { - _defaultTypes.put(categoryName, categoryName); - } + final Class<? extends ConfiguredObject> categoryClass = factory.getCategoryClass(); + final String categoryName = categoryClass.getSimpleName(); - } - if (categoryFactories.put(factory.getType(), factory) != null) + Map<String, ConfiguredObjectTypeFactory> categoryFactories = _allFactories.get(categoryName); + if (categoryFactories == null) + { + categoryFactories = new HashMap<String, ConfiguredObjectTypeFactory>(); + _allFactories.put(categoryName, categoryFactories); + _supportedTypes.put(categoryName, new ArrayList<String>()); + ManagedObject annotation = categoryClass.getAnnotation(ManagedObject.class); + if (annotation != null && !"".equals(annotation.defaultType())) { - throw new ServerScopedRuntimeException( - "Misconfiguration - there is more than one factory defined for class " + categoryName - + " with type " + factory.getType()); + _defaultTypes.put(categoryName, annotation.defaultType()); } - if (factory.getType() != null) + else { - _supportedTypes.get(categoryName).add(factory.getType()); + _defaultTypes.put(categoryName, categoryName); } + + } + if (categoryFactories.put(factory.getType(), factory) != null) + { + throw new ServerScopedRuntimeException( + "Misconfiguration - there is more than one factory defined for class " + categoryName + + " with type " + factory.getType()); + } + if (factory.getType() != null) + { + _supportedTypes.get(categoryName).add(factory.getType()); } - } - catch (RuntimeException | Error e) - { - e.printStackTrace(); } } @@ -103,7 +96,7 @@ public class ConfiguredObjectFactoryImpl implements ConfiguredObjectFactory if(factory == null) { - throw new ServerScopedRuntimeException("No factory defined for ConfiguredObject of category " + category + " and type " + type); + throw new NoFactoryForTypeException(category, type); } return factory.recover(this, record, parents); @@ -115,10 +108,7 @@ public class ConfiguredObjectFactoryImpl implements ConfiguredObjectFactory final ConfiguredObject<?>... parents) { ConfiguredObjectTypeFactory<X> factory = getConfiguredObjectTypeFactory(clazz, attributes); - if(factory == null) - { - throw new ServerScopedRuntimeException("No factory defined for ConfiguredObject of category " + clazz.getSimpleName() + " and attributes " + attributes); - } + return factory.create(this, attributes, parents); } @@ -130,7 +120,7 @@ public class ConfiguredObjectFactoryImpl implements ConfiguredObjectFactory Map<String, ConfiguredObjectTypeFactory> categoryFactories = _allFactories.get(category); if(categoryFactories == null) { - throw new ServerScopedRuntimeException("No factory defined for ConfiguredObject of category " + category); + throw new NoFactoryForCategoryException(category); } String type = (String) attributes.get(ConfiguredObject.TYPE); @@ -139,6 +129,10 @@ public class ConfiguredObjectFactoryImpl implements ConfiguredObjectFactory if(type != null) { factory = getConfiguredObjectTypeFactory(category, type); + if(factory == null) + { + throw new NoFactoryForTypeException(category, type); + } } else { @@ -147,6 +141,10 @@ public class ConfiguredObjectFactoryImpl implements ConfiguredObjectFactory { ManagedObject annotation = categoryClass.getAnnotation(ManagedObject.class); factory = getConfiguredObjectTypeFactory(category, annotation.defaultType()); + if(factory == null) + { + throw new NoFactoryForTypeException(category, annotation.defaultType()); + } } } return factory; @@ -159,12 +157,16 @@ public class ConfiguredObjectFactoryImpl implements ConfiguredObjectFactory Map<String, ConfiguredObjectTypeFactory> categoryFactories = _allFactories.get(category); if(categoryFactories == null) { - throw new ServerScopedRuntimeException("No factory defined for ConfiguredObject of category " + category); + throw new NoFactoryForCategoryException(category); } ConfiguredObjectTypeFactory factory = categoryFactories.get(type); if(factory == null) { factory = categoryFactories.get(_defaultTypes.get(category)); + if(factory == null) + { + throw new NoFactoryForTypeException(category, _defaultTypes.get(category)); + } } return factory; } diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/exchange/AMQUnknownExchangeType.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/NoFactoryForCategoryException.java index d5daf22a52..4e249ab5dc 100644 --- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/exchange/AMQUnknownExchangeType.java +++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/NoFactoryForCategoryException.java @@ -18,24 +18,20 @@ * under the License. * */ +package org.apache.qpid.server.model; -package org.apache.qpid.server.exchange; - -/** - * AMQUnknownExchangeType represents coding error where unknown exchange type requested from exchange factory. - * - * <p/><table id="crc"><caption>CRC Card</caption> - * <tr><th> Responsibilities <th> Collaborations - * <tr><td> Represents unknown exchange type request. - * <tr><td> - * - * @todo Represent coding error, where unknown exchange type is requested by passing a string parameter. Use a type safe - * enum for the exchange type, or replace with IllegalArgumentException. Should be runtime. - */ -public class AMQUnknownExchangeType extends RuntimeException +public class NoFactoryForCategoryException extends RuntimeException { - public AMQUnknownExchangeType(String message, Throwable cause) + private final String _category; + + public NoFactoryForCategoryException(final String category) + { + super("Unknown category: " + category); + _category = category; + } + + public String getCategory() { - super(message, cause); + return _category; } } diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/NoFactoryForTypeException.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/NoFactoryForTypeException.java new file mode 100644 index 0000000000..1ccf685495 --- /dev/null +++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/NoFactoryForTypeException.java @@ -0,0 +1,45 @@ +/* + * + * 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; + +public class NoFactoryForTypeException extends RuntimeException +{ + private final String _category; + private final String _type; + + public NoFactoryForTypeException(final String category, + final String type) + { + super("Unknown configured object type '"+type+"' of category '" + category +"'"); + _category = category; + _type = type; + } + + public String getCategory() + { + return _category; + } + + public String getType() + { + return _type; + } +} diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/virtualhost/AbstractVirtualHost.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/virtualhost/AbstractVirtualHost.java index dd97b0cba9..93006823d9 100644 --- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/virtualhost/AbstractVirtualHost.java +++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/virtualhost/AbstractVirtualHost.java @@ -41,12 +41,12 @@ import java.util.concurrent.atomic.AtomicBoolean; import javax.security.auth.Subject; import org.apache.log4j.Logger; + import org.apache.qpid.exchange.ExchangeDefaults; import org.apache.qpid.server.configuration.BrokerProperties; import org.apache.qpid.server.configuration.IllegalConfigurationException; import org.apache.qpid.server.connection.ConnectionRegistry; import org.apache.qpid.server.connection.IConnectionRegistry; -import org.apache.qpid.server.exchange.AMQUnknownExchangeType; import org.apache.qpid.server.exchange.DefaultDestination; import org.apache.qpid.server.exchange.ExchangeImpl; import org.apache.qpid.server.logging.EventLogger; @@ -671,7 +671,7 @@ public abstract class AbstractVirtualHost<X extends AbstractVirtualHost<X>> exte @Override public ExchangeImpl createExchange(Map<String,Object> attributes) throws ExchangeExistsException, ReservedExchangeNameException, - AMQUnknownExchangeType + NoFactoryForTypeException { checkVHostStateIsActive(); ExchangeImpl child = addExchange(attributes); @@ -682,7 +682,7 @@ public abstract class AbstractVirtualHost<X extends AbstractVirtualHost<X>> exte private ExchangeImpl addExchange(Map<String,Object> attributes) throws ExchangeExistsException, ReservedExchangeNameException, - AMQUnknownExchangeType + NoFactoryForTypeException { try { @@ -1329,7 +1329,7 @@ public abstract class AbstractVirtualHost<X extends AbstractVirtualHost<X>> exte // We're ok if the exchange already exists dlExchange = e.getExistingExchange(); } - catch (ReservedExchangeNameException | AMQUnknownExchangeType | UnknownConfiguredObjectException e) + catch (ReservedExchangeNameException | NoFactoryForTypeException | UnknownConfiguredObjectException e) { throw new ConnectionScopedRuntimeException("Attempt to create an alternate exchange for a queue failed",e); } diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/virtualhost/VirtualHostImpl.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/virtualhost/VirtualHostImpl.java index 46351aa970..d3698495c3 100755 --- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/virtualhost/VirtualHostImpl.java +++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/virtualhost/VirtualHostImpl.java @@ -27,12 +27,12 @@ import java.util.concurrent.ScheduledFuture; import org.apache.qpid.common.Closeable; import org.apache.qpid.server.connection.IConnectionRegistry; -import org.apache.qpid.server.exchange.AMQUnknownExchangeType; import org.apache.qpid.server.exchange.ExchangeImpl; import org.apache.qpid.server.logging.EventLogger; import org.apache.qpid.server.logging.EventLoggerProvider; import org.apache.qpid.server.message.MessageDestination; import org.apache.qpid.server.message.MessageSource; +import org.apache.qpid.server.model.NoFactoryForTypeException; import org.apache.qpid.server.model.VirtualHost; import org.apache.qpid.server.protocol.LinkRegistry; import org.apache.qpid.server.queue.AMQQueue; @@ -66,7 +66,7 @@ public interface VirtualHostImpl< X extends VirtualHostImpl<X,Q,E>, Q extends AM E createExchange(Map<String,Object> attributes) throws ExchangeExistsException, ReservedExchangeNameException, - AMQUnknownExchangeType; + NoFactoryForTypeException; void removeExchange(E exchange, boolean force) throws ExchangeIsAlternateException, RequiredExchangeException; diff --git a/qpid/java/broker-plugins/amqp-0-10-protocol/src/main/java/org/apache/qpid/server/protocol/v0_10/ServerSessionDelegate.java b/qpid/java/broker-plugins/amqp-0-10-protocol/src/main/java/org/apache/qpid/server/protocol/v0_10/ServerSessionDelegate.java index ff57e6a33c..db94249c64 100644 --- a/qpid/java/broker-plugins/amqp-0-10-protocol/src/main/java/org/apache/qpid/server/protocol/v0_10/ServerSessionDelegate.java +++ b/qpid/java/broker-plugins/amqp-0-10-protocol/src/main/java/org/apache/qpid/server/protocol/v0_10/ServerSessionDelegate.java @@ -33,7 +33,6 @@ import java.util.UUID; import org.apache.log4j.Logger; import org.apache.qpid.server.consumer.ConsumerImpl; -import org.apache.qpid.server.exchange.AMQUnknownExchangeType; import org.apache.qpid.server.exchange.DirectExchange; import org.apache.qpid.server.exchange.ExchangeImpl; import org.apache.qpid.server.exchange.HeadersExchange; @@ -47,6 +46,7 @@ import org.apache.qpid.server.message.MessageReference; import org.apache.qpid.server.message.MessageSource; import org.apache.qpid.server.model.ExclusivityPolicy; import org.apache.qpid.server.model.LifetimePolicy; +import org.apache.qpid.server.model.NoFactoryForTypeException; import org.apache.qpid.server.model.Queue; import org.apache.qpid.server.model.UnknownConfiguredObjectException; import org.apache.qpid.server.plugin.ExchangeType; @@ -755,7 +755,7 @@ public class ServerSessionDelegate extends SessionDelegate exception(session, method, ExecutionErrorCode.NOT_FOUND, "Unknown alternate exchange " + e.getName()); } - catch(AMQUnknownExchangeType e) + catch(NoFactoryForTypeException e) { exception(session, method, ExecutionErrorCode.NOT_FOUND, "Unknown Exchange Type: " + method.getType()); } diff --git a/qpid/java/broker-plugins/amqp-0-8-protocol/src/main/java/org/apache/qpid/server/protocol/v0_8/handler/ExchangeDeclareHandler.java b/qpid/java/broker-plugins/amqp-0-8-protocol/src/main/java/org/apache/qpid/server/protocol/v0_8/handler/ExchangeDeclareHandler.java index efd50e5595..73b53c5e64 100644 --- a/qpid/java/broker-plugins/amqp-0-8-protocol/src/main/java/org/apache/qpid/server/protocol/v0_8/handler/ExchangeDeclareHandler.java +++ b/qpid/java/broker-plugins/amqp-0-8-protocol/src/main/java/org/apache/qpid/server/protocol/v0_8/handler/ExchangeDeclareHandler.java @@ -33,10 +33,10 @@ import org.apache.qpid.framing.AMQShortString; import org.apache.qpid.framing.ExchangeDeclareBody; import org.apache.qpid.framing.MethodRegistry; import org.apache.qpid.protocol.AMQConstant; -import org.apache.qpid.server.exchange.AMQUnknownExchangeType; import org.apache.qpid.server.exchange.DirectExchange; import org.apache.qpid.server.exchange.ExchangeImpl; import org.apache.qpid.server.model.LifetimePolicy; +import org.apache.qpid.server.model.NoFactoryForTypeException; import org.apache.qpid.server.model.UnknownConfiguredObjectException; import org.apache.qpid.server.protocol.v0_8.AMQChannel; import org.apache.qpid.server.protocol.v0_8.AMQProtocolSession; @@ -147,7 +147,7 @@ public class ExchangeDeclareHandler implements StateAwareMethodListener<Exchange body.getMajor(), body.getMinor(),null); } } - catch(AMQUnknownExchangeType e) + catch(NoFactoryForTypeException e) { throw body.getConnectionException(AMQConstant.COMMAND_INVALID, "Unknown exchange: " + exchangeName,e); } diff --git a/qpid/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/mbeans/VirtualHostManagerMBean.java b/qpid/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/mbeans/VirtualHostManagerMBean.java index 3fdee24ff8..69b7dff117 100644 --- a/qpid/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/mbeans/VirtualHostManagerMBean.java +++ b/qpid/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/mbeans/VirtualHostManagerMBean.java @@ -42,10 +42,10 @@ import org.apache.qpid.management.common.mbeans.ManagedQueue; import org.apache.qpid.management.common.mbeans.annotations.MBeanConstructor; import org.apache.qpid.management.common.mbeans.annotations.MBeanDescription; import org.apache.qpid.management.common.mbeans.annotations.MBeanOperationParameter; -import org.apache.qpid.server.exchange.AMQUnknownExchangeType; import org.apache.qpid.server.jmx.ManagedObject; import org.apache.qpid.server.model.Exchange; import org.apache.qpid.server.model.LifetimePolicy; +import org.apache.qpid.server.model.NoFactoryForTypeException; import org.apache.qpid.server.model.Queue; import org.apache.qpid.server.model.VirtualHost; import org.apache.qpid.server.queue.QueueArgumentsConverter; @@ -187,7 +187,7 @@ public class VirtualHostManagerMBean extends AbstractStatisticsGatheringMBean<Vi { throw new UnsupportedOperationException("'" + name + "' is a reserved exchange name"); } - catch(AMQUnknownExchangeType e) + catch(NoFactoryForTypeException e) { JMException jme = new JMException(e.getMessage()); throw new MBeanException(jme, "Error in creating exchange " + name); diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/test/client/destination/AddressBasedDestinationTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/test/client/destination/AddressBasedDestinationTest.java index 88f8142f94..14cadc2389 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/test/client/destination/AddressBasedDestinationTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/test/client/destination/AddressBasedDestinationTest.java @@ -56,6 +56,7 @@ import org.apache.qpid.client.AMQSession_0_10; import org.apache.qpid.client.message.QpidMessageProperties; import org.apache.qpid.jndi.PropertiesFileInitialContextFactory; import org.apache.qpid.messaging.Address; +import org.apache.qpid.protocol.AMQConstant; import org.apache.qpid.test.utils.QpidBrokerTestCase; import org.apache.qpid.transport.ExecutionErrorCode; @@ -270,7 +271,7 @@ public class AddressBasedDestinationTest extends QpidBrokerTestCase public void testCreateExchange() throws Exception { - createExchangeImpl(false, false); + createExchangeImpl(false, false, false); } /** @@ -279,7 +280,7 @@ public class AddressBasedDestinationTest extends QpidBrokerTestCase */ public void testCreateExchangeWithArgs() throws Exception { - createExchangeImpl(true, false); + createExchangeImpl(true, false, false); } /** @@ -289,11 +290,12 @@ public class AddressBasedDestinationTest extends QpidBrokerTestCase */ public void testCreateExchangeWithNonsenseArgs() throws Exception { - createExchangeImpl(true, true); + createExchangeImpl(true, true, false); } private void createExchangeImpl(final boolean withExchangeArgs, - final boolean useNonsenseArguments) throws Exception + final boolean useNonsenseArguments, + final boolean useNonsenseExchangeType) throws Exception { Session jmsSession = _connection.createSession(false,Session.AUTO_ACKNOWLEDGE); @@ -305,7 +307,9 @@ public class AddressBasedDestinationTest extends QpidBrokerTestCase "type: topic, " + "x-declare: " + "{ " + - "type:direct, " + + "type:" + + (useNonsenseExchangeType ? "nonsense" : "direct") + + ", " + "auto-delete: true" + createExchangeArgsString(withExchangeArgs, useNonsenseArguments) + "}" + @@ -318,7 +322,7 @@ public class AddressBasedDestinationTest extends QpidBrokerTestCase try { cons = jmsSession.createConsumer(dest); - if(useNonsenseArguments) + if(useNonsenseArguments || useNonsenseExchangeType) { fail("Expected execution exception during exchange declare did not occur"); } @@ -331,6 +335,10 @@ public class AddressBasedDestinationTest extends QpidBrokerTestCase //for. We can't do the rest of the test as a result of the exception, just stop. return; } + else if(useNonsenseExchangeType && (e.getErrorCode().equals(String.valueOf(AMQConstant.NOT_FOUND.getCode())))) + { + return; + } else { fail("Unexpected exception whilst creating consumer: " + e); @@ -1239,8 +1247,11 @@ public class AddressBasedDestinationTest extends QpidBrokerTestCase { assertEquals("Failure code is not as expected", "404", e.getErrorCode()); } + } - + public void testUnknownExchangeType() throws Exception + { + createExchangeImpl(false, false, true); } public void testQueueBrowserWithSelectorAutoAcknowledgement() throws Exception |
