servicemix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ge...@apache.org
Subject svn commit: r1134568 - in /servicemix/components/trunk/bindings/servicemix-http/src: main/java/org/apache/servicemix/http/endpoints/ main/java/org/apache/servicemix/http/exception/ test/java/org/apache/servicemix/http/endpoints/ test/java/org/apache/se...
Date Sat, 11 Jun 2011 10:53:01 GMT
Author: gertv
Date: Sat Jun 11 10:53:00 2011
New Revision: 1134568

URL: http://svn.apache.org/viewvc?rev=1134568&view=rev
Log:
SMXCOMP-881: Introducing exception types to better distinguish between the time-out and the
late response that follows it

Added:
    servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/exception/
    servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/exception/HttpTimeoutException.java
    servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/exception/LateResponseException.java
    servicemix/components/trunk/bindings/servicemix-http/src/test/java/org/apache/servicemix/http/exception/
    servicemix/components/trunk/bindings/servicemix-http/src/test/java/org/apache/servicemix/http/exception/HttpTimeoutExceptionTest.java
    servicemix/components/trunk/bindings/servicemix-http/src/test/java/org/apache/servicemix/http/exception/LateResponseExceptionTest.java
Modified:
    servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/HttpConsumerEndpoint.java
    servicemix/components/trunk/bindings/servicemix-http/src/test/java/org/apache/servicemix/http/endpoints/HttpConsumerLateResponseHandlingTest.java

Modified: servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/HttpConsumerEndpoint.java
URL: http://svn.apache.org/viewvc/servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/HttpConsumerEndpoint.java?rev=1134568&r1=1134567&r2=1134568&view=diff
==============================================================================
--- servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/HttpConsumerEndpoint.java
(original)
+++ servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/HttpConsumerEndpoint.java
Sat Jun 11 10:53:00 2011
@@ -38,6 +38,8 @@ import javax.xml.transform.TransformerEx
 import javax.xml.transform.dom.DOMSource;
 import javax.xml.transform.stream.StreamResult;
 
