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/05/19 21:39:10 UTC

svn commit: r776429 - in /cxf/trunk: api/src/main/java/org/apache/cxf/endpoint/ rt/core/src/main/java/org/apache/cxf/endpoint/ rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/ rt/transports/http/src/main/java/org/apache/cxf/transport/http/ rt/tran...

Author: dkulp
Date: Tue May 19 19:39:10 2009
New Revision: 776429

URL: http://svn.apache.org/viewvc?rev=776429&view=rev
Log:
Fix problems with async calls hanging if there is a read/connection
timeout.
Also allow passing a HTTPClientPolicy object in via request context to
set timeouts and such

Modified:
    cxf/trunk/api/src/main/java/org/apache/cxf/endpoint/ClientCallback.java
    cxf/trunk/rt/core/src/main/java/org/apache/cxf/endpoint/ClientImpl.java
    cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JaxWsClientProxy.java
    cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java
    cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/policy/PolicyUtils.java
    cxf/trunk/systests/src/test/java/org/apache/cxf/systest/dispatch/DispatchClientServerTest.java
    cxf/trunk/systests/src/test/java/org/apache/cxf/systest/interceptor/InterceptorFaultTest.java
    cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/JaxWsClientThreadTest.java
    cxf/trunk/systests/src/test/java/org/apache/cxf/systest/schema_validation/ValidationClientServerTest.java
    cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/policy/HTTPClientPolicyTest.java
    cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/policy/http_client_greeter.wsdl

Modified: cxf/trunk/api/src/main/java/org/apache/cxf/endpoint/ClientCallback.java
URL: http://svn.apache.org/viewvc/cxf/trunk/api/src/main/java/org/apache/cxf/endpoint/ClientCallback.java?rev=776429&r1=776428&r2=776429&view=diff
==============================================================================
--- cxf/trunk/api/src/main/java/org/apache/cxf/endpoint/ClientCallback.java (original)
+++ cxf/trunk/api/src/main/java/org/apache/cxf/endpoint/ClientCallback.java Tue May 19 19:39:10 2009
@@ -141,6 +141,9 @@
         if (cancelled) {
             throw new InterruptedException("Operation Cancelled");
         }
+        if (!done) {
+            throw new TimeoutException("Timeout Exceeded");
+        }
         if (exception != null) {
             throw new ExecutionException(exception);
         }

Modified: cxf/trunk/rt/core/src/main/java/org/apache/cxf/endpoint/ClientImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/endpoint/ClientImpl.java?rev=776429&r1=776428&r2=776429&view=diff
==============================================================================
--- cxf/trunk/rt/core/src/main/java/org/apache/cxf/endpoint/ClientImpl.java (original)
+++ cxf/trunk/rt/core/src/main/java/org/apache/cxf/endpoint/ClientImpl.java Tue May 19 19:39:10 2009
@@ -637,6 +637,8 @@
                 chain.doInterceptStartingAfter(message, startingAfterInterceptorID);
             } else if (startingInterceptorID != null) {
                 chain.doInterceptStartingAt(message, startingInterceptorID);
+            } else if (message.getContent(Exception.class) != null) {
+                chain.getFaultObserver().onMessage(message);
             } else {
                 chain.doIntercept(message);
             }

Modified: cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JaxWsClientProxy.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JaxWsClientProxy.java?rev=776429&r1=776428&r2=776429&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JaxWsClientProxy.java (original)
+++ cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JaxWsClientProxy.java Tue May 19 19:39:10 2009
@@ -52,6 +52,7 @@
 import org.apache.cxf.endpoint.Endpoint;
 import org.apache.cxf.frontend.MethodDispatcher;
 import org.apache.cxf.helpers.CastUtils;
+import org.apache.cxf.interceptor.Fault;
 import org.apache.cxf.jaxws.context.WrappedMessageContext;
 import org.apache.cxf.jaxws.support.JaxWsEndpointImpl;
 import org.apache.cxf.service.model.BindingOperationInfo;
@@ -137,9 +138,12 @@
                 if (soapFault == null) {
                     throw new WebServiceException(ex);
                 }
-                
                 SOAPFaultException  exception = new SOAPFaultException(soapFault);
