From 4bf6c675b8ccf0b79a2cb635de937677299e3642 Mon Sep 17 00:00:00 2001 From: Chris Beams Date: Thu, 29 Jul 2010 18:00:58 +0200 Subject: [PATCH] Remove dead code and unused imports Fix dead exception case Exception was previously being thrown if replyTo address was null, however this was unreachable code as replyTo is always assigned a new Address. Logic has been changed to throw the same exception if the default response routing key is found to be null. --- .../amqp/core/SimpleMessageProperties.java | 242 ------------------ .../erlang/core/ErlangTemplate.java | 1 - .../springframework/util/exec/Background.java | 7 +- .../org/springframework/util/exec/Escape.java | 2 +- .../springframework/util/exec/Execute.java | 2 - .../util/exec/PumpStreamHandler.java | 9 - .../amqp/rabbit/admin/QueueInfo.java | 1 - .../admin/RabbitControlErlangConverter.java | 4 - .../admin/JInterfaceIntegrationTests.java | 1 - .../RabbitBrokerAdminIntegrationTests.java | 1 - ...TestExecutionListenerIntegrationTests.java | 2 - .../adapter/MessageListenerAdapter.java | 4 +- .../RabbitAdminNamespaceHandlerTests.java | 22 +- 13 files changed, 5 insertions(+), 293 deletions(-) delete mode 100644 spring-amqp-core/src/main/java/org/springframework/amqp/core/SimpleMessageProperties.java diff --git a/spring-amqp-core/src/main/java/org/springframework/amqp/core/SimpleMessageProperties.java b/spring-amqp-core/src/main/java/org/springframework/amqp/core/SimpleMessageProperties.java deleted file mode 100644 index 784b26a2..00000000 --- a/spring-amqp-core/src/main/java/org/springframework/amqp/core/SimpleMessageProperties.java +++ /dev/null @@ -1,242 +0,0 @@ -/* - * Copyright 2002-2010 the original author or authors. - * - * Licensed 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.springframework.amqp.core; - -import java.util.Date; -import java.util.HashMap; -import java.util.Map; - -/** - * @author Mark Fisher - */ -public class SimpleMessageProperties implements MessageProperties { - - private static final String DEFAULT_CHARSET = "UTF-8"; - - - private volatile String defaultCharset = DEFAULT_CHARSET; - - private volatile String appId; - - private volatile String clusterId; - - private volatile String contentEncoding; - - private volatile long contentLength; - - private volatile String contentType = MessageProperties.CONTENT_TYPE_BYTES; - - private volatile byte[] correlationId; - - private volatile MessageDeliveryMode deliveryMode; - - private volatile long deliveryTag; - - private volatile String expiration; - - private volatile Map headers = new HashMap(); - - private volatile Integer messageCount; - - private volatile String messageId; - - private volatile Integer priority; - - private volatile String receivedExchange; - - private volatile String receivedRoutingKey; - - private volatile Address replyTo; - - private volatile Date timestamp; - - private volatile String type; - - private volatile String userId; - - private volatile Boolean redelivered; - - - public String getAppId() { - return this.appId; - } - - public void setAppId(String appId) { - this.appId = appId; - } - - public String getClusterId() { - return this.clusterId; - } - - public void setClusterId(String clusterId) { - this.clusterId = clusterId; - } - - public String getContentEncoding() { - return this.contentEncoding; - } - - public void setContentEncoding(String contentEncoding) { - this.contentEncoding = contentEncoding; - } - - public long getContentLength() { - return this.contentLength; - } - - public void setContentLength(long contentLength) { - this.contentLength = contentLength; - } - - public String getContentType() { - return this.contentType; - } - - public void setContentType(String contentType) { - this.contentType = contentType; - } - - public byte[] getCorrelationId() { - return this.correlationId; - } - - public void setCorrelationId(byte[] correlationId) { - this.correlationId = correlationId; - } - - public MessageDeliveryMode getDeliveryMode() { - return this.deliveryMode; - } - - public void setDeliveryMode(MessageDeliveryMode deliveryMode) { - this.deliveryMode = deliveryMode; - } - - public long getDeliveryTag() { - return this.deliveryTag; - } - - public void setDeliveryTag(long deliveryTag) { - this.deliveryTag = deliveryTag; - } - - public String getExpiration() { - return this.expiration; - } - - public void setExpiration(String expiration) { - this.expiration = expiration; - } - - public Map getHeaders() { - return this.headers; - } - - public void setHeaders(Map headers) { - this.headers = headers; - } - - public Integer getMessageCount() { - return this.messageCount; - } - - public void setMessageCount(Integer messageCount) { - this.messageCount = messageCount; - } - - public String getMessageId() { - return this.messageId; - } - - public void setMessageId(String messageId) { - this.messageId = messageId; - } - - public Integer getPriority() { - return this.priority; - } - - public void setPriority(Integer priority) { - this.priority = priority; - } - - public String getReceivedExchange() { - return this.receivedExchange; - } - - public void setReceivedExchange(String receivedExchange) { - this.receivedExchange = receivedExchange; - } - - public String getReceivedRoutingKey() { - return this.receivedRoutingKey; - } - - public void setReceivedRoutingKey(String receivedRoutingKey) { - this.receivedRoutingKey = receivedRoutingKey; - } - - public Address getReplyTo() { - return this.replyTo; - } - - public void setReplyTo(Address replyTo) { - this.replyTo = replyTo; - } - - public Date getTimestamp() { - return this.timestamp; - } - - public void setTimestamp(Date timestamp) { - this.timestamp = timestamp; - } - - public String getType() { - return this.type; - } - - public void setType(String type) { - this.type = type; - } - - public String getUserId() { - return this.userId; - } - - public void setUserId(String userId) { - this.userId = userId; - } - - public Boolean isRedelivered() { - return this.redelivered; - } - - public void setRedelivered(Boolean redelivered) { - this.redelivered = redelivered; - } - - public void setDefaultCharset(String defaultCharset) { - this.defaultCharset = defaultCharset; - } - - public void setHeader(String key, Object value) { - this.headers.put(key, value); - } - -} diff --git a/spring-erlang/src/main/java/org/springframework/erlang/core/ErlangTemplate.java b/spring-erlang/src/main/java/org/springframework/erlang/core/ErlangTemplate.java index f2bfeb96..41d86965 100644 --- a/spring-erlang/src/main/java/org/springframework/erlang/core/ErlangTemplate.java +++ b/spring-erlang/src/main/java/org/springframework/erlang/core/ErlangTemplate.java @@ -61,7 +61,6 @@ public class ErlangTemplate extends ErlangAccessor implements ErlangOperations { if (result instanceof OtpErlangTuple) { OtpErlangTuple msg = (OtpErlangTuple)result; - OtpErlangObject[] elements = msg.elements(); if (msg.elementAt(0) instanceof OtpErlangAtom) { OtpErlangAtom responseAtom = (OtpErlangAtom)msg.elementAt(0); diff --git a/spring-erlang/src/main/java/org/springframework/util/exec/Background.java b/spring-erlang/src/main/java/org/springframework/util/exec/Background.java index 5676dc1e..7d420fca 100644 --- a/spring-erlang/src/main/java/org/springframework/util/exec/Background.java +++ b/spring-erlang/src/main/java/org/springframework/util/exec/Background.java @@ -72,7 +72,6 @@ public class Background { { StringBuffer escaped; String[] execCmd; - Runtime r; escaped = new StringBuffer(); for(int i=0; i tmpCmd = new ArrayList(); tmpCmd.add("cmd"); @@ -126,7 +121,7 @@ public class Background { (appendErr == true ? ">>" : " >") + Escape.escape(errFile.getAbsolutePath())); - Process p = Runtime.getRuntime().exec((String [])tmpCmd.toArray(cmd)); + Runtime.getRuntime().exec((String [])tmpCmd.toArray(cmd)); } public static void main(String[] args) throws Exception { diff --git a/spring-erlang/src/main/java/org/springframework/util/exec/Escape.java b/spring-erlang/src/main/java/org/springframework/util/exec/Escape.java index b083a2a1..17a5deb1 100644 --- a/spring-erlang/src/main/java/org/springframework/util/exec/Escape.java +++ b/spring-erlang/src/main/java/org/springframework/util/exec/Escape.java @@ -30,7 +30,7 @@ public class Escape { * (such as whitespace, quotes, slashes, etc.) */ public static String escape(String in){ - char[] inChars, outChars, resChars; + char[] inChars, outChars; int numOut; inChars = new char[in.length()]; diff --git a/spring-erlang/src/main/java/org/springframework/util/exec/Execute.java b/spring-erlang/src/main/java/org/springframework/util/exec/Execute.java index c5de040a..f789ac42 100644 --- a/spring-erlang/src/main/java/org/springframework/util/exec/Execute.java +++ b/spring-erlang/src/main/java/org/springframework/util/exec/Execute.java @@ -112,8 +112,6 @@ public class Execute { return cmd; } else if ( Os.isFamily("windows") ) { - String osname = - System.getProperty("os.name").toLowerCase(Locale.US); String[] cmd = {"cmd", "/c", "set" }; return cmd; } diff --git a/spring-erlang/src/main/java/org/springframework/util/exec/PumpStreamHandler.java b/spring-erlang/src/main/java/org/springframework/util/exec/PumpStreamHandler.java index 478c5fc9..0fcf9f5f 100644 --- a/spring-erlang/src/main/java/org/springframework/util/exec/PumpStreamHandler.java +++ b/spring-erlang/src/main/java/org/springframework/util/exec/PumpStreamHandler.java @@ -73,16 +73,10 @@ public class PumpStreamHandler implements ExecuteStreamHandler { public void stop() { if( ! running ) return; try { - //if( log.isDebugEnabled() ) log.debug("Joining it"); - // inputThread.interrupt(); inputThread.join(1000); - //if( log.isDebugEnabled() ) log.debug("Joined" ); } catch(InterruptedException e) {} try { - //if( log.isDebugEnabled() ) log.debug("Joining it"); - // errorThread.interrupt(); errorThread.join(1000); - //if( log.isDebugEnabled() ) log.debug("Joined" ); } catch(InterruptedException e) {} try { err.flush(); @@ -119,7 +113,4 @@ public class PumpStreamHandler implements ExecuteStreamHandler { return result; } - private static org.apache.commons.logging.Log log= - org.apache.commons.logging.LogFactory.getLog( PumpStreamHandler.class ); - } diff --git a/spring-rabbit-admin/src/main/java/org/springframework/amqp/rabbit/admin/QueueInfo.java b/spring-rabbit-admin/src/main/java/org/springframework/amqp/rabbit/admin/QueueInfo.java index fd6c03a2..92f713dc 100644 --- a/spring-rabbit-admin/src/main/java/org/springframework/amqp/rabbit/admin/QueueInfo.java +++ b/spring-rabbit-admin/src/main/java/org/springframework/amqp/rabbit/admin/QueueInfo.java @@ -15,7 +15,6 @@ */ package org.springframework.amqp.rabbit.admin; -import java.util.Map; /** * This class represents a Queue that is configured on the RabbitMQ broker diff --git a/spring-rabbit-admin/src/main/java/org/springframework/amqp/rabbit/admin/RabbitControlErlangConverter.java b/spring-rabbit-admin/src/main/java/org/springframework/amqp/rabbit/admin/RabbitControlErlangConverter.java index f68a3850..29a7a1f0 100644 --- a/spring-rabbit-admin/src/main/java/org/springframework/amqp/rabbit/admin/RabbitControlErlangConverter.java +++ b/spring-rabbit-admin/src/main/java/org/springframework/amqp/rabbit/admin/RabbitControlErlangConverter.java @@ -18,13 +18,11 @@ package org.springframework.amqp.rabbit.admin; import java.util.ArrayList; import java.util.HashMap; -import java.util.Iterator; import java.util.List; import java.util.Map; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; - import org.springframework.erlang.core.Application; import org.springframework.erlang.core.Node; import org.springframework.erlang.support.converter.ErlangConversionException; @@ -34,9 +32,7 @@ import org.springframework.erlang.support.converter.SimpleErlangConverter; import com.ericsson.otp.erlang.OtpErlangAtom; import com.ericsson.otp.erlang.OtpErlangBinary; import com.ericsson.otp.erlang.OtpErlangList; -import com.ericsson.otp.erlang.OtpErlangLong; import com.ericsson.otp.erlang.OtpErlangObject; -import com.ericsson.otp.erlang.OtpErlangPid; import com.ericsson.otp.erlang.OtpErlangTuple; /*** diff --git a/spring-rabbit-admin/src/test/java/org/springframework/amqp/rabbit/admin/JInterfaceIntegrationTests.java b/spring-rabbit-admin/src/test/java/org/springframework/amqp/rabbit/admin/JInterfaceIntegrationTests.java index 9c74bc89..a999a11b 100644 --- a/spring-rabbit-admin/src/test/java/org/springframework/amqp/rabbit/admin/JInterfaceIntegrationTests.java +++ b/spring-rabbit-admin/src/test/java/org/springframework/amqp/rabbit/admin/JInterfaceIntegrationTests.java @@ -24,7 +24,6 @@ public class JInterfaceIntegrationTests { @Test public void rawApi() { - String markpCookie = "HRVDLVJTUELWREUSYOCA"; OtpConnection connection = null; try { OtpSelf self = new OtpSelf("rabbit-monitor"); diff --git a/spring-rabbit-admin/src/test/java/org/springframework/amqp/rabbit/admin/RabbitBrokerAdminIntegrationTests.java b/spring-rabbit-admin/src/test/java/org/springframework/amqp/rabbit/admin/RabbitBrokerAdminIntegrationTests.java index e523721d..105ebea5 100644 --- a/spring-rabbit-admin/src/test/java/org/springframework/amqp/rabbit/admin/RabbitBrokerAdminIntegrationTests.java +++ b/spring-rabbit-admin/src/test/java/org/springframework/amqp/rabbit/admin/RabbitBrokerAdminIntegrationTests.java @@ -22,7 +22,6 @@ import static org.junit.Assert.assertTrue; import java.util.List; import org.junit.BeforeClass; -import org.junit.Ignore; import org.junit.Test; import org.springframework.amqp.core.Queue; diff --git a/spring-rabbit-admin/src/test/java/org/springframework/amqp/rabbit/test/RabbitTestExecutionListenerIntegrationTests.java b/spring-rabbit-admin/src/test/java/org/springframework/amqp/rabbit/test/RabbitTestExecutionListenerIntegrationTests.java index 5afe1623..6dc2ceb8 100644 --- a/spring-rabbit-admin/src/test/java/org/springframework/amqp/rabbit/test/RabbitTestExecutionListenerIntegrationTests.java +++ b/spring-rabbit-admin/src/test/java/org/springframework/amqp/rabbit/test/RabbitTestExecutionListenerIntegrationTests.java @@ -12,8 +12,6 @@ import org.springframework.test.context.ContextConfiguration; @Ignore // only works on Windows at the moment public class RabbitTestExecutionListenerIntegrationTests { - private static int count; - @Test public void doNothing() throws InterruptedException { Thread.sleep(1000); diff --git a/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/listener/adapter/MessageListenerAdapter.java b/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/listener/adapter/MessageListenerAdapter.java index 698c83e9..5bbec71b 100644 --- a/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/listener/adapter/MessageListenerAdapter.java +++ b/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/listener/adapter/MessageListenerAdapter.java @@ -562,11 +562,11 @@ public class MessageListenerAdapter implements MessageListener, ChannelAwareMess Address replyTo = request.getMessageProperties().getReplyTo(); if (replyTo == null) { - replyTo = new Address(defaultResponseRoutingKey); - if (replyTo == null) { + if (defaultResponseRoutingKey == null) { throw new AmqpException("Cannot determine ReplyTo message property value: " + "Request message does not contain reply-to property, and no default ReplyTo value set."); } + replyTo = new Address(defaultResponseRoutingKey); } return replyTo.toString(); } diff --git a/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/config/RabbitAdminNamespaceHandlerTests.java b/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/config/RabbitAdminNamespaceHandlerTests.java index 497ba996..bac23055 100644 --- a/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/config/RabbitAdminNamespaceHandlerTests.java +++ b/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/config/RabbitAdminNamespaceHandlerTests.java @@ -16,19 +16,8 @@ package org.springframework.amqp.rabbit.config; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import java.util.Map; - import org.junit.Test; -import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer; -import org.springframework.beans.factory.support.DefaultListableBeanFactory; -import org.springframework.beans.factory.xml.XmlBeanDefinitionReader; -import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; -import org.springframework.core.io.Resource; /** * @@ -38,16 +27,7 @@ public final class RabbitAdminNamespaceHandlerTests { @Test public void testParse() throws Exception { - ApplicationContext applicationContext = new ClassPathXmlApplicationContext( - "rabbitAdminNamespaceHandlerTests.xml", getClass()); - - /* - * Map beans = applicationContext - .getBeansOfType(PropertyPlaceholderConfigurer.class); - assertFalse("No PropertyPlaceHolderConfigurer found", beans.isEmpty()); - String s = (String) applicationContext.getBean("string"); - assertEquals("No properties replaced", "bar", s); - */ + new ClassPathXmlApplicationContext("rabbitAdminNamespaceHandlerTests.xml", getClass()); } }