Package net.officefloor.server.http
Class HttpClientTestUtil
- java.lang.Object
-
- net.officefloor.server.http.HttpClientTestUtil
-
public class HttpClientTestUtil extends java.lang.Object
Utility class aiding in testing HTTP functionality.- Author:
- Daniel Sagenschneider
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
PROPERTY_NO_TIMEOUT
System
property configured totrue
to not time outHttpClient
instances.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static org.apache.http.client.CredentialsProvider
configureCredentials(org.apache.http.impl.client.HttpClientBuilder builder, java.lang.String realm, java.lang.String scheme, java.lang.String username, java.lang.String password)
ConfiguresCredentialsProvider
for theHttpClientBuilder
.static void
configureHttps(org.apache.http.impl.client.HttpClientBuilder builder)
Configures theHttpClientBuilder
for HTTPS.static void
configureNoRedirects(org.apache.http.impl.client.HttpClientBuilder builder)
Configures no redirects for theHttpClientBuilder
.static org.apache.http.impl.client.CloseableHttpClient
createHttpClient()
Creates aCloseableHttpClient
ready for use with default values.static org.apache.http.impl.client.CloseableHttpClient
createHttpClient(boolean isSecure)
Creates aCloseableHttpClient
ready for use.static org.apache.http.impl.client.HttpClientBuilder
createHttpClientBuilder()
Create theHttpClientBuilder
.static org.apache.http.impl.client.HttpClientBuilder
createHttpClientBuilder(int timeout)
Create theHttpClientBuilder
.static java.lang.String
entityToString(org.apache.http.HttpResponse response)
Obtains theHttpEntity
content.static java.lang.String
entityToString(org.apache.http.HttpResponse response, java.nio.charset.Charset charset)
Obtains theHttpEntity
content.static int
getClientTimeout()
Obtains the client time out.
-
-
-
Field Detail
-
PROPERTY_NO_TIMEOUT
public static final java.lang.String PROPERTY_NO_TIMEOUT
System
property configured totrue
to not time outHttpClient
instances. This is useful for debugging server handling of requests.- See Also:
- Constant Field Values
-
-
Method Detail
-
getClientTimeout
public static int getClientTimeout()
Obtains the client time out.- Returns:
- Client time out.
-
entityToString
public static java.lang.String entityToString(org.apache.http.HttpResponse response) throws java.io.IOException
Obtains theHttpEntity
content.- Parameters:
response
-HttpResponse
.- Returns:
- Content of
HttpEntity
. - Throws:
java.io.IOException
- If fails to obtain content.
-
entityToString
public static java.lang.String entityToString(org.apache.http.HttpResponse response, java.nio.charset.Charset charset) throws java.io.IOException
Obtains theHttpEntity
content.- Parameters:
response
-HttpResponse
.charset
-Charset
.- Returns:
- Content of
HttpEntity
. - Throws:
java.io.IOException
- If fails to obtain content.
-
createHttpClientBuilder
public static org.apache.http.impl.client.HttpClientBuilder createHttpClientBuilder()
Create theHttpClientBuilder
.- Returns:
HttpClientBuilder
.
-
createHttpClientBuilder
public static org.apache.http.impl.client.HttpClientBuilder createHttpClientBuilder(int timeout)
Create theHttpClientBuilder
.- Returns:
HttpClientBuilder
.
-
createHttpClient
public static org.apache.http.impl.client.CloseableHttpClient createHttpClient()
Creates aCloseableHttpClient
ready for use with default values.- Returns:
CloseableHttpClient
.
-
createHttpClient
public static org.apache.http.impl.client.CloseableHttpClient createHttpClient(boolean isSecure)
Creates aCloseableHttpClient
ready for use.- Parameters:
isSecure
- Indicate if require secure connection.- Returns:
CloseableHttpClient
.
-
configureHttps
public static void configureHttps(org.apache.http.impl.client.HttpClientBuilder builder)
Configures theHttpClientBuilder
for HTTPS.- Parameters:
builder
-HttpClientBuilder
.
-
configureNoRedirects
public static void configureNoRedirects(org.apache.http.impl.client.HttpClientBuilder builder)
Configures no redirects for theHttpClientBuilder
.- Parameters:
builder
-HttpClientBuilder
.
-
configureCredentials
public static org.apache.http.client.CredentialsProvider configureCredentials(org.apache.http.impl.client.HttpClientBuilder builder, java.lang.String realm, java.lang.String scheme, java.lang.String username, java.lang.String password)
ConfiguresCredentialsProvider
for theHttpClientBuilder
.- Parameters:
builder
-HttpClientBuilder
.realm
- Security realm.scheme
- Security scheme.username
- User name.password
- Password.- Returns:
CredentialsProvider
.
-
-