public class HttpTestUtil extends Object
Modifier and Type | Method and Description |
---|---|
static org.apache.http.client.CredentialsProvider |
configureCredentials(org.apache.http.impl.client.HttpClientBuilder builder,
String realm,
String scheme,
String username,
String password)
Configures
CredentialsProvider for the HttpClientBuilder . |
static void |
configureHttps(org.apache.http.impl.client.HttpClientBuilder builder)
Configures the
HttpClientBuilder for HTTPS. |
static void |
configureNoRedirects(org.apache.http.impl.client.HttpClientBuilder builder)
Configures no redirects for the
HttpClientBuilder . |
static org.apache.http.impl.client.CloseableHttpClient |
createHttpClient()
Creates a
CloseableHttpClient ready for use with default values. |
static org.apache.http.impl.client.CloseableHttpClient |
createHttpClient(boolean isSecure)
Creates a
CloseableHttpClient ready for use. |
static HttpRequest |
createHttpRequest(String method,
String requestUri,
String entity,
String... headerNameValues)
Creates a
HttpRequest
for testing. |
static int |
getAvailablePort()
Obtains the next port number for testing.
|
static String |
getEntityBody(org.apache.http.HttpResponse response)
Obtains the
HttpEntity content. |
static String |
getEntityBody(org.apache.http.HttpResponse response,
Charset charset)
Obtains the
HttpEntity content. |
static Class<? extends SslEngineSource> |
getSslEngineSourceClass()
Obtains the
SslEngineSource for the corresponding configured
HTTPS. |
public static int getAvailablePort()
public static String getEntityBody(org.apache.http.HttpResponse response) throws IOException
HttpEntity
content.response
- HttpResponse
.HttpEntity
.IOException
- If fails to obtain content.public static String getEntityBody(org.apache.http.HttpResponse response, Charset charset) throws IOException
HttpEntity
content.response
- HttpResponse
.charset
- Charset
.HttpEntity
.IOException
- If fails to obtain content.public static org.apache.http.impl.client.CloseableHttpClient createHttpClient()
CloseableHttpClient
ready for use with default values.CloseableHttpClient
.public static org.apache.http.impl.client.CloseableHttpClient createHttpClient(boolean isSecure)
CloseableHttpClient
ready for use.isSecure
- Indicate if require secure connection.CloseableHttpClient
.public static void configureHttps(org.apache.http.impl.client.HttpClientBuilder builder)
HttpClientBuilder
for HTTPS.builder
- HttpClientBuilder
.getSslEngineSourceClass()
public static void configureNoRedirects(org.apache.http.impl.client.HttpClientBuilder builder)
HttpClientBuilder
.builder
- HttpClientBuilder
.public static org.apache.http.client.CredentialsProvider configureCredentials(org.apache.http.impl.client.HttpClientBuilder builder, String realm, String scheme, String username, String password)
CredentialsProvider
for the HttpClientBuilder
.builder
- HttpClientBuilder
.realm
- Security realm.scheme
- Security scheme.username
- User name.password
- Password.CredentialsProvider
.public static Class<? extends SslEngineSource> getSslEngineSourceClass()
SslEngineSource
for the corresponding configured
HTTPS.SslEngineSource
for the corresponding configured HTTPS.configureHttps(HttpClientBuilder)
public static HttpRequest createHttpRequest(String method, String requestUri, String entity, String... headerNameValues) throws Exception
HttpRequest
for testing.method
- HTTP method (GET, POST).requestUri
- Request URI.entity
- Contents of the
HttpRequest
entity.headerNameValues
- HttpHeader
name values.HttpRequest
.Exception
- If fails to create the
HttpRequest
.Copyright © 2005–2016. All rights reserved.