Skip to content
Permalink
Browse files
Simple message builders
  • Loading branch information
ok2c committed Mar 14, 2021
1 parent d944951 commit 1174c240e29ca4f5e0609583545e3e98b3a91263
Show file tree
Hide file tree
Showing 12 changed files with 1,229 additions and 7 deletions.
@@ -31,6 +31,7 @@
import org.apache.hc.client5.http.async.methods.SimpleBody;
import org.apache.hc.client5.http.async.methods.SimpleHttpRequest;
import org.apache.hc.client5.http.async.methods.SimpleHttpResponse;
import org.apache.hc.client5.http.async.methods.SimpleRequestBuilder;
import org.apache.hc.core5.http.ContentType;
import org.apache.hc.core5.http.EntityDetails;
import org.apache.hc.core5.http.HttpException;
@@ -63,11 +64,11 @@ protected SimpleHttpRequest buildResult(
final HttpRequest request,
final byte[] body,
final ContentType contentType) {
final SimpleHttpRequest simpleRequest = SimpleHttpRequest.copy(request);
final SimpleRequestBuilder builder = SimpleRequestBuilder.copy(request);
if (body != null) {
simpleRequest.setBody(body, contentType);
builder.setBody(body, contentType);
}
return simpleRequest;
return builder.build();
}

};
@@ -33,6 +33,7 @@
import org.apache.hc.client5.http.config.RequestConfig;
import org.apache.hc.core5.http.HttpHost;
import org.apache.hc.core5.http.message.BasicHttpRequest;
import org.apache.hc.core5.net.URIAuthority;

/**
* HTTP request message with a custom configuration.
@@ -52,6 +53,13 @@ public ConfigurableHttpRequest(final String method, final HttpHost host, final S
super(method, host, path);
}

/**
* @since 5.1
*/
public ConfigurableHttpRequest(final String method, final String scheme, final URIAuthority authority, final String path) {
super(method, scheme, authority, path);
}

public ConfigurableHttpRequest(final String method, final URI requestUri) {
super(method, requestUri);
}
@@ -99,8 +99,8 @@ public boolean isBytes() {

@Override
public String toString() {
return "content length=" + (bodyAsBytes != null ? bodyAsBytes.length : "chunked") +
", content type=" + contentType;
return "SimpleBody{content length=" + (bodyAsBytes != null ? bodyAsBytes.length : "chunked") +
", content type=" + contentType + "}";
}

}
@@ -35,6 +35,7 @@
import org.apache.hc.core5.http.HttpHost;
import org.apache.hc.core5.http.HttpRequest;
import org.apache.hc.core5.http.Method;
import org.apache.hc.core5.net.URIAuthority;
import org.apache.hc.core5.util.Args;

/**
@@ -49,6 +50,45 @@ public final class SimpleHttpRequest extends ConfigurableHttpRequest {
private static final long serialVersionUID = 1L;
private SimpleBody body;

/**
* @since 5.1
*/
public static SimpleHttpRequest create(final String method, final String uri) {
return new SimpleHttpRequest(method, uri);
}

/**
* @since 5.1
*/
public static SimpleHttpRequest create(final String method, final URI uri) {
return new SimpleHttpRequest(method, uri);
}

/**
* @since 5.1
*/
public static SimpleHttpRequest create(final Method method, final URI uri) {
return new SimpleHttpRequest(method, uri);
}

/**
* @since 5.1
*/
public static SimpleHttpRequest create(final Method method, final HttpHost host, final String path) {
return new SimpleHttpRequest(method, host, path);
}

/**
* @since 5.1
*/
public static SimpleHttpRequest create(final String method, final String scheme, final URIAuthority authority, final String path) {
return new SimpleHttpRequest(method, scheme, authority, path);
}

/**
* @deprecated Use {@link SimpleRequestBuilder}
*/
@Deprecated
public static SimpleHttpRequest copy(final HttpRequest original) {
Args.notNull(original, "HTTP request");
final SimpleHttpRequest copy = new SimpleHttpRequest(original.getMethod(), original.getRequestUri());
@@ -73,14 +113,27 @@ public SimpleHttpRequest(final String method, final URI requestUri) {
super(method, requestUri);
}

SimpleHttpRequest(final Method method, final URI requestUri) {
/**
* @since 5.1
*/
public SimpleHttpRequest(final Method method, final URI requestUri) {
this(method.name(), requestUri);
}

SimpleHttpRequest(final Method method, final HttpHost host, final String path) {
/**
* @since 5.1
*/
public SimpleHttpRequest(final Method method, final HttpHost host, final String path) {
this(method.name(), host, path);
}

/**
* @since 5.1
*/
public SimpleHttpRequest(final String method, final String scheme, final URIAuthority authority, final String path) {
super(method, scheme, authority, path);
}

public void setBody(final SimpleBody body) {
this.body = body;
}

0 comments on commit 1174c24

Please sign in to comment.