Author: clebert.suconic(a)jboss.com
Date: 2011-11-18 17:24:01 -0500 (Fri, 18 Nov 2011)
New Revision: 11721
Modified:
branches/Branch_2_2_EAP/src/main/org/hornetq/core/postoffice/PostOffice.java
branches/Branch_2_2_EAP/src/main/org/hornetq/core/postoffice/impl/PostOfficeImpl.java
branches/Branch_2_2_EAP/src/main/org/hornetq/core/postoffice/impl/SimpleAddressManager.java
branches/Branch_2_2_EAP/src/main/org/hornetq/core/protocol/stomp/StompProtocolManager.java
branches/Branch_2_2_EAP/src/main/org/hornetq/core/protocol/stomp/StompSession.java
branches/Branch_2_2_EAP/tests/src/org/hornetq/tests/integration/stomp/StompTest.java
branches/Branch_2_2_EAP/tests/src/org/hornetq/tests/unit/core/server/impl/fakes/FakePostOffice.java
Log:
Stomp to throw exception on inexistent destination = HORNETQ-799
Modified: branches/Branch_2_2_EAP/src/main/org/hornetq/core/postoffice/PostOffice.java
===================================================================
---
branches/Branch_2_2_EAP/src/main/org/hornetq/core/postoffice/PostOffice.java 2011-11-18
22:15:50 UTC (rev 11720)
+++
branches/Branch_2_2_EAP/src/main/org/hornetq/core/postoffice/PostOffice.java 2011-11-18
22:24:01 UTC (rev 11721)
@@ -42,7 +42,21 @@
void addBinding(Binding binding) throws Exception;
Binding removeBinding(SimpleString uniqueName) throws Exception;
+
+ /**
+ * It will lookup the Binding without creating an item on the Queue if non-existent
+ * @param address
+ * @return
+ * @throws Exception
+ */
+ Bindings lookupBindingsForAddress(SimpleString address) throws Exception;
+ /**
+ * Differently to lookupBindings, this will always create a new element on the Queue
if non-existent
+ * @param address
+ * @return
+ * @throws Exception
+ */
Bindings getBindingsForAddress(SimpleString address) throws Exception;
Binding getBinding(SimpleString uniqueName);
Modified:
branches/Branch_2_2_EAP/src/main/org/hornetq/core/postoffice/impl/PostOfficeImpl.java
===================================================================
---
branches/Branch_2_2_EAP/src/main/org/hornetq/core/postoffice/impl/PostOfficeImpl.java 2011-11-18
22:15:50 UTC (rev 11720)
+++
branches/Branch_2_2_EAP/src/main/org/hornetq/core/postoffice/impl/PostOfficeImpl.java 2011-11-18
22:24:01 UTC (rev 11721)
@@ -541,6 +541,12 @@
return bindings;
}
+
+ public Bindings lookupBindingsForAddress(final SimpleString address) throws Exception
+ {
+ return addressManager.getBindingsForRoutingAddress(address);
+ }
+
public Binding getBinding(final SimpleString name)
{
return addressManager.getBinding(name);
Modified:
branches/Branch_2_2_EAP/src/main/org/hornetq/core/postoffice/impl/SimpleAddressManager.java
===================================================================
---
branches/Branch_2_2_EAP/src/main/org/hornetq/core/postoffice/impl/SimpleAddressManager.java 2011-11-18
22:15:50 UTC (rev 11720)
+++
branches/Branch_2_2_EAP/src/main/org/hornetq/core/postoffice/impl/SimpleAddressManager.java 2011-11-18
22:24:01 UTC (rev 11721)
@@ -35,8 +35,14 @@
{
private static final Logger log = Logger.getLogger(SimpleAddressManager.class);
+ /**
+ * HashMap<Address, Binding>
+ */
private final ConcurrentMap<SimpleString, Bindings> mappings = new
ConcurrentHashMap<SimpleString, Bindings>();
+ /**
+ * HashMap<QueueName, Binding>
+ */
private final ConcurrentMap<SimpleString, Binding> nameMap = new
ConcurrentHashMap<SimpleString, Binding>();
private final BindingsFactory bindingsFactory;
Modified:
branches/Branch_2_2_EAP/src/main/org/hornetq/core/protocol/stomp/StompProtocolManager.java
===================================================================
---
branches/Branch_2_2_EAP/src/main/org/hornetq/core/protocol/stomp/StompProtocolManager.java 2011-11-18
22:15:50 UTC (rev 11720)
+++
branches/Branch_2_2_EAP/src/main/org/hornetq/core/protocol/stomp/StompProtocolManager.java 2011-11-18
22:24:01 UTC (rev 11721)
@@ -32,6 +32,7 @@
import org.hornetq.api.core.client.HornetQClient;
import org.hornetq.core.journal.IOAsyncTask;
import org.hornetq.core.logging.Logger;
+import org.hornetq.core.postoffice.Bindings;
import org.hornetq.core.server.HornetQServer;
import org.hornetq.core.server.ServerSession;
import org.hornetq.core.server.impl.ServerMessageImpl;
@@ -536,10 +537,14 @@
String destination = (String)headers.remove(Stomp.Headers.Send.DESTINATION);
String txID = (String)headers.remove(Stomp.Headers.TRANSACTION);
long timestamp = System.currentTimeMillis();
-
+
+ SimpleString address = SimpleString.toSimpleString(destination);
ServerMessageImpl message = new
ServerMessageImpl(server.getStorageManager().generateUniqueID(), 512);
message.setTimestamp(timestamp);
- message.setAddress(SimpleString.toSimpleString(destination));
+ message.setAddress(address);
+
+ validateDestination(address);
+
StompUtils.copyStandardHeadersFromFrameToMessage(frame, message);
if (headers.containsKey(Stomp.Headers.CONTENT_LENGTH))
{
@@ -571,6 +576,20 @@
return null;
}
+ /**
+ * @param address
+ * @throws Exception
+ * @throws HornetQException
+ */
+ private void validateDestination(SimpleString address) throws Exception,
HornetQException
+ {
+ Bindings binding = server.getPostOffice().lookupBindingsForAddress(address);
+ if (binding == null || binding.getBindings().size() == 0)
+ {
+ throw new HornetQException(HornetQException.ADDRESS_DOES_NOT_EXIST,
"Address " + address + " has not been deployed");
+ }
+ }
+
private StompFrame onConnect(StompFrame frame, final StompConnection connection)
throws Exception
{
Map<String, Object> headers = frame.getHeaders();
Modified:
branches/Branch_2_2_EAP/src/main/org/hornetq/core/protocol/stomp/StompSession.java
===================================================================
---
branches/Branch_2_2_EAP/src/main/org/hornetq/core/protocol/stomp/StompSession.java 2011-11-18
22:15:50 UTC (rev 11720)
+++
branches/Branch_2_2_EAP/src/main/org/hornetq/core/protocol/stomp/StompSession.java 2011-11-18
22:24:01 UTC (rev 11721)
@@ -23,7 +23,6 @@
import org.hornetq.api.core.Message;
import org.hornetq.api.core.Pair;
import org.hornetq.api.core.SimpleString;
-import org.hornetq.api.core.TransportConfiguration;
import org.hornetq.core.logging.Logger;
import org.hornetq.core.message.impl.MessageImpl;
import org.hornetq.core.persistence.OperationContext;
Modified:
branches/Branch_2_2_EAP/tests/src/org/hornetq/tests/integration/stomp/StompTest.java
===================================================================
---
branches/Branch_2_2_EAP/tests/src/org/hornetq/tests/integration/stomp/StompTest.java 2011-11-18
22:15:50 UTC (rev 11720)
+++
branches/Branch_2_2_EAP/tests/src/org/hornetq/tests/integration/stomp/StompTest.java 2011-11-18
22:24:01 UTC (rev 11721)
@@ -74,6 +74,23 @@
assertTrue(latch.await(60, TimeUnit.SECONDS));
}
+ public void testSendInvalidDestination() throws Exception
+ {
+ String frame = "CONNECT\n" + "login: brianm\n" +
"passcode: wombats\n\n" + Stomp.NULL;
+ sendFrame(frame);
+ frame = receiveFrame(10000);
+
+ Assert.assertTrue(frame.startsWith("CONNECTED"));
+
+ frame = "SEND\n" + "destination:" + getQueuePrefix() +
getQueueName()+"IdontExist" + "\n\n" + "Hello World" +
Stomp.NULL;
+ sendFrame(frame);
+
+ String frameReceived = receiveFrame(1000);
+ System.out.println(frameReceived);
+
+ Assert.assertTrue(frameReceived.startsWith("ERROR"));
+ }
+
public void testConnect() throws Exception
{
@@ -124,7 +141,6 @@
{
}
}
-
public void testSendMessage() throws Exception
{
Modified:
branches/Branch_2_2_EAP/tests/src/org/hornetq/tests/unit/core/server/impl/fakes/FakePostOffice.java
===================================================================
---
branches/Branch_2_2_EAP/tests/src/org/hornetq/tests/unit/core/server/impl/fakes/FakePostOffice.java 2011-11-18
22:15:50 UTC (rev 11720)
+++
branches/Branch_2_2_EAP/tests/src/org/hornetq/tests/unit/core/server/impl/fakes/FakePostOffice.java 2011-11-18
22:24:01 UTC (rev 11721)
@@ -85,6 +85,12 @@
return null;
}
+ public Bindings lookupBindingsForAddress(final SimpleString address) throws Exception
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
/* (non-Javadoc)
* @see
org.hornetq.core.postoffice.PostOffice#getDuplicateIDCache(org.hornetq.utils.SimpleString)
*/