cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From e..@apache.org
Subject svn commit: r996809 - in /cxf/trunk: api/src/main/java/org/apache/cxf/endpoint/ rt/transports/http/src/main/java/org/apache/cxf/transport/http/ systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/
Date Tue, 14 Sep 2010 09:55:34 GMT
Author: ema
Date: Tue Sep 14 09:55:34 2010
New Revision: 996809

URL: http://svn.apache.org/viewvc?rev=996809&view=rev
Log:
[CXF-2991]:Configure the http client connection and receive timeout via BindingProvider.getRequestContext

Modified:
    cxf/trunk/api/src/main/java/org/apache/cxf/endpoint/Client.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/Messages.properties
    cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/ClientServerTest.java

Modified: cxf/trunk/api/src/main/java/org/apache/cxf/endpoint/Client.java
URL: http://svn.apache.org/viewvc/cxf/trunk/api/src/main/java/org/apache/cxf/endpoint/Client.java?rev=996809&r1=996808&r2=996809&view=diff
==============================================================================
--- cxf/trunk/api/src/main/java/org/apache/cxf/endpoint/Client.java (original)
+++ cxf/trunk/api/src/main/java/org/apache/cxf/endpoint/Client.java Tue Sep 14 09:55:34 2010
@@ -34,6 +34,8 @@ public interface Client extends Intercep
     String REQUEST_CONTEXT = "RequestContext";
     String RESPONSE_CONTEXT = "ResponseContext";
     String KEEP_CONDUIT_ALIVE = "KeepConduitAlive";
+    String CONNECTION_TIMEOUT = "javax.xml.ws.client.connectionTimeout";
+    String RECEIVE_TIMEOUT = "javax.xml.ws.client.receiveTimeout";
 
     /**
      * Invokes an operation synchronously

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=996809&r1=996808&r2=996809&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 Sep 14 09:55:34 2010
@@ -57,6 +57,7 @@ import org.apache.cxf.configuration.jsse
 import org.apache.cxf.configuration.security.AuthorizationPolicy;
 import org.apache.cxf.configuration.security.CertificateConstraintsType;
 import org.apache.cxf.configuration.security.ProxyAuthorizationPolicy;
+import org.apache.cxf.endpoint.Client;
 import org.apache.cxf.helpers.CastUtils;
 import org.apache.cxf.helpers.HttpHeaderHelper;
 import org.apache.cxf.helpers.IOUtils;
@@ -503,8 +504,34 @@ public class HTTPConduit 
 
         HttpURLConnectionFactory f = getConnectionFactory(currentURL);
         HttpURLConnection connection = f.createConnection(getProxy(csPolicy), currentURL);
-        connection.setDoOutput(true);  
-             
+        connection.setDoOutput(true);       
+        Map<String, Object> ctx = CastUtils.cast((Map<?, ?>)message.get(Message.INVOCATION_CONTEXT));
+        if (ctx != null) {
+            Map<String, Object> reqCtx = CastUtils.cast((Map<?, ?>)ctx.get(Client.REQUEST_CONTEXT));
+            if (reqCtx != null && reqCtx.get(Client.RECEIVE_TIMEOUT) != null) {
+                Object obj = reqCtx.get(Client.RECEIVE_TIMEOUT);
+                try {
+                    csPolicy.setReceiveTimeout(Long.parseLong(obj.toString()));
+                } catch (NumberFormatException e) {
+                    LOG.log(Level.WARNING, "INVALID_TIMEOUT_FORMAT", new Object[] {
+                        Client.RECEIVE_TIMEOUT, obj.toString()
+                    });
+                }
+
+            }
+            if (reqCtx != null && reqCtx.get(Client.CONNECTION_TIMEOUT) != null)
{
+                Object obj = reqCtx.get(Client.CONNECTION_TIMEOUT);
+                try {
+                    csPolicy.setReceiveTimeout(Long.parseLong(obj.toString()));
+                } catch (NumberFormatException e) {
+                    LOG.log(Level.WARNING, "INVALID_TIMEOUT_FORMAT", new Object[] {
+                        Client.CONNECTION_TIMEOUT, obj.toString()
+                    });
+                }
+
+            }
+        }
+        
         long timeout = csPolicy.getConnectionTimeout();
         if (timeout > Integer.MAX_VALUE) {
             timeout = Integer.MAX_VALUE;

Modified: cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/Messages.properties
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/Messages.properties?rev=996809&r1=996808&r2=996809&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/Messages.properties
(original)
+++ cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/Messages.properties
Tue Sep 14 09:55:34 2010
@@ -24,3 +24,4 @@ NULL_RESPONSE_MSG = Response object is n
 DECOUPLED_RESPONSE_FAILED_MSG = Decouple response failed
 MISSING_PATH_INFO = PATH_INFO not present in message context, multiplex id is unavailable.
Ensure the portName passed to getCurrentEndpointReferenceId is correct if the service has
multiple ports
 INVALID_ENCODING_MSG = Invalid character set {0} in request.
+INVALID_TIMEOUT_FORMAT = Invalid name/value pair {0}={1} set in RequestConext 

Modified: cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/ClientServerTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/ClientServerTest.java?rev=996809&r1=996808&r2=996809&view=diff
==============================================================================
--- cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/ClientServerTest.java
(original)
+++ cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/ClientServerTest.java
Tue Sep 14 09:55:34 2010
@@ -170,6 +170,28 @@ public class ClientServerTest extends Ab
     }
     
     @Test
+    public void testTimeoutConfigutation() throws Exception {
+
+        SOAPService service = new SOAPService();
+        assertNotNull(service);
+
+        Greeter greeter = service.getPort(portName, Greeter.class);
+        updateAddressPort(greeter, PORT);
+        ((javax.xml.ws.BindingProvider)greeter).getRequestContext().put("javax.xml.ws.client.receiveTimeout",
+                                                                        "1");
+        try {
+            greeter.greetMe("test");
+            // remove fail() check to let this test pass in the powerful machine
+        } catch (Throwable ex) {
+            Object cause = null;
+            if (ex.getCause() != null) {
+                cause = ex.getCause();
+            }
+            assertTrue("Timeout cause is expected", cause instanceof java.net.SocketTimeoutException);
+        }
+    }    
+    
+    @Test
     public void testNillable() throws Exception {
         SOAPService service = new SOAPService();
         assertNotNull(service);



Mime
View raw message