cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1369622 - in /cxf/sandbox/dkulp_async_clients/http-hc/src: main/java/org/apache/cxf/transport/http/asyncclient/ test/resources/
Date Sun, 05 Aug 2012 17:26:53 GMT
Author: olegk
Date: Sun Aug  5 17:26:52 2012
New Revision: 1369622

URL: http://svn.apache.org/viewvc?rev=1369622&view=rev
Log:
Use i/o reactor #timeout event to enforce receive timeout specified by HTTPClientPolicy

Added:
    cxf/sandbox/dkulp_async_clients/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/CXFAsyncRequestExecutor.java
  (with props)
Modified:
    cxf/sandbox/dkulp_async_clients/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduit.java
    cxf/sandbox/dkulp_async_clients/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPTransportFactory.java
    cxf/sandbox/dkulp_async_clients/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/SharedInputBuffer.java
    cxf/sandbox/dkulp_async_clients/http-hc/src/test/resources/log4j.properties

Modified: cxf/sandbox/dkulp_async_clients/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduit.java
URL: http://svn.apache.org/viewvc/cxf/sandbox/dkulp_async_clients/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduit.java?rev=1369622&r1=1369621&r2=1369622&view=diff
==============================================================================
--- cxf/sandbox/dkulp_async_clients/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduit.java
(original)
+++ cxf/sandbox/dkulp_async_clients/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduit.java
Sun Aug  5 17:26:52 2012
@@ -45,6 +45,7 @@ import org.apache.http.HttpResponse;
 import org.apache.http.concurrent.FutureCallback;
 import org.apache.http.entity.BasicHttpEntity;
 import org.apache.http.nio.util.HeapByteBufferAllocator;
