Package net.officefloor.server.http
Class AbstractHttpClientJUnit<T>
- java.lang.Object
-
- net.officefloor.server.http.AbstractHttpClientJUnit<T>
-
- Direct Known Subclasses:
HttpClientExtension
,HttpClientRule
public abstract class AbstractHttpClientJUnit<T> extends java.lang.Object
AbstractHttpClient
toHttpServer
.- Author:
- Daniel Sagenschneider
-
-
Constructor Summary
Constructors Constructor Description AbstractHttpClientJUnit()
Instantiate for non-secure (HTTP) connection toHttpServer
.AbstractHttpClientJUnit(boolean isSecure)
Instantiate with flagging if secure (HTTPS) connection toHttpServer
.AbstractHttpClientJUnit(boolean isSecure, int port)
Instantiate indicating the server port.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
closeHttpClient()
Closes theHttpClient
.org.apache.http.HttpResponse
execute(org.apache.http.client.methods.HttpUriRequest request)
Convenience method to execute theHttpUriRequest
.T
followRedirects(boolean isFollowRedirects)
Flags whether to follow redirects.org.apache.http.client.HttpClient
getHttpClient()
Obtains theHttpClient
.protected void
openHttpClient()
Opens theCloseableHttpClient
.T
timeout(int timeout)
Specifies the request timeout in milliseconds.java.lang.String
url(java.lang.String path)
Creates URL to the server.
-
-
-
Constructor Detail
-
AbstractHttpClientJUnit
public AbstractHttpClientJUnit()
Instantiate for non-secure (HTTP) connection toHttpServer
.
-
AbstractHttpClientJUnit
public AbstractHttpClientJUnit(boolean isSecure)
Instantiate with flagging if secure (HTTPS) connection toHttpServer
.- Parameters:
isSecure
- Indicates if secure (HTTPS).
-
AbstractHttpClientJUnit
public AbstractHttpClientJUnit(boolean isSecure, int port)
Instantiate indicating the server port.- Parameters:
isSecure
- Indicates if secure (HTTPS).port
- Server port to connect.
-
-
Method Detail
-
followRedirects
public T followRedirects(boolean isFollowRedirects)
Flags whether to follow redirects.- Parameters:
isFollowRedirects
- Indicates if follow redirects.- Returns:
this
.
-
timeout
public T timeout(int timeout)
Specifies the request timeout in milliseconds.- Parameters:
timeout
- Time out.- Returns:
this
.
-
getHttpClient
public org.apache.http.client.HttpClient getHttpClient()
Obtains theHttpClient
.- Returns:
HttpClient
.
-
url
public java.lang.String url(java.lang.String path)
Creates URL to the server.- Parameters:
path
- Path on the server.- Returns:
- URL to the server.
-
execute
public org.apache.http.HttpResponse execute(org.apache.http.client.methods.HttpUriRequest request) throws java.io.IOException, org.apache.http.client.ClientProtocolException
Convenience method to execute theHttpUriRequest
.- Parameters:
request
-HttpUriRequest
.- Returns:
HttpResponse
.- Throws:
java.io.IOException
- If failure in communication with server.org.apache.http.client.ClientProtocolException
- If client protocol issue.
-
openHttpClient
protected void openHttpClient()
Opens theCloseableHttpClient
.
-
closeHttpClient
protected void closeHttpClient() throws java.io.IOException
Closes theHttpClient
.- Throws:
java.io.IOException
- If fails to close theHttpClient
.
-
-