camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cmuel...@apache.org
Subject svn commit: r1139815 - in /camel/trunk/components/camel-smpp/src: main/java/org/apache/camel/component/smpp/MessageReceiverListenerImpl.java test/java/org/apache/camel/component/smpp/MessageReceiverListenerImplTest.java
Date Sun, 26 Jun 2011 15:32:00 GMT
Author: cmueller
Date: Sun Jun 26 15:32:00 2011
New Revision: 1139815

URL: http://svn.apache.org/viewvc?rev=1139815&view=rev
Log:
CAMEL-4136: Camel-smpp should be able to return ProcessRequestException to the SMSC instead
of catching all exceptions

Modified:
    camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/MessageReceiverListenerImpl.java
    camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/MessageReceiverListenerImplTest.java

Modified: camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/MessageReceiverListenerImpl.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/MessageReceiverListenerImpl.java?rev=1139815&r1=1139814&r2=1139815&view=diff
==============================================================================
--- camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/MessageReceiverListenerImpl.java
(original)
+++ camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/MessageReceiverListenerImpl.java
Sun Jun 26 15:32:00 2011
@@ -61,7 +61,7 @@ public class MessageReceiverListenerImpl
         }
     }
 
-    public void onAcceptDeliverSm(DeliverSm deliverSm) {
+    public void onAcceptDeliverSm(DeliverSm deliverSm) throws ProcessRequestException {
         LOG.debug("Received a deliverSm {}", deliverSm);
 
         try {
@@ -72,6 +72,9 @@ public class MessageReceiverListenerImpl
             LOG.trace("processed the new smpp exchange");
         } catch (Exception e) {
             exceptionHandler.handleException(e);
+            if (e instanceof ProcessRequestException) {
+                throw (ProcessRequestException) e;
+            }
         }
     }
 
@@ -88,6 +91,9 @@ public class MessageReceiverListenerImpl
             LOG.trace("processed the new smpp exchange");
         } catch (Exception e) {
             exceptionHandler.handleException(e);
+            if (e instanceof ProcessRequestException) {
+                throw (ProcessRequestException) e;
+            }
             throw new ProcessRequestException(e.getMessage(), 255, e);
         }
 

Modified: camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/MessageReceiverListenerImplTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/MessageReceiverListenerImplTest.java?rev=1139815&r1=1139814&r2=1139815&view=diff
==============================================================================
--- camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/MessageReceiverListenerImplTest.java
(original)
+++ camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/MessageReceiverListenerImplTest.java
Sun Jun 26 15:32:00 2011
@@ -38,6 +38,7 @@ import static org.easymock.classextensio
 import static org.easymock.classextension.EasyMock.replay;
 import static org.easymock.classextension.EasyMock.verify;
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertSame;
 import static org.junit.Assert.fail;
 
@@ -70,13 +71,10 @@ public class MessageReceiverListenerImpl
     public void onAcceptAlertNotificationSuccess() throws Exception {
         AlertNotification alertNotification = createMock(AlertNotification.class);
         Exchange exchange = createMock(Exchange.class);
-        Exception exception = new Exception("forced exception for test");
         
         expect(endpoint.createOnAcceptAlertNotificationExchange(alertNotification))
             .andReturn(exchange);
         processor.process(exchange);
-        expectLastCall().andThrow(exception);
-        exceptionHandler.handleException(exception);
         
         replay(endpoint, processor, exceptionHandler, alertNotification, exchange);
         
@@ -86,13 +84,16 @@ public class MessageReceiverListenerImpl
     }
     
     @Test
-    public void onAcceptAlertNotificationFailure() throws Exception {
+    public void onAcceptAlertNotificationException() throws Exception {
         AlertNotification alertNotification = createMock(AlertNotification.class);
         Exchange exchange = createMock(Exchange.class);
+        Exception exception = new Exception("forced exception for test");
         
         expect(endpoint.createOnAcceptAlertNotificationExchange(alertNotification))
             .andReturn(exchange);
         processor.process(exchange);
+        expectLastCall().andThrow(exception);
+        exceptionHandler.handleException(exception);
         
         replay(endpoint, processor, exceptionHandler, alertNotification, exchange);
         
@@ -121,7 +122,7 @@ public class MessageReceiverListenerImpl
     }
     
     @Test
-    public void onAcceptDeliverSmFailure() throws Exception {
+    public void onAcceptDeliverSmException() throws Exception {
         DeliverSm deliverSm = createMock(DeliverSm.class);
         Exchange exchange = createMock(Exchange.class);
         
@@ -137,6 +138,32 @@ public class MessageReceiverListenerImpl
     }
     
     @Test
+    public void onAcceptDeliverSmProcessRequestException() throws Exception {
+        DeliverSm deliverSm = createMock(DeliverSm.class);
+        Exchange exchange = createMock(Exchange.class);
+        ProcessRequestException exception = new ProcessRequestException("forced exception
for test", 100);
+        
+        expect(endpoint.createOnAcceptDeliverSmExchange(deliverSm))
+            .andReturn(exchange);
+        processor.process(exchange);
+        expectLastCall().andThrow(exception);
+        exceptionHandler.handleException(exception);
+        
+        replay(endpoint, processor, exceptionHandler, deliverSm, exchange);
+        
+        try {
+            listener.onAcceptDeliverSm(deliverSm);
+            fail("ProcessRequestException expected");
+        } catch (ProcessRequestException e) {
+            assertEquals(100, e.getErrorCode());
+            assertEquals("forced exception for test", e.getMessage());
+            assertNull(e.getCause());
+        }
+        
+        verify(endpoint, processor, exceptionHandler, deliverSm, exchange);
+    }
+    
+    @Test
     public void onAcceptDataSmSuccess() throws Exception {
         SMPPSession session = createMock(SMPPSession.class);
         DataSm dataSm = createMock(DataSm.class);
@@ -160,7 +187,7 @@ public class MessageReceiverListenerImpl
     }
     
     @Test
-    public void onAcceptDataSmFailure() throws Exception {
+    public void onAcceptDataSmException() throws Exception {
         SMPPSession session = createMock(SMPPSession.class);
         DataSm dataSm = createMock(DataSm.class);
         Exchange exchange = createMock(Exchange.class);
@@ -185,4 +212,31 @@ public class MessageReceiverListenerImpl
         
         verify(endpoint, processor, exceptionHandler, session, dataSm, exchange);
     }
+    
+    @Test
+    public void onAcceptDataSmProcessRequestException() throws Exception {
+        SMPPSession session = createMock(SMPPSession.class);
+        DataSm dataSm = createMock(DataSm.class);
+        Exchange exchange = createMock(Exchange.class);
+        ProcessRequestException exception = new ProcessRequestException("forced exception
for test", 100);
+        
+        expect(endpoint.createOnAcceptDataSm(dataSm, "1"))
+            .andReturn(exchange);
+        processor.process(exchange);
+        expectLastCall().andThrow(exception);
+        exceptionHandler.handleException(exception);
+        
+        replay(endpoint, processor, exceptionHandler, session, dataSm, exchange);
+        
+        try {
+            listener.onAcceptDataSm(dataSm, session);
+            fail("ProcessRequestException expected");
+        } catch (ProcessRequestException e) {
+            assertEquals(100, e.getErrorCode());
+            assertEquals("forced exception for test", e.getMessage());
+            assertNull(e.getCause());
+        }
+        
+        verify(endpoint, processor, exceptionHandler, session, dataSm, exchange);
+    }
 }
\ No newline at end of file



Mime
View raw message