Преглед изворни кода

Web service now uses SystemEvents interface to place incoming registration attempts on queue. JMS is now isolated to the infrastructure.messagning.jms package.

peter_backlund пре 18 година
родитељ
комит
b4012c6f86

+ 1
- 1
dddsample/src/main/java/se/citerus/dddsample/application/SystemEvents.java Прегледај датотеку

@@ -26,6 +26,6 @@ public interface SystemEvents {
26 26
 
27 27
   void rejectHandlingEventRegistrationAttempt(HandlingEventRegistrationAttempt attempt, CannotCreateHandlingEventException problem);
28 28
 
29
-  //void scheduleWasChanged(Voyage voyage);
29
+  void receivedHandlingEventRegistrationAttempt(HandlingEventRegistrationAttempt attempt);
30 30
 
31 31
 }

+ 7
- 28
dddsample/src/main/java/se/citerus/dddsample/application/ws/HandlingEventServiceEndpointImpl.java Прегледај датотеку

@@ -3,18 +3,13 @@ package se.citerus.dddsample.application.ws;
3 3
 import org.apache.commons.lang.StringUtils;
4 4
 import org.apache.commons.logging.Log;
5 5
 import org.apache.commons.logging.LogFactory;
6
-import org.springframework.jms.core.JmsOperations;
7
-import org.springframework.jms.core.MessageCreator;
8 6
 import se.citerus.dddsample.application.HandlingEventRegistrationAttempt;
7
+import se.citerus.dddsample.application.SystemEvents;
9 8
 import se.citerus.dddsample.domain.model.cargo.TrackingId;
10 9
 import se.citerus.dddsample.domain.model.carrier.VoyageNumber;
11 10
 import se.citerus.dddsample.domain.model.handling.HandlingEvent;
12 11
 import se.citerus.dddsample.domain.model.location.UnLocode;
13 12
 
14
-import javax.jms.JMSException;
15
-import javax.jms.Message;
16
-import javax.jms.Queue;
17
-import javax.jms.Session;
18 13
 import javax.jws.WebService;
19 14
 import java.text.ParseException;
20 15
 import java.text.SimpleDateFormat;
@@ -32,8 +27,7 @@ import java.util.List;
32 27
 @WebService(endpointInterface = "se.citerus.dddsample.application.ws.HandlingEventServiceEndpoint")
33 28
 public class HandlingEventServiceEndpointImpl implements HandlingEventServiceEndpoint {
34 29
 
35
-  private JmsOperations jmsOperations;
36
-  private Queue handlingEventQueue;
30
+  private SystemEvents systemEvents;
37 31
   private static final Log logger = LogFactory.getLog(HandlingEventServiceEndpointImpl.class);
38 32
   
39 33
   public static final String ISO_8601_FORMAT = "yyyy-mm-dd HH:MM:SS.SSS";
@@ -49,25 +43,14 @@ public class HandlingEventServiceEndpointImpl implements HandlingEventServiceEnd
49 43
     final UnLocode ul = parseUnLocode(unlocode, errors);
50 44
 
51 45
     if (errors.isEmpty()) {
52
-      sendRegistrationAttemptMessage(date, tid, voyageNumber, type, ul);
46
+      final HandlingEventRegistrationAttempt attempt = new HandlingEventRegistrationAttempt(new Date(), date, tid, voyageNumber, type, ul);
47
+      systemEvents.receivedHandlingEventRegistrationAttempt(attempt);
53 48
     } else {
54
-      logger.info("Handling event registration attempt failed: " + errors);
49
+      logger.warn("Handling event registration attempt failed: " + errors);
55 50
       throw new RegistrationFailure(errors);
56 51
     }
57 52
   }
58 53
 
59
-  private void sendRegistrationAttemptMessage(final Date completionDate, final TrackingId tid, final VoyageNumber voyageNumber, final HandlingEvent.Type type, final UnLocode ul) {
60
-    jmsOperations.send(handlingEventQueue, new MessageCreator() {
61
-      public Message createMessage(Session session) throws JMSException {
62
-        final HandlingEventRegistrationAttempt attempt = new HandlingEventRegistrationAttempt(new Date(), completionDate, tid, voyageNumber, type, ul);
63
-        return session.createObjectMessage(attempt);
64
-      }
65
-    });
66
-    if (logger.isDebugEnabled()) {
67
-      logger.debug("Incoming handling event registration attempt added to queue");
68
-    }
69
-  }
70
-
71 54
   private UnLocode parseUnLocode(final String unlocode, final List<String> errors) {
72 55
     try {
73 56
       return new UnLocode(unlocode);
@@ -119,11 +102,7 @@ public class HandlingEventServiceEndpointImpl implements HandlingEventServiceEnd
119 102
     }
120 103
   }
121 104
 
122
-  public void setJmsOperations(final JmsOperations jmsOperations) {
123
-    this.jmsOperations = jmsOperations;
124
-  }
125
-
126
-  public void setHandlingEventQueue(final Queue handlingEventQueue) {
127
-    this.handlingEventQueue = handlingEventQueue;
105
+  public void setSystemEvents(SystemEvents systemEvents) {
106
+    this.systemEvents = systemEvents;
128 107
   }
129 108
 }

+ 14
- 0
dddsample/src/main/java/se/citerus/dddsample/infrastructure/messaging/jms/JmsSystemEventsImpl.java Прегледај датотеку

@@ -23,6 +23,7 @@ public final class JmsSystemEventsImpl implements SystemEvents {
23 23
   private Destination misdirectedCargoTopic;
24 24
   private Destination deliveredCargoTopic;
25 25
   private Destination rejectedRegistrationAttemptsQueue;
26
+  private Destination handlingEventQueue;
26 27
 
27 28
   @Override
28 29
   public void cargoWasHandled(final HandlingEvent event) {
@@ -62,6 +63,15 @@ public final class JmsSystemEventsImpl implements SystemEvents {
62 63
     });
63 64
   }
64 65
 
66
+  @Override
67
+  public void receivedHandlingEventRegistrationAttempt(final HandlingEventRegistrationAttempt attempt) {
68
+    jmsOperations.send(handlingEventQueue, new MessageCreator() {
69
+      public Message createMessage(Session session) throws JMSException {
70
+        return session.createObjectMessage(attempt);
71
+      }
72
+    });
73
+  }
74
+
65 75
   public void setJmsOperations(final JmsOperations jmsOperations) {
66 76
     this.jmsOperations = jmsOperations;
67 77
   }
@@ -81,4 +91,8 @@ public final class JmsSystemEventsImpl implements SystemEvents {
81 91
   public void setRejectedRegistrationAttemptsQueue(Destination rejectedRegistrationAttemptsQueue) {
82 92
     this.rejectedRegistrationAttemptsQueue = rejectedRegistrationAttemptsQueue;
83 93
   }
94
+
95
+  public void setHandlingEventQueue(Destination handlingEventQueue) {
96
+    this.handlingEventQueue = handlingEventQueue;
97
+  }
84 98
 }

+ 1
- 0
dddsample/src/main/resources/context-messaging-jms.xml Прегледај датотеку

@@ -37,6 +37,7 @@
37 37
     <property name="misdirectedCargoTopic" ref="misdirectedCargoTopic"/>
38 38
     <property name="deliveredCargoTopic" ref="deliveredCargoTopic"/>
39 39
     <property name="rejectedRegistrationAttemptsQueue" ref="rejectedRegistrationAttemptsQueue"/>
40
+    <property name="handlingEventQueue" ref="handlingEventRegistrationAttemptQueue"/>
40 41
   </bean>
41 42
 
42 43
   <bean id="cargoHandledConsumer" class="se.citerus.dddsample.infrastructure.messaging.jms.CargoHandledConsumer">

+ 1
- 2
dddsample/src/main/resources/context-remote.xml Прегледај датотеку

@@ -22,8 +22,7 @@
22 22
   </wss:bindings>
23 23
 
