You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2014/03/05 17:03:50 UTC
svn commit: r1574548 - in /httpcomponents/httpclient/branches/4.3.x: ./
fluent-hc/src/main/java/org/apache/http/client/fluent/
Author: olegk
Date: Wed Mar 5 16:03:49 2014
New Revision: 1574548
URL: http://svn.apache.org/r1574548
Log:
HTTPCLIENT-1474: fixed broken entity enclosing requests in HC Fluent
Added:
httpcomponents/httpclient/branches/4.3.x/fluent-hc/src/main/java/org/apache/http/client/fluent/InternalEntityEnclosingHttpRequest.java (with props)
Modified:
httpcomponents/httpclient/branches/4.3.x/RELEASE_NOTES.txt
httpcomponents/httpclient/branches/4.3.x/fluent-hc/src/main/java/org/apache/http/client/fluent/InternalHttpRequest.java
httpcomponents/httpclient/branches/4.3.x/fluent-hc/src/main/java/org/apache/http/client/fluent/Request.java
Modified: httpcomponents/httpclient/branches/4.3.x/RELEASE_NOTES.txt
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/4.3.x/RELEASE_NOTES.txt?rev=1574548&r1=1574547&r2=1574548&view=diff
==============================================================================
--- httpcomponents/httpclient/branches/4.3.x/RELEASE_NOTES.txt (original)
+++ httpcomponents/httpclient/branches/4.3.x/RELEASE_NOTES.txt Wed Mar 5 16:03:49 2014
@@ -4,6 +4,9 @@ Changes for 4.3.TBA
Changelog:
-------------------
+* [HTTPCLIENT-1474] Fixed broken entity enclosing requests in HC Fluent.
+ Contributed by Oleg Kalnichevski <olegk at apache.org>
+
* [HTTPCLIENT-1470] CachingExec(ClientExecChain, HttpCache, CacheConfig, AsynchronousValidator) throws NPE if config is null
Added: httpcomponents/httpclient/branches/4.3.x/fluent-hc/src/main/java/org/apache/http/client/fluent/InternalEntityEnclosingHttpRequest.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/4.3.x/fluent-hc/src/main/java/org/apache/http/client/fluent/InternalEntityEnclosingHttpRequest.java?rev=1574548&view=auto
==============================================================================
--- httpcomponents/httpclient/branches/4.3.x/fluent-hc/src/main/java/org/apache/http/client/fluent/InternalEntityEnclosingHttpRequest.java (added)
+++ httpcomponents/httpclient/branches/4.3.x/fluent-hc/src/main/java/org/apache/http/client/fluent/InternalEntityEnclosingHttpRequest.java Wed Mar 5 16:03:49 2014
@@ -0,0 +1,60 @@
+/*
+ * ====================================================================
+ * 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.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.client.fluent;
+
+import java.net.URI;
+
+import org.apache.http.Header;
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpEntityEnclosingRequest;
+import org.apache.http.annotation.NotThreadSafe;
+import org.apache.http.protocol.HTTP;
+
+@NotThreadSafe
+class InternalEntityEnclosingHttpRequest extends InternalHttpRequest implements HttpEntityEnclosingRequest {
+
+ private HttpEntity entity;
+
+ public InternalEntityEnclosingHttpRequest(final String method, final URI requestURI) {
+ super(method, requestURI);
+ }
+
+ public HttpEntity getEntity() {
+ return this.entity;
+ }
+
+ public void setEntity(final HttpEntity entity) {
+ this.entity = entity;
+ }
+
+ public boolean expectContinue() {
+ final Header expect = getFirstHeader(HTTP.EXPECT_DIRECTIVE);
+ return expect != null && HTTP.EXPECT_CONTINUE.equalsIgnoreCase(expect.getValue());
+ }
+
+}
Propchange: httpcomponents/httpclient/branches/4.3.x/fluent-hc/src/main/java/org/apache/http/client/fluent/InternalEntityEnclosingHttpRequest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: httpcomponents/httpclient/branches/4.3.x/fluent-hc/src/main/java/org/apache/http/client/fluent/InternalEntityEnclosingHttpRequest.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: httpcomponents/httpclient/branches/4.3.x/fluent-hc/src/main/java/org/apache/http/client/fluent/InternalEntityEnclosingHttpRequest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: httpcomponents/httpclient/branches/4.3.x/fluent-hc/src/main/java/org/apache/http/client/fluent/InternalHttpRequest.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/4.3.x/fluent-hc/src/main/java/org/apache/http/client/fluent/InternalHttpRequest.java?rev=1574548&r1=1574547&r2=1574548&view=diff
==============================================================================
--- httpcomponents/httpclient/branches/4.3.x/fluent-hc/src/main/java/org/apache/http/client/fluent/InternalHttpRequest.java (original)
+++ httpcomponents/httpclient/branches/4.3.x/fluent-hc/src/main/java/org/apache/http/client/fluent/InternalHttpRequest.java Wed Mar 5 16:03:49 2014
@@ -28,6 +28,8 @@
package org.apache.http.client.fluent;
import java.net.URI;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicReference;
import org.apache.http.HttpVersion;
import org.apache.http.ProtocolVersion;
@@ -35,24 +37,32 @@ import org.apache.http.RequestLine;
import org.apache.http.annotation.NotThreadSafe;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.Configurable;
+import org.apache.http.client.methods.HttpExecutionAware;
import org.apache.http.client.methods.HttpUriRequest;
+import org.apache.http.concurrent.Cancellable;
import org.apache.http.message.AbstractHttpMessage;
import org.apache.http.message.BasicRequestLine;
import org.apache.http.util.Args;
@NotThreadSafe
-class InternalHttpRequest extends AbstractHttpMessage implements HttpUriRequest, Configurable {
+class InternalHttpRequest extends AbstractHttpMessage
+ implements HttpUriRequest, HttpExecutionAware, Configurable {
private final String method;
private ProtocolVersion version;
private URI uri;
private RequestConfig config;
+ private final AtomicBoolean aborted;
+ private final AtomicReference<Cancellable> cancellableRef;
+
InternalHttpRequest(final String method, final URI requestURI) {
Args.notBlank(method, "Method");
Args.notNull(requestURI, "Request URI");
this.method = method;
this.uri = requestURI;
+ this.aborted = new AtomicBoolean(false);
+ this.cancellableRef = new AtomicReference<Cancellable>(null);
}
public void setProtocolVersion(final ProtocolVersion version) {
@@ -72,10 +82,22 @@ class InternalHttpRequest extends Abstra
}
public void abort() throws UnsupportedOperationException {
+ if (this.aborted.compareAndSet(false, true)) {
+ final Cancellable cancellable = this.cancellableRef.getAndSet(null);
+ if (cancellable != null) {
+ cancellable.cancel();
+ }
+ }
}
public boolean isAborted() {
- return false;
+ return this.aborted.get();
+ }
+
+ public void setCancellable(final Cancellable cancellable) {
+ if (!this.aborted.get()) {
+ this.cancellableRef.set(cancellable);
+ }
}
public RequestLine getRequestLine() {
@@ -92,7 +114,6 @@ class InternalHttpRequest extends Abstra
return new BasicRequestLine(method, uritext, ver);
}
-
public RequestConfig getConfig() {
return config;
}
Modified: httpcomponents/httpclient/branches/4.3.x/fluent-hc/src/main/java/org/apache/http/client/fluent/Request.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/4.3.x/fluent-hc/src/main/java/org/apache/http/client/fluent/Request.java?rev=1574548&r1=1574547&r2=1574548&view=diff
==============================================================================
--- httpcomponents/httpclient/branches/4.3.x/fluent-hc/src/main/java/org/apache/http/client/fluent/Request.java (original)
+++ httpcomponents/httpclient/branches/4.3.x/fluent-hc/src/main/java/org/apache/http/client/fluent/Request.java Wed Mar 5 16:03:49 2014
@@ -72,64 +72,64 @@ public class Request {
private SimpleDateFormat dateFormatter;
public static Request Get(final URI uri) {
- return new Request(HttpGet.METHOD_NAME, uri);
+ return new Request(new InternalHttpRequest(HttpGet.METHOD_NAME, uri));
}
public static Request Get(final String uri) {
- return new Request(HttpGet.METHOD_NAME, URI.create(uri));
+ return new Request(new InternalHttpRequest(HttpGet.METHOD_NAME, URI.create(uri)));
}
public static Request Head(final URI uri) {
- return new Request(HttpHead.METHOD_NAME, uri);
+ return new Request(new InternalHttpRequest(HttpHead.METHOD_NAME, uri));
}
public static Request Head(final String uri) {
- return new Request(HttpHead.METHOD_NAME, URI.create(uri));
+ return new Request(new InternalHttpRequest(HttpHead.METHOD_NAME, URI.create(uri)));
}
public static Request Post(final URI uri) {
- return new Request(HttpPost.METHOD_NAME, uri);
+ return new Request(new InternalEntityEnclosingHttpRequest(HttpPost.METHOD_NAME, uri));
}
public static Request Post(final String uri) {
- return new Request(HttpPost.METHOD_NAME, URI.create(uri));
+ return new Request(new InternalEntityEnclosingHttpRequest(HttpPost.METHOD_NAME, URI.create(uri)));
}
public static Request Put(final URI uri) {
- return new Request(HttpPut.METHOD_NAME, uri);
+ return new Request(new InternalEntityEnclosingHttpRequest(HttpPut.METHOD_NAME, uri));
}
public static Request Put(final String uri) {
- return new Request(HttpPut.METHOD_NAME, URI.create(uri));
+ return new Request(new InternalEntityEnclosingHttpRequest(HttpPut.METHOD_NAME, URI.create(uri)));
}
public static Request Trace(final URI uri) {
- return new Request(HttpTrace.METHOD_NAME, uri);
+ return new Request(new InternalHttpRequest(HttpTrace.METHOD_NAME, uri));
}
public static Request Trace(final String uri) {
- return new Request(HttpTrace.METHOD_NAME, URI.create(uri));
+ return new Request(new InternalHttpRequest(HttpTrace.METHOD_NAME, URI.create(uri)));
}
public static Request Delete(final URI uri) {
- return new Request(HttpDelete.METHOD_NAME, uri);
+ return new Request(new InternalHttpRequest(HttpDelete.METHOD_NAME, uri));
}
public static Request Delete(final String uri) {
- return new Request(HttpDelete.METHOD_NAME, URI.create(uri));
+ return new Request(new InternalHttpRequest(HttpDelete.METHOD_NAME, URI.create(uri)));
}
public static Request Options(final URI uri) {
- return new Request(HttpOptions.METHOD_NAME, uri);
+ return new Request(new InternalHttpRequest(HttpOptions.METHOD_NAME, uri));
}
public static Request Options(final String uri) {
- return new Request(HttpOptions.METHOD_NAME, URI.create(uri));
+ return new Request(new InternalHttpRequest(HttpOptions.METHOD_NAME, URI.create(uri)));
}
- Request(final String method, final URI requestURI) {
+ Request(final InternalHttpRequest request) {
super();
- this.request = new InternalHttpRequest(method, requestURI);
+ this.request = request;
this.configBuilder = RequestConfig.custom();
}