+import org.apache.http.params.CoreConnectionPNames;
 import org.apache.http.protocol.BasicHttpContext;
 
 /**
@@ -68,17 +69,16 @@ public class AsyncHTTPConduit extends HT
             message.put(Message.HTTP_REQUEST_METHOD, httpRequestMethod);
         }
         CXFHttpRequest e = new CXFHttpRequest(httpRequestMethod);
-        
-        BasicHttpEntity entity = new BasicHttpEntity() {
-            public boolean isStreaming() {
-                return true;
-            }
-        };
+        BasicHttpEntity entity = new BasicHttpEntity();
         entity.setChunked(true);
-        //entity.setContentLength(this.file.length());
         entity.setContentType((String)message.get(Message.CONTENT_TYPE));
         e.setURI(uri);
         e.setEntity(entity);
+        
+        // Set socket timeout
+        e.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, 
+                Integer.valueOf((int) csPolicy.getReceiveTimeout()));
+        
         message.put(CXFHttpRequest.class, e);
     }
     
@@ -124,7 +124,7 @@ public class AsyncHTTPConduit extends HT
             entity = message.get(CXFHttpRequest.class);
             basicEntity = (BasicHttpEntity)entity.getEntity();
             HeapByteBufferAllocator allocator = new HeapByteBufferAllocator();
-            inbuf = new SharedInputBuffer(4096 * 4, allocator, csPolicy.getReceiveTimeout());
+            inbuf = new SharedInputBuffer(4096 * 4, allocator);
             outbuf = new SharedOutputBuffer(4096 * 4, allocator);
         }
         
@@ -358,7 +358,7 @@ public class AsyncHTTPConduit extends HT
             }
             //reset the buffers
             HeapByteBufferAllocator allocator = new HeapByteBufferAllocator();
-            inbuf = new SharedInputBuffer(4096 * 4, allocator, csPolicy.getReceiveTimeout());
+            inbuf = new SharedInputBuffer(4096 * 4, allocator);
             outbuf = new SharedOutputBuffer(4096 * 4, allocator);
         }
         

Modified: cxf/sandbox/dkulp_async_clients/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPTransportFactory.java
URL: http://svn.apache.org/viewvc/cxf/sandbox/dkulp_async_clients/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPTransportFactory.java?rev=1369622&r1=1369621&r2=1369622&view=diff
==============================================================================
--- cxf/sandbox/dkulp_async_clients/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPTransportFactory.java
(original)
+++ cxf/sandbox/dkulp_async_clients/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPTransportFactory.java
Sun Aug  5 17:26:52 2012
@@ -40,7 +40,6 @@ import org.apache.http.impl.nio.DefaultH
 import org.apache.http.impl.nio.pool.BasicNIOConnFactory;
 import org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor;
 import org.apache.http.impl.nio.reactor.IOReactorConfig;
-import org.apache.http.nio.protocol.HttpAsyncRequestExecutor;
 import org.apache.http.nio.reactor.ConnectingIOReactor;
 import org.apache.http.nio.reactor.IOEventDispatch;
 import org.apache.http.nio.reactor.IOReactorException;
@@ -114,10 +113,10 @@ public class AsyncHTTPTransportFactory e
         httpproc.addInterceptor(new RequestExpectContinue());
 
         // Create client-side HTTP protocol handler
-        HttpAsyncRequestExecutor protocolHandler = new HttpAsyncRequestExecutor();
+        CXFAsyncRequestExecutor protocolHandler = new CXFAsyncRequestExecutor();
         // Create client-side I/O event dispatch
-        final CXFPlainConnectionFactory plainConnFactory = new CXFPlainConnectionFactory(params);
-        final CXFSSLConnectionFactory sslConnFactory = new CXFSSLConnectionFactory(params);
+        CXFPlainConnectionFactory plainConnFactory = new CXFPlainConnectionFactory(params);
+        CXFSSLConnectionFactory sslConnFactory = new CXFSSLConnectionFactory(params);
         final IOEventDispatch ioEventDispatch = new DefaultHttpClientIODispatch(protocolHandler,

                 plainConnFactory);
         // Create client-side I/O reactor

Added: cxf/sandbox/dkulp_async_clients/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/CXFAsyncRequestExecutor.java
URL: http://svn.apache.org/viewvc/cxf/sandbox/dkulp_async_clients/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/CXFAsyncRequestExecutor.java?rev=1369622&view=auto
==============================================================================
--- cxf/sandbox/dkulp_async_clients/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/CXFAsyncRequestExecutor.java
(added)
+++ cxf/sandbox/dkulp_async_clients/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/CXFAsyncRequestExecutor.java
Sun Aug  5 17:26:52 2012
@@ -0,0 +1,122 @@
+/**
+ * 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.cxf.transport.http.asyncclient;
+
+import java.io.IOException;
+
+import org.apache.http.HttpException;
+import org.apache.http.nio.ContentDecoder;
+import org.apache.http.nio.ContentEncoder;
+import org.apache.http.nio.NHttpClientConnection;
+import org.apache.http.nio.protocol.HttpAsyncRequestExecutor;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class CXFAsyncRequestExecutor extends HttpAsyncRequestExecutor {
+
+    private static final Logger LOG = LoggerFactory.getLogger(CXFAsyncRequestExecutor.class);
+
+    @Override
+    public void connected(
+            final NHttpClientConnection conn,
+            final Object attachment) throws IOException, HttpException {
+        if (LOG.isDebugEnabled()) {
+            LOG.debug(conn + ": Connected");
+        }
+        super.connected(conn, attachment);
+    }
+
+    @Override
+    public void closed(final NHttpClientConnection conn) {
+        if (LOG.isDebugEnabled()) {
+            LOG.debug(conn + ": Disconnected");
+        }
+        super.closed(conn);
+    }
+
+    @Override
+    public void exception(final NHttpClientConnection conn, final Exception ex) {
+        if (LOG.isErrorEnabled()) {
+            LOG.error(conn + " HTTP protocol exception: " + ex.getMessage(), ex);
+        }
+        super.exception(conn, ex);
+    }
+
+    @Override
+    public void requestReady(
+            final NHttpClientConnection conn) throws IOException, HttpException {
+        if (LOG.isDebugEnabled()) {
+            LOG.debug(conn + " Request ready");
+        }
+        super.requestReady(conn);
+    }
+
+    @Override
+    public void inputReady(
+            final NHttpClientConnection conn,
+            final ContentDecoder decoder) throws IOException {
+        if (LOG.isDebugEnabled()) {
+            LOG.debug(conn + " Input ready");
+        }
+        super.inputReady(conn, decoder);
+        if (LOG.isDebugEnabled()) {
+            LOG.debug(conn + " " + decoder);
+        }
+    }
+
+    @Override
+    public void outputReady(
+            final NHttpClientConnection conn,
+            final ContentEncoder encoder) throws IOException {
+        if (LOG.isDebugEnabled()) {
+            LOG.debug(conn + " Output ready");
+        }
+        super.outputReady(conn, encoder);
+        if (LOG.isDebugEnabled()) {
+            LOG.debug(conn + " " + encoder);
+        }
+    }
+
+    @Override
+    public void responseReceived(
+            final NHttpClientConnection conn) throws HttpException, IOException {
+        if (LOG.isDebugEnabled()) {
+            LOG.debug(conn + " Response received");
+        }
+        super.responseReceived(conn);
+    }
+
+    @Override
+    public void timeout(final NHttpClientConnection conn) throws IOException {
+        if (LOG.isDebugEnabled()) {
+            LOG.debug(conn + " Timeout");
+        }
+        super.timeout(conn);
+    }
+
+    @Override
+    public void endOfInput(NHttpClientConnection conn) throws IOException {
+        if (LOG.isDebugEnabled()) {
+            LOG.debug(conn + " End of input");
+        }
+        super.endOfInput(conn);
+    }
+    
+}

Propchange: cxf/sandbox/dkulp_async_clients/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/CXFAsyncRequestExecutor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/sandbox/dkulp_async_clients/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/CXFAsyncRequestExecutor.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: cxf/sandbox/dkulp_async_clients/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/CXFAsyncRequestExecutor.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: cxf/sandbox/dkulp_async_clients/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/SharedInputBuffer.java
URL: http://svn.apache.org/viewvc/cxf/sandbox/dkulp_async_clients/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/SharedInputBuffer.java?rev=1369622&r1=1369621&r2=1369622&view=diff
==============================================================================
--- cxf/sandbox/dkulp_async_clients/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/SharedInputBuffer.java
(original)
+++ cxf/sandbox/dkulp_async_clients/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/SharedInputBuffer.java
Sun Aug  5 17:26:52 2012
@@ -21,7 +21,6 @@ package org.apache.cxf.transport.http.as
 
 import java.io.IOException;
 import java.io.InterruptedIOException;
-import java.util.concurrent.TimeUnit;
 import java.util.concurrent.locks.Condition;
 import java.util.concurrent.locks.ReentrantLock;
 
@@ -49,19 +48,16 @@ public class SharedInputBuffer extends E
 
     private final ReentrantLock lock;
     private final Condition condition;
-    private final long timeout;
 
     private volatile IOControl ioctrl;
     private volatile boolean shutdown;
     private volatile boolean endOfStream;
 
     public SharedInputBuffer(int buffersize, 
-                             final ByteBufferAllocator allocator,
-                             long timeout) {
+                             final ByteBufferAllocator allocator) {
         super(buffersize, allocator);
         this.lock = new ReentrantLock();
         this.condition = this.lock.newCondition();
-        this.timeout = timeout;
     }
 
     public void reset() {
@@ -167,10 +163,7 @@ public class SharedInputBuffer extends E
                     if (this.ioctrl != null) {
                         this.ioctrl.requestInput();
                     }
-                    if (!this.condition.await(timeout, TimeUnit.MILLISECONDS)) {
-                        shutdown();
-                        throw new IOException("Read timeout waiting for data");
-                    }
+                    this.condition.await();
                 }
             } catch (InterruptedException ex) {
                 throw new IOException("Interrupted while waiting for more data");

Modified: cxf/sandbox/dkulp_async_clients/http-hc/src/test/resources/log4j.properties
URL: http://svn.apache.org/viewvc/cxf/sandbox/dkulp_async_clients/http-hc/src/test/resources/log4j.properties?rev=1369622&r1=1369621&r2=1369622&view=diff
==============================================================================
--- cxf/sandbox/dkulp_async_clients/http-hc/src/test/resources/log4j.properties (original)
+++ cxf/sandbox/dkulp_async_clients/http-hc/src/test/resources/log4j.properties Sun Aug  5
17:26:52 2012
@@ -5,4 +5,4 @@ log4j.appender.stdout.layout.ConversionP
  
 log4j.rootLogger=WARN, stdout
 #log4j.logger.org.apache.http=DEBUG
- 
+#log4j.logger.org.apache.cxf.transport.http.asyncclient=DEBUG



Mime
View raw message