24 24
   <bean id="handlingEventServiceEndpoint" class="se.citerus.dddsample.application.ws.HandlingEventServiceEndpointImpl">
25
-    <property name="jmsOperations" ref="jmsOperations"/>
26
-    <property name="handlingEventQueue" ref="handlingEventRegistrationAttemptQueue"/>
25
+    <property name="systemEvents" ref="systemEvents"/>
27 26
   </bean>
28 27
 
29 28
   <!-- RMI exposed booking service facade -->

+ 9
- 14
dddsample/src/test/java/se/citerus/dddsample/application/ws/HandlinEventServiceEndpointTest.java Прегледај датотеку

@@ -2,10 +2,9 @@ package se.citerus.dddsample.application.ws;
2 2
 
3 3
 import junit.framework.TestCase;
4 4
 import static org.easymock.EasyMock.*;
5
-import org.springframework.jms.core.JmsOperations;
6
-import org.springframework.jms.core.MessageCreator;
5
+import se.citerus.dddsample.application.HandlingEventRegistrationAttempt;
6
+import se.citerus.dddsample.application.SystemEvents;
7 7
 
8
-import javax.jms.Queue;
9 8
 import java.text.SimpleDateFormat;
10 9
 import java.util.Date;
11 10
 
@@ -14,29 +13,25 @@ public class HandlinEventServiceEndpointTest extends TestCase {
14 13
   private HandlingEventServiceEndpointImpl endpoint;
15 14
   private SimpleDateFormat sdf = new SimpleDateFormat(HandlingEventServiceEndpointImpl.ISO_8601_FORMAT);
16 15
   private Date date = new Date(100);
17
-  private JmsOperations jmsOperations;
18
-  private Queue queue;
16
+  private SystemEvents systemEvents;
19 17
 
20 18
   protected void setUp() throws Exception {
21 19
     endpoint = new HandlingEventServiceEndpointImpl();
22 20
 
23
-    jmsOperations = createMock(JmsOperations.class);
24
-    queue = createMock(Queue.class);
25
-
26
-    endpoint.setJmsOperations(jmsOperations);
27
-    endpoint.setHandlingEventQueue(queue);
21
+    systemEvents = createMock(SystemEvents.class);
22
+    endpoint.setSystemEvents(systemEvents);
28 23
   }
29 24
 
30 25
   public void testRegisterValidEvent() throws Exception {
31
-    jmsOperations.send(eq(queue), isA(MessageCreator.class));
32
-    replay(jmsOperations, queue);
26
+    systemEvents.receivedHandlingEventRegistrationAttempt(isA(HandlingEventRegistrationAttempt.class));
27
+    replay(systemEvents);
33 28
 
34 29
     // Tested call
35 30
     endpoint.register(sdf.format(date), "FOO", "CAR_456", "CNHKG", "LOAD");
36 31
   }
37 32
 
38 33
   public void testRegisterInalidEvent() throws Exception {
39
-    replay(jmsOperations, queue);
34
+    replay(systemEvents);
40 35
 
41 36
     // Tested call
42 37
     try {
@@ -48,6 +43,6 @@ public class HandlinEventServiceEndpointTest extends TestCase {
48 43
   }
49 44
 
50 45
   protected void tearDown() throws Exception {
51
-    verify(jmsOperations, queue);
46
+    verify(systemEvents);
52 47
   }
53 48
 }

+ 2
- 0
dddsample/src/test/java/se/citerus/dddsample/scenario/CargoHandlingScenarioTest.java Прегледај датотеку

@@ -151,6 +151,8 @@ public class CargoHandlingScenarioTest extends TestCase {
151 151
       public void cargoHasArrived(Cargo cargo) {}
152 152
       @Override
153 153
       public void rejectHandlingEventRegistrationAttempt(HandlingEventRegistrationAttempt attempt, CannotCreateHandlingEventException problem) {}
154
+      @Override
155
+      public void receivedHandlingEventRegistrationAttempt(HandlingEventRegistrationAttempt attempt) {}
154 156
     };
155 157
 
156 158
     // Stub