-                exception.initCause(ex);
+                if (ex instanceof Fault && ex.getCause() != null) {
+                    exception.initCause(ex.getCause());
+                } else {
+                    exception.initCause(ex);
+                }
                 throw exception;                
             } else {
                 throw new WebServiceException(ex);

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=776429&r1=776428&r2=776429&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 Tue May 19 19:39:10 2009
@@ -492,18 +492,19 @@
         // The need to cache the request is off by default
         boolean needToCacheRequest = false;
         
+        HTTPClientPolicy csPolicy = getClient(message);
         HttpURLConnection connection = getConnectionFactory(currentURL)
-            .createConnection(getProxy(clientSidePolicy), currentURL);
+            .createConnection(getProxy(csPolicy), currentURL);
         connection.setDoOutput(true);  
         
         //TODO using Message context to decided HTTP send properties 
              
-        long timeout = clientSidePolicy.getConnectionTimeout();
+        long timeout = csPolicy.getConnectionTimeout();
         if (timeout > Integer.MAX_VALUE) {
             timeout = Integer.MAX_VALUE;
         }
         connection.setConnectTimeout((int)timeout);
-        timeout = clientSidePolicy.getReceiveTimeout();
+        timeout = csPolicy.getReceiveTimeout();
         if (timeout > Integer.MAX_VALUE) {
             timeout = Integer.MAX_VALUE;
         }
@@ -540,7 +541,7 @@
             }
             message.put("AUTH_VALUE", auth);
         }
