You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by dk...@apache.org on 2009/11/16 23:03:54 UTC

svn commit: r880991 - in /cxf/trunk: rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/policy/HTTPClientPolicyTest.java

Author: dkulp
Date: Mon Nov 16 22:03:54 2009
New Revision: 880991

URL: http://svn.apache.org/viewvc?rev=880991&view=rev
Log:
[CXF-2537] Enhance the error messages on the client side for http
conduits.

Heavily modified patch from Cyrille Le Clerc applied.

Modified:
    cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java
    cxf/trunk/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/policy/HTTPClientPolicyTest.java

Modified: cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java?rev=880991&r1=880990&r2=880991&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java (original)
+++ cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java Mon Nov 16 22:03:54 2009
@@ -1980,13 +1980,32 @@
             }
             try {
                 handleResponse();
+            } catch (IOException e) {
+                throw mapException(e.getClass().getSimpleName() 
+                                   + " invoking " + connection.getURL(), e,
+                                   IOException.class);
+            } catch (RuntimeException e) {
+                throw mapException(e.getClass().getSimpleName() 
+                                   + " invoking " + connection.getURL(), e,
+                                   RuntimeException.class);
             } finally {
                 if (cachingForRetransmission && cachedStream != null) {
                     cachedStream.close();
                 }
             }
         }
-        
+        private <T extends Exception> T mapException(String msg, T ex, Class<T> cls) {
+            T ex2 = ex;
+            try {
+                ex2 = cls.cast(ex.getClass().getConstructor(String.class).newInstance(msg));
+                ex2.initCause(ex);
+            } catch (Throwable e) {
+                ex2 = ex;
+            }
+            
+            
+            return ex2;
+        }
         
         /**
          * This procedure handles all retransmits, if any.
@@ -2106,7 +2125,8 @@
         
             
             if (responseCode == HttpURLConnection.HTTP_NOT_FOUND) {
-                throw new IOException(connection.getResponseMessage());
+                throw new IOException("HTTP response '" + responseCode + ": " 
+                        + connection.getResponseMessage() + "'");
             }
 
             

Modified: cxf/trunk/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/policy/HTTPClientPolicyTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/policy/HTTPClientPolicyTest.java?rev=880991&r1=880990&r2=880991&view=diff
==============================================================================
--- cxf/trunk/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/policy/HTTPClientPolicyTest.java (original)
+++ cxf/trunk/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/policy/HTTPClientPolicyTest.java Mon Nov 16 22:03:54 2009
@@ -149,6 +149,7 @@
             greeter.greetMe("cxf");
             fail("Didn't get the exception");
         } catch (Exception ex) {
+            ex.printStackTrace();
             assertTrue(ex.getCause().getClass().getName(), ex.getCause() instanceof SocketTimeoutException);
         }