Package net.officefloor.server.http
Class HttpClientTestUtil
java.lang.Object
net.officefloor.server.http.HttpClientTestUtil
Utility class aiding in testing HTTP functionality.
- Author:
- Daniel Sagenschneider
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic org.apache.http.client.CredentialsProviderconfigureCredentials(org.apache.http.impl.client.HttpClientBuilder builder, String realm, String scheme, String username, String password) ConfiguresCredentialsProviderfor theHttpClientBuilder.static voidconfigureHttps(org.apache.http.impl.client.HttpClientBuilder builder) Configures theHttpClientBuilderfor HTTPS.static voidconfigureNoRedirects(org.apache.http.impl.client.HttpClientBuilder builder) Configures no redirects for theHttpClientBuilder.static org.apache.http.impl.client.CloseableHttpClientCreates aCloseableHttpClientready for use with default values.static org.apache.http.impl.client.CloseableHttpClientcreateHttpClient(boolean isSecure) Creates aCloseableHttpClientready for use.static org.apache.http.impl.client.HttpClientBuilderCreate theHttpClientBuilder.static org.apache.http.impl.client.HttpClientBuildercreateHttpClientBuilder(int timeout) Create theHttpClientBuilder.static StringentityToString(org.apache.http.HttpResponse response) Obtains theHttpEntitycontent.static StringentityToString(org.apache.http.HttpResponse response, Charset charset) Obtains theHttpEntitycontent.static intObtains the client time out.
-
Field Details
-
PROPERTY_NO_TIMEOUT
Systemproperty configured totrueto not time outHttpClientinstances. This is useful for debugging server handling of requests.- See Also:
-
-
Method Details
-
getClientTimeout
public static int getClientTimeout()Obtains the client time out.- Returns:
- Client time out.
-
entityToString
Obtains theHttpEntitycontent.- Parameters:
response-HttpResponse.- Returns:
- Content of
HttpEntity. - Throws:
IOException- If fails to obtain content.
-
entityToString
public static String entityToString(org.apache.http.HttpResponse response, Charset charset) throws IOException Obtains theHttpEntitycontent.- Parameters:
response-HttpResponse.charset-Charset.- Returns:
- Content of
HttpEntity. - Throws:
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.- Parameters:
timeout- Timeout in milliseconds.- Returns:
HttpClientBuilder.
-
createHttpClient
public static org.apache.http.impl.client.CloseableHttpClient createHttpClient()Creates aCloseableHttpClientready for use with default values.- Returns:
CloseableHttpClient.
-
createHttpClient
public static org.apache.http.impl.client.CloseableHttpClient createHttpClient(boolean isSecure) Creates aCloseableHttpClientready for use.- Parameters:
isSecure- Indicate if require secure connection.- Returns:
CloseableHttpClient.
-
configureHttps
public static void configureHttps(org.apache.http.impl.client.HttpClientBuilder builder) Configures theHttpClientBuilderfor 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, String realm, String scheme, String username, String password) ConfiguresCredentialsProviderfor theHttpClientBuilder.- Parameters:
builder-HttpClientBuilder.realm- Security realm.scheme- Security scheme.username- User name.password- Password.- Returns:
CredentialsProvider.
-