-        if (getClient().isAutoRedirect()) {
+        if (csPolicy.isAutoRedirect()) {
             needToCacheRequest = true;
             LOG.log(Level.FINE, "AutoRedirect is turned on.");
         }
@@ -548,12 +549,12 @@
         // if chunking is enabled
         // TODO : ensure chunking can be enabled for non-empty PUTs - if requested
         if (connection.getRequestMethod().equals("POST")
-            && getClient().isAllowChunking()) {
+            && csPolicy.isAllowChunking()) {
             //TODO: The chunking mode be configured or at least some
             // documented client constant.
             //use -1 and allow the URL connection to pick a default value
             isChunking = true;
-            chunkThreshold = getClient().getChunkingThreshold();
+            chunkThreshold = csPolicy.getChunkingThreshold();
             if (chunkThreshold <= 0) {
                 chunkThreshold = 0;
                 connection.setChunkedStreamingMode(-1);                    
@@ -1452,7 +1453,7 @@
     ) throws IOException {
         
         // If we are not redirecting by policy, then we don't.
-        if (!getClient().isAutoRedirect()) {
+        if (!getClient(message).isAutoRedirect()) {
             return connection;
         }
 
@@ -1638,11 +1639,12 @@
         // Disconnect the old, and in with the new.
         connection.disconnect();
         
-        connection = getConnectionFactory(newURL).createConnection(getProxy(clientSidePolicy), newURL);
+        HTTPClientPolicy cp = getClient(message);
+        connection = getConnectionFactory(newURL).createConnection(getProxy(cp), newURL);
         connection.setDoOutput(true);        
-        // TODO: using Message context to deceided HTTP send properties        
-        connection.setConnectTimeout((int)getClient().getConnectionTimeout());
-        connection.setReadTimeout((int)getClient().getReceiveTimeout());
+        // TODO: using Message context to deceided HTTP send properties
+        connection.setConnectTimeout((int)cp.getConnectionTimeout());
+        connection.setReadTimeout((int)cp.getReceiveTimeout());
         connection.setUseCaches(false);
         connection.setInstanceFollowRedirects(false);
 
@@ -1964,7 +1966,7 @@
 
                 HttpURLConnection oldcon = connection;
                 
-                HTTPClientPolicy policy = getClient();
+                HTTPClientPolicy policy = getClient(outMessage);
                 
                 // Default MaxRetransmits is -1 which means unlimited.
                 int maxRetransmits = (policy == null)
@@ -2016,8 +2018,11 @@
                     public void run() {
                         try {
                             handleResponseInternal();
-                        } catch (IOException e) {
-                            LOG.log(Level.WARNING, e.getMessage(), e);
+                        } catch (Exception e) {
+                            Message inMessage = new MessageImpl();
+                            inMessage.setExchange(outMessage.getExchange());
+                            inMessage.setContent(Exception.class, e);
+                            incomingObserver.onMessage(inMessage);
                         }
                     }
                 };

Modified: cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/policy/PolicyUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/policy/PolicyUtils.java?rev=776429&r1=776428&r2=776429&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/policy/PolicyUtils.java (original)
+++ cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/policy/PolicyUtils.java Tue May 19 19:39:10 2009
@@ -73,6 +73,10 @@
      * @throws PolicyException if no compatible HTTPClientPolicy can be determined
      */
     public static HTTPClientPolicy getClient(Message message, HTTPClientPolicy confPolicy) {
+        HTTPClientPolicy pol = message.get(HTTPClientPolicy.class);
+        if (pol != null) {
+            return intersect(pol, confPolicy);
+        }
         AssertionInfoMap amap =  message.get(AssertionInfoMap.class);
         if (null == amap) {
             return confPolicy;
@@ -200,7 +204,11 @@
      * @param client the client policy
      */
     public static void assertClientPolicy(Message message, HTTPClientPolicy client) {
-       
+        HTTPClientPolicy pol = message.get(HTTPClientPolicy.class);
+        if (pol != null) {
+            client = intersect(pol, client);
+        }
+
         AssertionInfoMap aim = message.get(AssertionInfoMap.class);
         if (null == aim) {
             return;

Modified: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/dispatch/DispatchClientServerTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/dispatch/DispatchClientServerTest.java?rev=776429&r1=776428&r2=776429&view=diff
==============================================================================
--- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/dispatch/DispatchClientServerTest.java (original)
+++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/dispatch/DispatchClientServerTest.java Tue May 19 19:39:10 2009
@@ -20,9 +20,12 @@
 package org.apache.cxf.systest.dispatch;
 
 import java.io.InputStream;
+import java.net.SocketTimeoutException;
 import java.net.URL;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
 
 import javax.xml.bind.JAXBContext;
 import javax.xml.namespace.QName;
@@ -51,10 +54,12 @@
 import org.apache.cxf.interceptor.LoggingOutInterceptor;
 import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
 import org.apache.cxf.testutil.common.AbstractBusTestServerBase;
+import org.apache.cxf.transports.http.configuration.HTTPClientPolicy;
 import org.apache.hello_world_soap_http.BadRecordLitFault;
 import org.apache.hello_world_soap_http.GreeterImpl;
 import org.apache.hello_world_soap_http.SOAPService;
 import org.apache.hello_world_soap_http.types.GreetMe;
+import org.apache.hello_world_soap_http.types.GreetMeLater;
 import org.apache.hello_world_soap_http.types.GreetMeResponse;
 import org.junit.BeforeClass;
 import org.junit.Test;
@@ -355,6 +360,32 @@
         } catch (ExecutionException ex) {
             //expected
         }
+        
+        GreetMeLater later = new GreetMeLater();
+        later.setRequestType(1000);
+        
+        HTTPClientPolicy pol = new HTTPClientPolicy();
+        pol.setReceiveTimeout(100);
+        disp.getRequestContext().put(HTTPClientPolicy.class.getName(), pol);
+        Response<Object> o = disp.invokeAsync(later);
+        try {
+            o.get(10, TimeUnit.SECONDS);
+            fail("Should have gotten a SocketTimeoutException");
+        } catch (ExecutionException ex) {
+            assertTrue(ex.getCause() instanceof SocketTimeoutException);
+        }
+
+        later.setRequestType(20000);
+        pol.setReceiveTimeout(20000);
+        disp.getRequestContext().put(HTTPClientPolicy.class.getName(), pol);
+        o = disp.invokeAsync(later);
+        try {
+            o.get(100, TimeUnit.MILLISECONDS);
+            fail("Should have gotten a SocketTimeoutException");
+        } catch (TimeoutException ex) {
+            //ignore - expected
+        }
+
     }
 
     @Test

Modified: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/interceptor/InterceptorFaultTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/interceptor/InterceptorFaultTest.java?rev=776429&r1=776428&r2=776429&view=diff
==============================================================================
--- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/interceptor/InterceptorFaultTest.java (original)
+++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/interceptor/InterceptorFaultTest.java Tue May 19 19:39:10 2009
@@ -44,7 +44,6 @@
 import org.apache.cxf.greeter_control.GreeterService;
 import org.apache.cxf.greeter_control.PingMeFault;
 import org.apache.cxf.greeter_control.types.FaultLocation;
-import org.apache.cxf.interceptor.Fault;
 import org.apache.cxf.phase.Phase;
 import org.apache.cxf.phase.PhaseComparator;
 import org.apache.cxf.phase.PhaseManager;
@@ -67,7 +66,6 @@
 
     private static final QName SOAP_FAULT_CODE = new QName("http://schemas.xmlsoap.org/soap/envelope/",
                                                            "Server");
-    private static final String FAULT_CODE = "COULD_NOT_SEND";
     private static final String FAULT_MESSAGE = "Could not send Message.";
     
     private static final String CONTROL_PORT_ADDRESS = 
@@ -261,10 +259,7 @@
             if (!expectOnewayFault) {
                 fail("Oneway operation unexpectedly failed.");
             }
-            Throwable cause = ex.getCause();
-            Fault f = (Fault)cause;
-            assertEquals(FAULT_CODE, f.getCode());
-            assertEquals(FAULT_MESSAGE, f.getMessage());
+            assertEquals(FAULT_MESSAGE, ex.getMessage());
         }
         
         try {

Modified: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/JaxWsClientThreadTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/JaxWsClientThreadTest.java?rev=776429&r1=776428&r2=776429&view=diff
==============================================================================
--- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/JaxWsClientThreadTest.java (original)
+++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/JaxWsClientThreadTest.java Tue May 19 19:39:10 2009
@@ -75,7 +75,7 @@
                         } catch (SOAPFaultException expected) {
                             //expected.getCause().printStackTrace();
                             MalformedURLException mue = (MalformedURLException)expected
-                                .getCause().getCause();
+                                .getCause();
                             if (mue == null || mue.getMessage() == null) {
                                 throw expected;
                             }

Modified: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/schema_validation/ValidationClientServerTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/schema_validation/ValidationClientServerTest.java?rev=776429&r1=776428&r2=776429&view=diff
==============================================================================
--- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/schema_validation/ValidationClientServerTest.java (original)
+++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/schema_validation/ValidationClientServerTest.java Tue May 19 19:39:10 2009
@@ -26,7 +26,6 @@
 import javax.xml.namespace.QName;
 import javax.xml.ws.WebServiceException;
 
-import org.apache.cxf.interceptor.Fault;
 import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
 import org.apache.schema_validation.SchemaValidation;
 import org.apache.schema_validation.SchemaValidationService;
@@ -77,9 +76,8 @@
             validation.setComplexStruct(complexStruct);
             fail("Set ComplexStruct hould have thrown ProtocolException");
         } catch (WebServiceException e) {
-            assertTrue(e.getCause() instanceof Fault);
             String expected = "'{\"http://apache.org/schema_validation/types\":elem2}' is expected.";
-            assertTrue(e.getCause().getMessage().indexOf(expected) != -1);
+            assertTrue(e.getMessage(), e.getMessage().indexOf(expected) != -1);
         }
 
         OccuringStruct occuringStruct = new OccuringStruct();
@@ -94,9 +92,8 @@
             validation.setOccuringStruct(occuringStruct);
             fail("Set OccuringStruct hould have thrown ProtocolException");
         } catch (WebServiceException e) {
-            assertTrue(e.getCause() instanceof Fault);
             String expected = "'{\"http://apache.org/schema_validation/types\":varFloat}' is expected.";
-            assertTrue(e.getCause().getMessage().indexOf(expected) != -1);
+            assertTrue(e.getMessage().indexOf(expected) != -1);
         }
 
         try {
@@ -107,10 +104,9 @@
             validation.getComplexStruct("Hello");
             fail("Get ComplexStruct should have thrown ProtocolException");
         } catch (WebServiceException e) {
-            assertTrue(e.getCause() instanceof Fault);
             String expected = "'{\"http://apache.org/schema_validation/types\":elem2}' is expected.";
-            assertTrue("Found message " + e.getCause().getMessage(), 
-                       e.getCause().getMessage().indexOf(expected) != -1);
+            assertTrue("Found message " + e.getMessage(), 
+                       e.getMessage().indexOf(expected) != -1);
         }
 
         try {
@@ -121,9 +117,8 @@
             validation.getOccuringStruct("World");
             fail("Get OccuringStruct should have thrown ProtocolException");
         } catch (WebServiceException e) {
-            assertTrue(e.getCause() instanceof Fault);
             String expected = "'{\"http://apache.org/schema_validation/types\":varFloat}' is expected.";
-            assertTrue(e.getCause().getMessage().indexOf(expected) != -1);
+            assertTrue(e.getMessage().indexOf(expected) != -1);
         }
     }
 

Modified: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/policy/HTTPClientPolicyTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/policy/HTTPClientPolicyTest.java?rev=776429&r1=776428&r2=776429&view=diff
==============================================================================
--- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/policy/HTTPClientPolicyTest.java (original)
+++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/policy/HTTPClientPolicyTest.java Tue May 19 19:39:10 2009
@@ -147,8 +147,9 @@
 
         try {
             greeter.greetMe("cxf");
+            fail("Didn't get the exception");
         } catch (Exception ex) {
-            assertTrue(ex.getCause() instanceof SocketTimeoutException);
+            assertTrue(ex.getCause().getClass().getName(), ex.getCause() instanceof SocketTimeoutException);
         }
      
         // pingMe - policy attached to binding operation fault should have no effect

Modified: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/policy/http_client_greeter.wsdl
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/policy/http_client_greeter.wsdl?rev=776429&r1=776428&r2=776429&view=diff
==============================================================================
--- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/policy/http_client_greeter.wsdl (original)
+++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/policy/http_client_greeter.wsdl Tue May 19 19:39:10 2009
@@ -143,7 +143,7 @@
         <wsdl:operation name="greetMe">
             <wsp:Policy xmlns:wsp="http://www.w3.org/2006/07/ws-policy">
                 <http-conf:client xmlns:http-conf="http://cxf.apache.org/transports/http/configuration"
-                    ReceiveTimeout="2000"/>
+                    ReceiveTimeout="1000"/>
             </wsp:Policy>
             <soap:operation soapAction="" style="document"/>
             <wsdl:input name="greetMeRequest">