Author: olegk
Date: Tue Jul 31 19:11:48 2012
New Revision: 1367707
URL: http://svn.apache.org/viewvc?rev=1367707&view=rev
Log:
Added custom request producer / response consumer implementations that use
shared buffers to produce / consume content data
Added:
cxf/sandbox/dkulp_async_clients/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/CXFHttpAsyncRequestProducer.java
(with props)
cxf/sandbox/dkulp_async_clients/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/CXFHttpAsyncResponseConsumer.java
(with props)
cxf/sandbox/dkulp_async_clients/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/CXFHttpRequest.java
(with props)
Modified:
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/main/java/org/apache/cxf/transport/http/asyncclient/SharedOutputBuffer.java
Added:
cxf/sandbox/dkulp_async_clients/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/CXFHttpAsyncRequestProducer.java
URL:
http://svn.apache.org/viewvc/cxf/sandbox/dkulp_async_clients/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/CXFHttpAsyncRequestProducer.java?rev=1367707&view=auto
==============================================================================
---
cxf/sandbox/dkulp_async_clients/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/CXFHttpAsyncRequestProducer.java
(added)
+++
cxf/sandbox/dkulp_async_clients/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/CXFHttpAsyncRequestProducer.java
Tue Jul 31 19:11:48 2012
@@ -0,0 +1,86 @@
+/**
+ * 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 java.net.URI;
+
+import org.apache.http.HttpException;
+import org.apache.http.HttpHost;
+import org.apache.http.HttpRequest;
+import org.apache.http.nio.ContentEncoder;
+import org.apache.http.nio.IOControl;
+import org.apache.http.nio.protocol.HttpAsyncRequestProducer;
+import org.apache.http.protocol.HttpContext;
+
+public class CXFHttpAsyncRequestProducer implements HttpAsyncRequestProducer {
+
+ private final CXFHttpRequest request;
+ private final SharedOutputBuffer buf;
+
+ public CXFHttpAsyncRequestProducer(final CXFHttpRequest request, final
SharedOutputBuffer buf) {
+ super();
+ this.buf = buf;
+ this.request = request;
+ }
+
+ public HttpHost getTarget() {
+ URI uri = request.getRequestURI();
+ if (uri == null) {
+ throw new IllegalStateException("Request URI is null");
+ }
+ if (!uri.isAbsolute()) {
+ throw new IllegalStateException("Request URI is not absolute");
+ }
+ int i = uri.getPort();
+ if (i == -1) {
+ i = 80;
+ }
+ return new HttpHost(uri.getHost(), i, uri.getScheme());
+ }
+
+ public HttpRequest generateRequest() throws IOException, HttpException {
+ return request;
+ }
+
+ public void produceContent(final ContentEncoder enc, final IOControl ioc)
throws IOException {
+ buf.produceContent(enc, ioc);
+ }
+
+ public void requestCompleted(final HttpContext context) {
+ }
+
+ public void failed(final Exception ex) {
+ buf.shutdown();
+ }
+
+ public boolean isRepeatable() {
+ return false;
+ }
+
+ public void resetRequest() throws IOException {
+ }
+
+ @Override
+ public void close() throws IOException {
+ buf.close();
+ }
+
+}
Propchange:
cxf/sandbox/dkulp_async_clients/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/CXFHttpAsyncRequestProducer.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
cxf/sandbox/dkulp_async_clients/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/CXFHttpAsyncRequestProducer.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange:
cxf/sandbox/dkulp_async_clients/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/CXFHttpAsyncRequestProducer.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added:
cxf/sandbox/dkulp_async_clients/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/CXFHttpAsyncResponseConsumer.java
URL:
http://svn.apache.org/viewvc/cxf/sandbox/dkulp_async_clients/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/CXFHttpAsyncResponseConsumer.java?rev=1367707&view=auto
==============================================================================
---
cxf/sandbox/dkulp_async_clients/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/CXFHttpAsyncResponseConsumer.java
(added)
+++
cxf/sandbox/dkulp_async_clients/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/CXFHttpAsyncResponseConsumer.java
Tue Jul 31 19:11:48 2012
@@ -0,0 +1,97 @@
+/**
+ * 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.HttpResponse;
+import org.apache.http.concurrent.BasicFuture;
+import org.apache.http.nio.ContentDecoder;
+import org.apache.http.nio.IOControl;
+import org.apache.http.nio.protocol.HttpAsyncResponseConsumer;
+import org.apache.http.protocol.HttpContext;
+
+public class CXFHttpAsyncResponseConsumer implements
HttpAsyncResponseConsumer<Boolean> {
+
+ private final SharedInputBuffer buf;
+ private final BasicFuture<HttpResponse> future;
+
+ private volatile boolean completed;
+ private volatile Exception exception;
+
+ public CXFHttpAsyncResponseConsumer(final SharedInputBuffer buf, final
BasicFuture<HttpResponse> future) {
+ super();
+ this.buf = buf;
+ this.future = future;
+ }
+
+ @Override
+ public void close() throws IOException {
+ buf.close();
+ }
+
+ @Override
+ public boolean cancel() {
+ completed = true;
+ buf.shutdown();
+ return true;
+ }
+
+ @Override
+ public void responseReceived(final HttpResponse response) throws
IOException, HttpException {
+ future.completed(response);
+ }
+
+ @Override
+ public void consumeContent(final ContentDecoder dec, final IOControl ioc)
throws IOException {
+ buf.consumeContent(dec, ioc);
+ }
+
+ @Override
+ public void responseCompleted(final HttpContext context) {
+ completed = true;
+ buf.close();
+ }
+
+ @Override
+ public void failed(final Exception ex) {
+ completed = true;
+ exception = ex;
+ buf.shutdown();
+ future.failed(ex);
+ }
+
+ @Override
+ public Exception getException() {
+ return exception;
+ }
+
+ @Override
+ public Boolean getResult() {
+ return exception != null;
+ }
+
+ @Override
+ public boolean isDone() {
+ return completed;
+ }
+
+}
Propchange:
cxf/sandbox/dkulp_async_clients/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/CXFHttpAsyncResponseConsumer.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
cxf/sandbox/dkulp_async_clients/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/CXFHttpAsyncResponseConsumer.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange:
cxf/sandbox/dkulp_async_clients/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/CXFHttpAsyncResponseConsumer.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added:
cxf/sandbox/dkulp_async_clients/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/CXFHttpRequest.java
URL:
http://svn.apache.org/viewvc/cxf/sandbox/dkulp_async_clients/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/CXFHttpRequest.java?rev=1367707&view=auto
==============================================================================
---
cxf/sandbox/dkulp_async_clients/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/CXFHttpRequest.java
(added)
+++
cxf/sandbox/dkulp_async_clients/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/CXFHttpRequest.java
Tue Jul 31 19:11:48 2012
@@ -0,0 +1,84 @@
+/**
+ * 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.net.URI;
+
+import org.apache.http.Header;
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpEntityEnclosingRequest;
+import org.apache.http.HttpVersion;
+import org.apache.http.ProtocolVersion;
+import org.apache.http.RequestLine;
+import org.apache.http.message.AbstractHttpMessage;
+import org.apache.http.message.BasicRequestLine;
+import org.apache.http.protocol.HTTP;
+
+class CXFHttpRequest extends AbstractHttpMessage implements
HttpEntityEnclosingRequest {
+
+ private final String method;
+
+ private URI requestURI;
+ private HttpEntity entity;
+
+ public CXFHttpRequest(final String method) {
+ super();
+ this.method = method;
+ }
+
+ public URI getRequestURI() {
+ return requestURI;
+ }
+
+ public void setRequestURI(final URI requestURI) {
+ this.requestURI = requestURI;
+ }
+
+ public String getMethod() {
+ return method;
+ }
+
+ @Override
+ public RequestLine getRequestLine() {
+ return new BasicRequestLine(
+ method,
+ requestURI != null ? requestURI.toASCIIString() : "/",
+ HttpVersion.HTTP_1_1);
+ }
+
+ @Override
+ public ProtocolVersion getProtocolVersion() {
+ return HttpVersion.HTTP_1_1;
+ }
+
+ public HttpEntity getEntity() {
+ return this.entity;
+ }
+
+ public void setEntity(final HttpEntity entity) {
+ this.entity = entity;
+ }
+
+ public boolean expectContinue() {
+ Header expect = getFirstHeader(HTTP.EXPECT_DIRECTIVE);
+ return expect != null &&
HTTP.EXPECT_CONTINUE.equalsIgnoreCase(expect.getValue());
+ }
+
+}
Propchange:
cxf/sandbox/dkulp_async_clients/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/CXFHttpRequest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
cxf/sandbox/dkulp_async_clients/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/CXFHttpRequest.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange:
cxf/sandbox/dkulp_async_clients/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/CXFHttpRequest.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=1367707&r1=1367706&r2=1367707&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
Tue Jul 31 19:11:48 2012
@@ -72,12 +72,13 @@ public class SharedInputBuffer extends E
}
}
- public int consumeContent(final ContentDecoder decoder) throws IOException
{
+ public int consumeContent(final ContentDecoder decoder, final IOControl
ioc) throws IOException {
if (this.shutdown) {
return -1;
}
this.lock.lock();
try {
+ this.ioctrl = ioc;
setInputMode();
int totalRead = 0;
int bytesRead;
@@ -106,15 +107,6 @@ public class SharedInputBuffer extends E
}
}
- public void setIOControl(final IOControl ioc) {
- this.lock.lock();
- try {
- this.ioctrl = ioc;
- } finally {
- this.lock.unlock();
- }
- }
-
@Override
public boolean hasData() {
this.lock.lock();
Modified:
cxf/sandbox/dkulp_async_clients/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/SharedOutputBuffer.java
URL:
http://svn.apache.org/viewvc/cxf/sandbox/dkulp_async_clients/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/SharedOutputBuffer.java?rev=1367707&r1=1367706&r2=1367707&view=diff
==============================================================================
---
cxf/sandbox/dkulp_async_clients/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/SharedOutputBuffer.java
(original)
+++
cxf/sandbox/dkulp_async_clients/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/SharedOutputBuffer.java
Tue Jul 31 19:11:48 2012
@@ -112,21 +112,13 @@ public class SharedOutputBuffer extends
}
}
- public void setIOControl(final IOControl ioc) {
- this.lock.lock();
- try {
- this.ioctrl = ioc;
- } finally {
- this.lock.unlock();
- }
- }
-
- public int produceContent(final ContentEncoder encoder) throws IOException
{
+ public int produceContent(final ContentEncoder encoder, final IOControl
ioc) throws IOException {
if (this.shutdown) {
return -1;
}
this.lock.lock();
try {
+ this.ioctrl = ioc;
setOutputMode();
int bytesWritten = 0;
if (super.hasData()) {