+import org.apache.servicemix.http.exception.HttpTimeoutException;
+import org.apache.servicemix.http.exception.LateResponseException;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
@@ -291,7 +293,7 @@ public class HttpConsumerEndpoint extend
         synchronized (mutex) {
             final Continuation continuation = continuations.get(id);
             if (continuation != null && continuation.isPending()) {
-                logger.debug("Resuming continuation for exchange: {}", exchange.getExchangeId());
+                logger.debug("Resuming continuation for exchange: {}", id);
 
                 // in case of the JMS/JCA flow, you might have a different instance of the
message exchange here
                 continuation.setObject(exchange);
@@ -318,7 +320,6 @@ public class HttpConsumerEndpoint extend
      *   (either because the exchange was received or because the request timed out)
      */
     public void process(HttpServletRequest request, HttpServletResponse response) throws
Exception {
-
         MessageExchange exchange = null;
 
         try {
@@ -363,7 +364,7 @@ public class HttpConsumerEndpoint extend
                     // Right after this if-block, we will try suspending the continuation
                     // If a SelectConnector is being used, the call to suspend will throw
a RetryRequest
                     // This will free the thread - this method will be invoked again when
the continuation gets resumed
-                    logger.debug("Suspending continuation for exchange: {}", exchange.getExchangeId());
+                    logger.debug("Suspending continuation for exchange: {}", id);
                 } else {
                     logger.debug("Resuming HTTP request: {}", request);
                 }
@@ -374,9 +375,9 @@ public class HttpConsumerEndpoint extend
                 // Cleaning up the stored objects for this continuation now
                 exchange = doEndContinuation(continuation);
 
-                // Timeout if SelectConnector is not used
+                // Throw exception when HTTP time-out has occurred
                 if (istimeout) {
-                    throw new Exception("HTTP request has timed out for exchange: " + exchange.getExchangeId());
+                    throw new HttpTimeoutException(exchange);
                 }
             }
 
@@ -397,7 +398,7 @@ public class HttpConsumerEndpoint extend
         if (exchange.getStatus() == ExchangeStatus.ERROR) {
             Exception e = exchange.getError();
             if (e == null) {
-                e = new Exception("Unkown error (exchange aborted ?)");
+                e = new Exception("Unknown error (exchange aborted ?)");
             }
             throw e;
         } else if (exchange.getStatus() == ExchangeStatus.ACTIVE) {
@@ -429,9 +430,11 @@ public class HttpConsumerEndpoint extend
         // if the exchange is no longer active by now, something else probably went wrong
in the meanwhile
         if (exchange.getStatus() == ExchangeStatus.ACTIVE) {
             if (lateResponseStrategy == LateResponseStrategy.error) {
-                fail(exchange, new Exception("HTTP request has timed out for exchange: {}
" + exchange.getExchangeId()));
+                // ends the exchange in ERROR
+                fail(exchange, new LateResponseException(exchange));
             } else {
-                logger.warn("HTTP request has timed out for exchange: {}", exchange.getExchangeId());
+                // let's log the exception message text, but end the exchange with DONE
+                logger.warn(LateResponseException.createMessage(exchange));
                 done(exchange);
             }
         }

Added: servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/exception/HttpTimeoutException.java
URL: http://svn.apache.org/viewvc/servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/exception/HttpTimeoutException.java?rev=1134568&view=auto
==============================================================================
--- servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/exception/HttpTimeoutException.java
(added)
+++ servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/exception/HttpTimeoutException.java
Sat Jun 11 10:53:00 2011
@@ -0,0 +1,38 @@
+/*
+ * 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.servicemix.http.exception;
+
+import javax.jbi.messaging.MessageExchange;
+
+/**
+ * Exception thrown when an HTTP connection has timed out
+ */
+public class HttpTimeoutException extends Exception {
+
+    public HttpTimeoutException(MessageExchange exchange) {
+        super(createMessage(exchange));
+    }
+
+    private static String createMessage(MessageExchange exchange) {
+        if (exchange == null) {
+            return "HTTP request has timed out";
+        } else {
+            return String.format("HTTP request has timed out for exchange: %s", exchange.getExchangeId());
+        }
+    }
+
+}

Added: servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/exception/LateResponseException.java
URL: http://svn.apache.org/viewvc/servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/exception/LateResponseException.java?rev=1134568&view=auto
==============================================================================
--- servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/exception/LateResponseException.java
(added)
+++ servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/exception/LateResponseException.java
Sat Jun 11 10:53:00 2011
@@ -0,0 +1,42 @@
+/*
+ * 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.servicemix.http.exception;
+
+import javax.jbi.messaging.MessageExchange;
+
+/**
+ * Exception to indicate that a late response has been received from the ESB, i.e. the ESB
response was received
+ * after the HTTP connection has timed out so we were unable to send back the response to
the client.
+ */
+public class LateResponseException extends Exception {
+
+    public LateResponseException(MessageExchange exchange) {
+        super(createMessage(exchange));
+    }
+
+    /**
+     * Helper method to create the late response error message
+     *
+     * @param exchange the exchange we received a late response for
+     * @return the error message
+     */
+    public static String createMessage(MessageExchange exchange) {
+        return String.format("Late response message for %s - received after HTTP connection
has timed out",
+                             exchange.getExchangeId());
+    }
+
+}

Modified: servicemix/components/trunk/bindings/servicemix-http/src/test/java/org/apache/servicemix/http/endpoints/HttpConsumerLateResponseHandlingTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/trunk/bindings/servicemix-http/src/test/java/org/apache/servicemix/http/endpoints/HttpConsumerLateResponseHandlingTest.java?rev=1134568&r1=1134567&r2=1134568&view=diff
==============================================================================
--- servicemix/components/trunk/bindings/servicemix-http/src/test/java/org/apache/servicemix/http/endpoints/HttpConsumerLateResponseHandlingTest.java
(original)
+++ servicemix/components/trunk/bindings/servicemix-http/src/test/java/org/apache/servicemix/http/endpoints/HttpConsumerLateResponseHandlingTest.java
Sat Jun 11 10:53:00 2011
@@ -24,6 +24,7 @@ import org.apache.servicemix.components.
 import org.apache.servicemix.http.HttpComponent;
 import org.apache.servicemix.http.HttpEndpointType;
 import org.apache.servicemix.http.PortFinder;
+import org.apache.servicemix.http.exception.LateResponseException;
 import org.apache.servicemix.jbi.container.JBIContainer;
 import org.apache.servicemix.jbi.helper.MessageUtil;
 
@@ -63,7 +64,8 @@ public class HttpConsumerLateResponseHan
     public void testInOutWithStrategyError() throws Exception {
         MessageExchange exchange = doTestInOutWithStrategy(HttpConsumerEndpoint.LateResponseStrategy.error);
         assertEquals("Exchange should have ended in ERROR", ExchangeStatus.ERROR, exchange.getStatus());
-        assertNotNull(exchange.getError());
+        assertTrue("Expecting a LateResponseException, but was " + exchange.getError().getClass().getName(),
+                   exchange.getError() instanceof LateResponseException);
     }
 
     public void testInOutWithStrategyWarning() throws Exception {

Added: servicemix/components/trunk/bindings/servicemix-http/src/test/java/org/apache/servicemix/http/exception/HttpTimeoutExceptionTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/trunk/bindings/servicemix-http/src/test/java/org/apache/servicemix/http/exception/HttpTimeoutExceptionTest.java?rev=1134568&view=auto
==============================================================================
--- servicemix/components/trunk/bindings/servicemix-http/src/test/java/org/apache/servicemix/http/exception/HttpTimeoutExceptionTest.java
(added)
+++ servicemix/components/trunk/bindings/servicemix-http/src/test/java/org/apache/servicemix/http/exception/HttpTimeoutExceptionTest.java
Sat Jun 11 10:53:00 2011
@@ -0,0 +1,44 @@
+/*
+ * 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.servicemix.http.exception;
+
+import junit.framework.TestCase;
+import org.apache.servicemix.tck.mock.MockExchangeFactory;
+
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.MessagingException;
+
+/**
+ * Test cases for {@link HttpTimeoutException}
+ */
+public class HttpTimeoutExceptionTest extends TestCase {
+
+    public void testMessageContainsExchangeId() throws MessagingException {
+        MockExchangeFactory factory = new MockExchangeFactory();
+        MessageExchange exchange = factory.createInOnlyExchange();
+
+        HttpTimeoutException exception = new HttpTimeoutException(exchange);
+        assertTrue("Exception message refers to the exchange id",
+                   exception.getMessage().contains(exchange.getExchangeId()));
+    }
+
+    public void testMessageWithNullExchange() throws MessagingException {
+        HttpTimeoutException exception = new HttpTimeoutException(null);
+        assertNotNull("We still expect some kind of message", exception.getMessage());
+    }
+
+}

Added: servicemix/components/trunk/bindings/servicemix-http/src/test/java/org/apache/servicemix/http/exception/LateResponseExceptionTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/trunk/bindings/servicemix-http/src/test/java/org/apache/servicemix/http/exception/LateResponseExceptionTest.java?rev=1134568&view=auto
==============================================================================
--- servicemix/components/trunk/bindings/servicemix-http/src/test/java/org/apache/servicemix/http/exception/LateResponseExceptionTest.java
(added)
+++ servicemix/components/trunk/bindings/servicemix-http/src/test/java/org/apache/servicemix/http/exception/LateResponseExceptionTest.java
Sat Jun 11 10:53:00 2011
@@ -0,0 +1,39 @@
+/*
+ * 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.servicemix.http.exception;
+
+import junit.framework.TestCase;
+import org.apache.servicemix.tck.mock.MockExchangeFactory;
+
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.MessagingException;
+
+/**
+ * Test cases for {@link org.apache.servicemix.http.exception.HttpTimeoutException}
+ */
+public class LateResponseExceptionTest extends TestCase {
+
+    public void testMessageContainsExchangeId() throws MessagingException {
+        MockExchangeFactory factory = new MockExchangeFactory();
+        MessageExchange exchange = factory.createInOnlyExchange();
+
+        LateResponseException exception = new LateResponseException(exchange);
+        assertTrue("Exception message refers to the exchange id",
+                   exception.getMessage().contains(exchange.getExchangeId()));
+    }
+
+}



Mime
View raw message