Removed deprecated classes
This commit is contained in:
parent
88a48b280f
commit
d929456278
|
@ -1,90 +0,0 @@
|
|||
/*
|
||||
* ====================================================================
|
||||
* 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.hc.client5.http;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* Common HTTP methods defined by the HTTP spec.
|
||||
*
|
||||
* @since 5.0
|
||||
*
|
||||
* @deprecated Use {@link org.apache.hc.core5.http.Methods}
|
||||
*/
|
||||
@Deprecated
|
||||
public enum StandardMethods {
|
||||
|
||||
GET(true, true),
|
||||
HEAD(true, true),
|
||||
POST(false, false),
|
||||
PUT(false, true),
|
||||
DELETE(false, true),
|
||||
CONNECT(false, false),
|
||||
TRACE(true, true),
|
||||
OPTIONS(true, true),
|
||||
PATCH(false, false);
|
||||
|
||||
private final boolean safe;
|
||||
private final boolean idempotent;
|
||||
|
||||
StandardMethods(final boolean safe, final boolean idempotent) {
|
||||
this.safe = safe;
|
||||
this.idempotent = idempotent;
|
||||
}
|
||||
|
||||
public boolean isSafe() {
|
||||
return safe;
|
||||
}
|
||||
|
||||
public boolean isIdempotent() {
|
||||
return idempotent;
|
||||
}
|
||||
|
||||
public static boolean isSafe(final String value) {
|
||||
if (value == null) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
return valueOf(value.toUpperCase(Locale.ROOT)).safe;
|
||||
} catch (final IllegalArgumentException ex) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isIdempotent(final String value) {
|
||||
if (value == null) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
return valueOf(value.toUpperCase(Locale.ROOT)).idempotent;
|
||||
} catch (final IllegalArgumentException ex) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,453 +0,0 @@
|
|||
/*
|
||||
* ====================================================================
|
||||
* 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.hc.client5.http.async.methods;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.hc.client5.http.config.RequestConfig;
|
||||
import org.apache.hc.core5.http.ContentType;
|
||||
import org.apache.hc.core5.http.Header;
|
||||
import org.apache.hc.core5.http.HttpHost;
|
||||
import org.apache.hc.core5.http.Methods;
|
||||
import org.apache.hc.core5.http.NameValuePair;
|
||||
import org.apache.hc.core5.http.ProtocolVersion;
|
||||
import org.apache.hc.core5.http.message.BasicHeader;
|
||||
import org.apache.hc.core5.http.message.BasicNameValuePair;
|
||||
import org.apache.hc.core5.http.message.HeaderGroup;
|
||||
import org.apache.hc.core5.http.nio.AsyncEntityProducer;
|
||||
import org.apache.hc.core5.http.nio.AsyncRequestProducer;
|
||||
import org.apache.hc.core5.http.nio.entity.BasicAsyncEntityProducer;
|
||||
import org.apache.hc.core5.http.nio.entity.StringAsyncEntityProducer;
|
||||
import org.apache.hc.core5.http.nio.support.BasicRequestProducer;
|
||||
import org.apache.hc.core5.net.URIBuilder;
|
||||
import org.apache.hc.core5.net.URLEncodedUtils;
|
||||
import org.apache.hc.core5.util.Args;
|
||||
import org.apache.hc.core5.util.TextUtils;
|
||||
|
||||
/**
|
||||
* Builder for {@link AsyncRequestProducer} instances.
|
||||
* <p>
|
||||
* Please note that this class treats parameters differently depending on composition
|
||||
* of the request: if the request has a content entity explicitly set with
|
||||
* {@link #setEntity(AsyncEntityProducer)} or it is not an entity enclosing method
|
||||
* (such as POST or PUT), parameters will be added to the query component of the request URI.
|
||||
* Otherwise, parameters will be added as a URL encoded entity.
|
||||
* </p>
|
||||
*
|
||||
* @since 5.0
|
||||
*
|
||||
* @deprecated Use {@link org.apache.hc.core5.http.nio.support.AsyncRequestBuilder}
|
||||
*/
|
||||
@Deprecated
|
||||
public class AsyncRequestBuilder {
|
||||
|
||||
private HttpHost host;
|
||||
private String path;
|
||||
private URI uri;
|
||||
private String method;
|
||||
private Charset charset;
|
||||
private ProtocolVersion version;
|
||||
private HeaderGroup headergroup;
|
||||
private AsyncEntityProducer entityProducer;
|
||||
private List<NameValuePair> parameters;
|
||||
private RequestConfig config;
|
||||
|
||||
AsyncRequestBuilder() {
|
||||
}
|
||||
|
||||
AsyncRequestBuilder(final String method) {
|
||||
super();
|
||||
this.method = method;
|
||||
}
|
||||
|
||||
AsyncRequestBuilder(final Methods method) {
|
||||
this(method.name());
|
||||
}
|
||||
|
||||
AsyncRequestBuilder(final String method, final URI uri) {
|
||||
super();
|
||||
this.method = method;
|
||||
this.uri = uri;
|
||||
}
|
||||
|
||||
AsyncRequestBuilder(final Methods method, final HttpHost host, final String path) {
|
||||
super();
|
||||
this.method = method.name();
|
||||
this.host = host;
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
AsyncRequestBuilder(final Methods method, final URI uri) {
|
||||
this(method.name(), uri);
|
||||
}
|
||||
|
||||
AsyncRequestBuilder(final Methods method, final String uri) {
|
||||
this(method.name(), uri != null ? URI.create(uri) : null);
|
||||
}
|
||||
|
||||
AsyncRequestBuilder(final String method, final String uri) {
|
||||
this(method, uri != null ? URI.create(uri) : null);
|
||||
}
|
||||
|
||||
public static AsyncRequestBuilder create(final String method) {
|
||||
Args.notBlank(method, "HTTP method");
|
||||
return new AsyncRequestBuilder(method);
|
||||
}
|
||||
|
||||
public static AsyncRequestBuilder get() {
|
||||
return new AsyncRequestBuilder(Methods.GET);
|
||||
}
|
||||
|
||||
public static AsyncRequestBuilder get(final URI uri) {
|
||||
return new AsyncRequestBuilder(Methods.GET, uri);
|
||||
}
|
||||
|
||||
public static AsyncRequestBuilder get(final String uri) {
|
||||
return new AsyncRequestBuilder(Methods.GET, uri);
|
||||
}
|
||||
|
||||
public static AsyncRequestBuilder get(final HttpHost host, final String path) {
|
||||
return new AsyncRequestBuilder(Methods.GET, host, path);
|
||||
}
|
||||
|
||||
public static AsyncRequestBuilder head() {
|
||||
return new AsyncRequestBuilder(Methods.HEAD);
|
||||
}
|
||||
|
||||
public static AsyncRequestBuilder head(final URI uri) {
|
||||
return new AsyncRequestBuilder(Methods.HEAD, uri);
|
||||
}
|
||||
|
||||
public static AsyncRequestBuilder head(final String uri) {
|
||||
return new AsyncRequestBuilder(Methods.HEAD, uri);
|
||||
}
|
||||
|
||||
public static AsyncRequestBuilder head(final HttpHost host, final String path) {
|
||||
return new AsyncRequestBuilder(Methods.HEAD, host, path);
|
||||
}
|
||||
|
||||
public static AsyncRequestBuilder patch() {
|
||||
return new AsyncRequestBuilder(Methods.PATCH);
|
||||
}
|
||||
|
||||
public static AsyncRequestBuilder patch(final URI uri) {
|
||||
return new AsyncRequestBuilder(Methods.PATCH, uri);
|
||||
}
|
||||
|
||||
public static AsyncRequestBuilder patch(final String uri) {
|
||||
return new AsyncRequestBuilder(Methods.PATCH, uri);
|
||||
}
|
||||
|
||||
public static AsyncRequestBuilder patch(final HttpHost host, final String path) {
|
||||
return new AsyncRequestBuilder(Methods.PATCH, host, path);
|
||||
}
|
||||
|
||||
public static AsyncRequestBuilder post() {
|
||||
return new AsyncRequestBuilder(Methods.POST);
|
||||
}
|
||||
|
||||
public static AsyncRequestBuilder post(final URI uri) {
|
||||
return new AsyncRequestBuilder(Methods.POST, uri);
|
||||
}
|
||||
|
||||
public static AsyncRequestBuilder post(final String uri) {
|
||||
return new AsyncRequestBuilder(Methods.POST, uri);
|
||||
}
|
||||
|
||||
public static AsyncRequestBuilder post(final HttpHost host, final String path) {
|
||||
return new AsyncRequestBuilder(Methods.POST, host, path);
|
||||
}
|
||||
|
||||
public static AsyncRequestBuilder put() {
|
||||
return new AsyncRequestBuilder(Methods.PUT);
|
||||
}
|
||||
|
||||
public static AsyncRequestBuilder put(final URI uri) {
|
||||
return new AsyncRequestBuilder(Methods.PUT, uri);
|
||||
}
|
||||
|
||||
public static AsyncRequestBuilder put(final String uri) {
|
||||
return new AsyncRequestBuilder(Methods.PUT, uri);
|
||||
}
|
||||
|
||||
public static AsyncRequestBuilder put(final HttpHost host, final String path) {
|
||||
return new AsyncRequestBuilder(Methods.PUT, host, path);
|
||||
}
|
||||
|
||||
public static AsyncRequestBuilder delete() {
|
||||
return new AsyncRequestBuilder(Methods.DELETE);
|
||||
}
|
||||
|
||||
public static AsyncRequestBuilder delete(final URI uri) {
|
||||
return new AsyncRequestBuilder(Methods.DELETE, uri);
|
||||
}
|
||||
|
||||
public static AsyncRequestBuilder delete(final String uri) {
|
||||
return new AsyncRequestBuilder(Methods.DELETE, uri);
|
||||
}
|
||||
|
||||
public static AsyncRequestBuilder delete(final HttpHost host, final String path) {
|
||||
return new AsyncRequestBuilder(Methods.DELETE, host, path);
|
||||
}
|
||||
|
||||
public static AsyncRequestBuilder trace() {
|
||||
return new AsyncRequestBuilder(Methods.TRACE);
|
||||
}
|
||||
|
||||
public static AsyncRequestBuilder trace(final URI uri) {
|
||||
return new AsyncRequestBuilder(Methods.TRACE, uri);
|
||||
}
|
||||
|
||||
public static AsyncRequestBuilder trace(final String uri) {
|
||||
return new AsyncRequestBuilder(Methods.TRACE, uri);
|
||||
}
|
||||
|
||||
public static AsyncRequestBuilder trace(final HttpHost host, final String path) {
|
||||
return new AsyncRequestBuilder(Methods.TRACE, host, path);
|
||||
}
|
||||
|
||||
public static AsyncRequestBuilder options() {
|
||||
return new AsyncRequestBuilder(Methods.OPTIONS);
|
||||
}
|
||||
|
||||
public static AsyncRequestBuilder options(final URI uri) {
|
||||
return new AsyncRequestBuilder(Methods.OPTIONS, uri);
|
||||
}
|
||||
|
||||
public static AsyncRequestBuilder options(final String uri) {
|
||||
return new AsyncRequestBuilder(Methods.OPTIONS, uri);
|
||||
}
|
||||
|
||||
public static AsyncRequestBuilder options(final HttpHost host, final String path) {
|
||||
return new AsyncRequestBuilder(Methods.OPTIONS, host, path);
|
||||
}
|
||||
|
||||
public AsyncRequestBuilder setCharset(final Charset charset) {
|
||||
this.charset = charset;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Charset getCharset() {
|
||||
return charset;
|
||||
}
|
||||
|
||||
public String getMethod() {
|
||||
return method;
|
||||
}
|
||||
|
||||
public URI getUri() {
|
||||
return uri;
|
||||
}
|
||||
|
||||
public AsyncRequestBuilder setUri(final URI uri) {
|
||||
this.uri = uri;
|
||||
this.host = null;
|
||||
this.path = null;
|
||||
return this;
|
||||
}
|
||||
|
||||
public AsyncRequestBuilder setUri(final String uri) {
|
||||
this.uri = uri != null ? URI.create(uri) : null;
|
||||
this.host = null;
|
||||
this.path = null;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ProtocolVersion getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public AsyncRequestBuilder setVersion(final ProtocolVersion version) {
|
||||
this.version = version;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Header getFirstHeader(final String name) {
|
||||
return headergroup != null ? headergroup.getFirstHeader(name) : null;
|
||||
}
|
||||
|
||||
public Header getLastHeader(final String name) {
|
||||
return headergroup != null ? headergroup.getLastHeader(name) : null;
|
||||
}
|
||||
|
||||
public Header[] getHeaders(final String name) {
|
||||
return headergroup != null ? headergroup.getHeaders(name) : null;
|
||||
}
|
||||
|
||||
public AsyncRequestBuilder addHeader(final Header header) {
|
||||
if (headergroup == null) {
|
||||
headergroup = new HeaderGroup();
|
||||
}
|
||||
headergroup.addHeader(header);
|
||||
return this;
|
||||
}
|
||||
|
||||
public AsyncRequestBuilder addHeader(final String name, final String value) {
|
||||
if (headergroup == null) {
|
||||
headergroup = new HeaderGroup();
|
||||
}
|
||||
this.headergroup.addHeader(new BasicHeader(name, value));
|
||||
return this;
|
||||
}
|
||||
|
||||
public AsyncRequestBuilder removeHeader(final Header header) {
|
||||
if (headergroup == null) {
|
||||
headergroup = new HeaderGroup();
|
||||
}
|
||||
headergroup.removeHeader(header);
|
||||
return this;
|
||||
}
|
||||
|
||||
public AsyncRequestBuilder removeHeaders(final String name) {
|
||||
if (name == null || headergroup == null) {
|
||||
return this;
|
||||
}
|
||||
for (final Iterator<Header> i = headergroup.headerIterator(); i.hasNext(); ) {
|
||||
final Header header = i.next();
|
||||
if (name.equalsIgnoreCase(header.getName())) {
|
||||
i.remove();
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public AsyncRequestBuilder setHeader(final Header header) {
|
||||
if (headergroup == null) {
|
||||
headergroup = new HeaderGroup();
|
||||
}
|
||||
this.headergroup.setHeader(header);
|
||||
return this;
|
||||
}
|
||||
|
||||
public AsyncRequestBuilder setHeader(final String name, final String value) {
|
||||
if (headergroup == null) {
|
||||
headergroup = new HeaderGroup();
|
||||
}
|
||||
this.headergroup.setHeader(new BasicHeader(name, value));
|
||||
return this;
|
||||
}
|
||||
|
||||
public List<NameValuePair> getParameters() {
|
||||
return parameters != null ? new ArrayList<>(parameters) :
|
||||
new ArrayList<NameValuePair>();
|
||||
}
|
||||
|
||||
public AsyncRequestBuilder addParameter(final NameValuePair nvp) {
|
||||
Args.notNull(nvp, "Name value pair");
|
||||
if (parameters == null) {
|
||||
parameters = new LinkedList<>();
|
||||
}
|
||||
parameters.add(nvp);
|
||||
return this;
|
||||
}
|
||||
|
||||
public AsyncRequestBuilder addParameter(final String name, final String value) {
|
||||
return addParameter(new BasicNameValuePair(name, value));
|
||||
}
|
||||
|
||||
public AsyncRequestBuilder addParameters(final NameValuePair... nvps) {
|
||||
for (final NameValuePair nvp: nvps) {
|
||||
addParameter(nvp);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public RequestConfig getConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
public AsyncRequestBuilder setConfig(final RequestConfig config) {
|
||||
this.config = config;
|
||||
return this;
|
||||
}
|
||||
|
||||
public AsyncEntityProducer getEntity() {
|
||||
return entityProducer;
|
||||
}
|
||||
|
||||
public AsyncRequestBuilder setEntity(final AsyncEntityProducer entityProducer) {
|
||||
this.entityProducer = entityProducer;
|
||||
return this;
|
||||
}
|
||||
|
||||
public AsyncRequestBuilder setEntity(final String content, final ContentType contentType) {
|
||||
this.entityProducer = new BasicAsyncEntityProducer(content, contentType);
|
||||
return this;
|
||||
}
|
||||
|
||||
public AsyncRequestBuilder setEntity(final byte[] content, final ContentType contentType) {
|
||||
this.entityProducer = new BasicAsyncEntityProducer(content, contentType);
|
||||
return this;
|
||||
}
|
||||
|
||||
public AsyncRequestProducer build() {
|
||||
AsyncEntityProducer entityProducerCopy = this.entityProducer;
|
||||
if (parameters != null && !parameters.isEmpty()) {
|
||||
if (entityProducerCopy == null && (Methods.POST.isSame(method) || Methods.PUT.isSame(method))) {
|
||||
final String content = URLEncodedUtils.format(
|
||||
parameters,
|
||||
charset != null ? charset : ContentType.APPLICATION_FORM_URLENCODED.getCharset());
|
||||
entityProducerCopy = new StringAsyncEntityProducer(
|
||||
content,
|
||||
ContentType.APPLICATION_FORM_URLENCODED);
|
||||
} else {
|
||||
try {
|
||||
uri = new URIBuilder(uri)
|
||||
.setCharset(this.charset)
|
||||
.addParameters(parameters)
|
||||
.build();
|
||||
} catch (final URISyntaxException ex) {
|
||||
// should never happen
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (entityProducerCopy != null && Methods.isSafe(method)) {
|
||||
throw new IllegalStateException(Methods.TRACE + " requests may not include an entity.");
|
||||
}
|
||||
|
||||
final ConfigurableHttpRequest request = host != null ?
|
||||
new ConfigurableHttpRequest(method, host, !TextUtils.isBlank(path) ? path : "/") :
|
||||
new ConfigurableHttpRequest(method, uri != null ? uri : URI.create("/"));
|
||||
if (this.headergroup != null) {
|
||||
request.setHeaders(this.headergroup.getHeaders());
|
||||
}
|
||||
if (version != null) {
|
||||
request.setVersion(version);
|
||||
}
|
||||
request.setConfig(config);
|
||||
return new BasicRequestProducer(request, entityProducerCopy);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,526 +0,0 @@
|
|||
/*
|
||||
* ====================================================================
|
||||
* 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.hc.client5.http.classic.methods;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.hc.client5.http.StandardMethods;
|
||||
import org.apache.hc.client5.http.config.Configurable;
|
||||
import org.apache.hc.client5.http.config.RequestConfig;
|
||||
import org.apache.hc.client5.http.entity.UrlEncodedFormEntity;
|
||||
import org.apache.hc.core5.http.ClassicHttpRequest;
|
||||
import org.apache.hc.core5.http.ContentType;
|
||||
import org.apache.hc.core5.http.Header;
|
||||
import org.apache.hc.core5.http.HttpEntity;
|
||||
import org.apache.hc.core5.http.HttpVersion;
|
||||
import org.apache.hc.core5.http.NameValuePair;
|
||||
import org.apache.hc.core5.http.ProtocolVersion;
|
||||
import org.apache.hc.core5.http.io.entity.EntityUtils;
|
||||
import org.apache.hc.core5.http.message.BasicHeader;
|
||||
import org.apache.hc.core5.http.message.BasicNameValuePair;
|
||||
import org.apache.hc.core5.http.message.HeaderGroup;
|
||||
import org.apache.hc.core5.net.URIBuilder;
|
||||
import org.apache.hc.core5.util.Args;
|
||||
|
||||
/**
|
||||
* Builder for {@link ClassicHttpRequest} instances.
|
||||
* <p>
|
||||
* Please note that this class treats parameters differently depending on composition
|
||||
* of the request: if the request has a content entity explicitly set with
|
||||
* {@link #setEntity(org.apache.hc.core5.http.HttpEntity)} or it is not an entity enclosing
|
||||
* method (such as POST or PUT), parameters will be added to the query component
|
||||
* of the request URI. Otherwise, parameters will be added as a URL encoded
|
||||
* {@link UrlEncodedFormEntity entity}.
|
||||
* </p>
|
||||
*
|
||||
* @since 4.3
|
||||
*
|
||||
* @deprecated Use {@link org.apache.hc.core5.http.io.support.ClassicRequestBuilder}
|
||||
*/
|
||||
@Deprecated
|
||||
public class RequestBuilder {
|
||||
|
||||
private String method;
|
||||
private Charset charset;
|
||||
private ProtocolVersion version;
|
||||
private URI uri;
|
||||
private HeaderGroup headerGroup;
|
||||
private HttpEntity entity;
|
||||
private List<NameValuePair> parameters;
|
||||
private RequestConfig config;
|
||||
|
||||
RequestBuilder(final String method) {
|
||||
super();
|
||||
this.charset = StandardCharsets.UTF_8;
|
||||
this.method = method;
|
||||
}
|
||||
|
||||
RequestBuilder() {
|
||||
}
|
||||
|
||||
RequestBuilder(final StandardMethods method) {
|
||||
this(method.name());
|
||||
}
|
||||
|
||||
RequestBuilder(final String method, final URI uri) {
|
||||
super();
|
||||
this.method = method;
|
||||
this.uri = uri;
|
||||
}
|
||||
|
||||
RequestBuilder(final StandardMethods method, final URI uri) {
|
||||
this(method.name(), uri);
|
||||
}
|
||||
|
||||
RequestBuilder(final String method, final String uri) {
|
||||
super();
|
||||
this.method = method;
|
||||
this.uri = uri != null ? URI.create(uri) : null;
|
||||
}
|
||||
|
||||
RequestBuilder(final StandardMethods method, final String uri) {
|
||||
this(method.name(), uri);
|
||||
}
|
||||
|
||||
public static RequestBuilder create(final String method) {
|
||||
Args.notBlank(method, "HTTP method");
|
||||
return new RequestBuilder(method);
|
||||
}
|
||||
|
||||
public static RequestBuilder get() {
|
||||
return new RequestBuilder(StandardMethods.GET.name());
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 4.4
|
||||
*/
|
||||
public static RequestBuilder get(final URI uri) {
|
||||
return new RequestBuilder(StandardMethods.GET, uri);
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 4.4
|
||||
*/
|
||||
public static RequestBuilder get(final String uri) {
|
||||
return new RequestBuilder(StandardMethods.GET, uri);
|
||||
}
|
||||
|
||||
public static RequestBuilder head() {
|
||||
return new RequestBuilder(StandardMethods.HEAD);
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 4.4
|
||||
*/
|
||||
public static RequestBuilder head(final URI uri) {
|
||||
return new RequestBuilder(StandardMethods.HEAD, uri);
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 4.4
|
||||
*/
|
||||
public static RequestBuilder head(final String uri) {
|
||||
return new RequestBuilder(StandardMethods.HEAD, uri);
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 4.4
|
||||
*/
|
||||
public static RequestBuilder patch() {
|
||||
return new RequestBuilder(StandardMethods.PATCH.name());
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 4.4
|
||||
*/
|
||||
public static RequestBuilder patch(final URI uri) {
|
||||
return new RequestBuilder(StandardMethods.PATCH, uri);
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 4.4
|
||||
*/
|
||||
public static RequestBuilder patch(final String uri) {
|
||||
return new RequestBuilder(StandardMethods.PATCH, uri);
|
||||
}
|
||||
|
||||
public static RequestBuilder post() {
|
||||
return new RequestBuilder(StandardMethods.POST);
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 4.4
|
||||
*/
|
||||
public static RequestBuilder post(final URI uri) {
|
||||
return new RequestBuilder(StandardMethods.POST, uri);
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 4.4
|
||||
*/
|
||||
public static RequestBuilder post(final String uri) {
|
||||
return new RequestBuilder(StandardMethods.POST, uri);
|
||||
}
|
||||
|
||||
public static RequestBuilder put() {
|
||||
return new RequestBuilder(StandardMethods.PUT);
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 4.4
|
||||
*/
|
||||
public static RequestBuilder put(final URI uri) {
|
||||
return new RequestBuilder(StandardMethods.PUT, uri);
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 4.4
|
||||
*/
|
||||
public static RequestBuilder put(final String uri) {
|
||||
return new RequestBuilder(StandardMethods.PUT, uri);
|
||||
}
|
||||
|
||||
public static RequestBuilder delete() {
|
||||
return new RequestBuilder(StandardMethods.DELETE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 4.4
|
||||
*/
|
||||
public static RequestBuilder delete(final URI uri) {
|
||||
return new RequestBuilder(StandardMethods.DELETE, uri);
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 4.4
|
||||
*/
|
||||
public static RequestBuilder delete(final String uri) {
|
||||
return new RequestBuilder(StandardMethods.DELETE, uri);
|
||||
}
|
||||
|
||||
public static RequestBuilder trace() {
|
||||
return new RequestBuilder(StandardMethods.TRACE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 4.4
|
||||
*/
|
||||
public static RequestBuilder trace(final URI uri) {
|
||||
return new RequestBuilder(StandardMethods.TRACE, uri);
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 4.4
|
||||
*/
|
||||
public static RequestBuilder trace(final String uri) {
|
||||
return new RequestBuilder(StandardMethods.TRACE, uri);
|
||||
}
|
||||
|
||||
public static RequestBuilder options() {
|
||||
return new RequestBuilder(StandardMethods.OPTIONS);
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 4.4
|
||||
*/
|
||||
public static RequestBuilder options(final URI uri) {
|
||||
return new RequestBuilder(StandardMethods.OPTIONS, uri);
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 4.4
|
||||
*/
|
||||
public static RequestBuilder options(final String uri) {
|
||||
return new RequestBuilder(StandardMethods.OPTIONS, uri);
|
||||
}
|
||||
|
||||
public static RequestBuilder copy(final ClassicHttpRequest request) {
|
||||
Args.notNull(request, "HTTP request");
|
||||
return new RequestBuilder().doCopy(request);
|
||||
}
|
||||
|
||||
private RequestBuilder doCopy(final ClassicHttpRequest request) {
|
||||
if (request == null) {
|
||||
return this;
|
||||
}
|
||||
method = request.getMethod();
|
||||
version = request.getVersion();
|
||||
|
||||
if (headerGroup == null) {
|
||||
headerGroup = new HeaderGroup();
|
||||
}
|
||||
headerGroup.clear();
|
||||
headerGroup.setHeaders(request.getHeaders());
|
||||
|
||||
parameters = null;
|
||||
entity = null;
|
||||
|
||||
final HttpEntity originalEntity = request.getEntity();
|
||||
if (originalEntity != null) {
|
||||
final ContentType contentType = ContentType.parse(originalEntity.getContentType());
|
||||
if (contentType != null &&
|
||||
contentType.getMimeType().equals(ContentType.APPLICATION_FORM_URLENCODED.getMimeType())) {
|
||||
try {
|
||||
final List<NameValuePair> formParams = EntityUtils.parse(originalEntity);
|
||||
if (!formParams.isEmpty()) {
|
||||
parameters = formParams;
|
||||
}
|
||||
} catch (final IOException ignore) {
|
||||
}
|
||||
} else {
|
||||
entity = originalEntity;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
uri = request.getUri();
|
||||
} catch (final URISyntaxException ignore) {
|
||||
}
|
||||
if (request instanceof Configurable) {
|
||||
config = ((Configurable) request).getConfig();
|
||||
} else {
|
||||
config = null;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 4.4
|
||||
*/
|
||||
public RequestBuilder setCharset(final Charset charset) {
|
||||
this.charset = charset;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 4.4
|
||||
*/
|
||||
public Charset getCharset() {
|
||||
return charset;
|
||||
}
|
||||
|
||||
public String getMethod() {
|
||||
return method;
|
||||
}
|
||||
|
||||
public ProtocolVersion getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public RequestBuilder setVersion(final ProtocolVersion version) {
|
||||
this.version = version;
|
||||
return this;
|
||||
}
|
||||
|
||||
public URI getUri() {
|
||||
return uri;
|
||||
}
|
||||
|
||||
public RequestBuilder setUri(final URI uri) {
|
||||
this.uri = uri;
|
||||
return this;
|
||||
}
|
||||
|
||||
public RequestBuilder setUri(final String uri) {
|
||||
this.uri = uri != null ? URI.create(uri) : null;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Header getFirstHeader(final String name) {
|
||||
return headerGroup != null ? headerGroup.getFirstHeader(name) : null;
|
||||
}
|
||||
|
||||
public Header getLastHeader(final String name) {
|
||||
return headerGroup != null ? headerGroup.getLastHeader(name) : null;
|
||||
}
|
||||
|
||||
public Header[] getHeaders(final String name) {
|
||||
return headerGroup != null ? headerGroup.getHeaders(name) : null;
|
||||
}
|
||||
|
||||
public RequestBuilder addHeader(final Header header) {
|
||||
if (headerGroup == null) {
|
||||
headerGroup = new HeaderGroup();
|
||||
}
|
||||
headerGroup.addHeader(header);
|
||||
return this;
|
||||
}
|
||||
|
||||
public RequestBuilder addHeader(final String name, final String value) {
|
||||
if (headerGroup == null) {
|
||||
headerGroup = new HeaderGroup();
|
||||
}
|
||||
this.headerGroup.addHeader(new BasicHeader(name, value));
|
||||
return this;
|
||||
}
|
||||
|
||||
public RequestBuilder removeHeader(final Header header) {
|
||||
if (headerGroup == null) {
|
||||
headerGroup = new HeaderGroup();
|
||||
}
|
||||
headerGroup.removeHeader(header);
|
||||
return this;
|
||||
}
|
||||
|
||||
public RequestBuilder removeHeaders(final String name) {
|
||||
if (name == null || headerGroup == null) {
|
||||
return this;
|
||||
}
|
||||
for (final Iterator<Header> i = headerGroup.headerIterator(); i.hasNext(); ) {
|
||||
final Header header = i.next();
|
||||
if (name.equalsIgnoreCase(header.getName())) {
|
||||
i.remove();
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public RequestBuilder setHeader(final Header header) {
|
||||
if (headerGroup == null) {
|
||||
headerGroup = new HeaderGroup();
|
||||
}
|
||||
this.headerGroup.setHeader(header);
|
||||
return this;
|
||||
}
|
||||
|
||||
public RequestBuilder setHeader(final String name, final String value) {
|
||||
if (headerGroup == null) {
|
||||
headerGroup = new HeaderGroup();
|
||||
}
|
||||
this.headerGroup.setHeader(new BasicHeader(name, value));
|
||||
return this;
|
||||
}
|
||||
|
||||
public HttpEntity getEntity() {
|
||||
return entity;
|
||||
}
|
||||
|
||||
public RequestBuilder setEntity(final HttpEntity entity) {
|
||||
this.entity = entity;
|
||||
return this;
|
||||
}
|
||||
|
||||
public List<NameValuePair> getParameters() {
|
||||
return parameters != null ? new ArrayList<>(parameters) :
|
||||
new ArrayList<NameValuePair>();
|
||||
}
|
||||
|
||||
public RequestBuilder addParameter(final NameValuePair nvp) {
|
||||
Args.notNull(nvp, "Name value pair");
|
||||
if (parameters == null) {
|
||||
parameters = new LinkedList<>();
|
||||
}
|
||||
parameters.add(nvp);
|
||||
return this;
|
||||
}
|
||||
|
||||
public RequestBuilder addParameter(final String name, final String value) {
|
||||
return addParameter(new BasicNameValuePair(name, value));
|
||||
}
|
||||
|
||||
public RequestBuilder addParameters(final NameValuePair... nvps) {
|
||||
for (final NameValuePair nvp: nvps) {
|
||||
addParameter(nvp);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public RequestConfig getConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
public RequestBuilder setConfig(final RequestConfig config) {
|
||||
this.config = config;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ClassicHttpRequest build() {
|
||||
URI uriNotNull = this.uri != null ? this.uri : URI.create("/");
|
||||
HttpEntity entityCopy = this.entity;
|
||||
if (parameters != null && !parameters.isEmpty()) {
|
||||
if (entityCopy == null && (StandardMethods.POST.name().equalsIgnoreCase(method)
|
||||
|| StandardMethods.PUT.name().equalsIgnoreCase(method))) {
|
||||
entityCopy = new UrlEncodedFormEntity(parameters, charset != null ? charset : StandardCharsets.ISO_8859_1);
|
||||
} else {
|
||||
try {
|
||||
uriNotNull = new URIBuilder(uriNotNull)
|
||||
.setCharset(this.charset)
|
||||
.addParameters(parameters)
|
||||
.build();
|
||||
} catch (final URISyntaxException ex) {
|
||||
// should never happen
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (entityCopy != null && StandardMethods.TRACE.name().equalsIgnoreCase(method)) {
|
||||
throw new IllegalStateException(StandardMethods.TRACE.name() + " requests may not include an entity.");
|
||||
}
|
||||
|
||||
final HttpUriRequestBase result = new HttpUriRequestBase(method, uriNotNull);
|
||||
result.setVersion(this.version != null ? this.version : HttpVersion.HTTP_1_1);
|
||||
if (this.headerGroup != null) {
|
||||
result.setHeaders(this.headerGroup.getHeaders());
|
||||
}
|
||||
result.setEntity(entityCopy);
|
||||
result.setConfig(this.config);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
builder.append("RequestBuilder [method=");
|
||||
builder.append(method);
|
||||
builder.append(", charset=");
|
||||
builder.append(charset);
|
||||
builder.append(", version=");
|
||||
builder.append(version);
|
||||
builder.append(", uri=");
|
||||
builder.append(uri);
|
||||
builder.append(", headerGroup=");
|
||||
builder.append(headerGroup);
|
||||
builder.append(", entity=");
|
||||
builder.append(entity);
|
||||
builder.append(", parameters=");
|
||||
builder.append(parameters);
|
||||
builder.append(", config=");
|
||||
builder.append(config);
|
||||
builder.append("]");
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,76 +0,0 @@
|
|||
/*
|
||||
* ====================================================================
|
||||
* 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.hc.client5.http.ssl;
|
||||
|
||||
import org.apache.hc.core5.http.ParseException;
|
||||
import org.apache.hc.core5.http.ProtocolVersion;
|
||||
|
||||
/**
|
||||
* Supported {@code TLS} protocol versions.
|
||||
*
|
||||
* @since 5.0
|
||||
*
|
||||
* @deprecated Use {@link org.apache.hc.core5.http.ssl.TLS}
|
||||
*/
|
||||
@Deprecated
|
||||
public enum TLS {
|
||||
|
||||
V_1_0("TLSv1", new ProtocolVersion("TLS", 1, 0)),
|
||||
V_1_1("TLSv1.1", new ProtocolVersion("TLS", 1, 1)),
|
||||
V_1_2("TLSv1.2", new ProtocolVersion("TLS", 1, 2)),
|
||||
V_1_3("TLSv1.3", new ProtocolVersion("TLS", 1, 3));
|
||||
|
||||
public final String ident;
|
||||
public final ProtocolVersion version;
|
||||
|
||||
TLS(final String ident, final ProtocolVersion version) {
|
||||
this.ident = ident;
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public boolean isSame(final ProtocolVersion protocolVersion) {
|
||||
return version.equals(protocolVersion);
|
||||
}
|
||||
|
||||
public boolean isComparable(final ProtocolVersion protocolVersion) {
|
||||
return version.isComparable(protocolVersion);
|
||||
}
|
||||
|
||||
public boolean greaterEquals(final ProtocolVersion protocolVersion) {
|
||||
return version.greaterEquals(protocolVersion);
|
||||
}
|
||||
|
||||
public boolean lessEquals(final ProtocolVersion protocolVersion) {
|
||||
return version.lessEquals(protocolVersion);
|
||||
}
|
||||
|
||||
public static ProtocolVersion parse(final String s) throws ParseException {
|
||||
return org.apache.hc.core5.http.ssl.TLS.parse(s);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue