Package com.rapid7.appspider
Class HttpClientService
- java.lang.Object
-
- com.rapid7.appspider.HttpClientService
-
- All Implemented Interfaces:
ClientService
public class HttpClientService extends Object implements ClientService
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Optional<org.apache.http.client.methods.HttpGet>
buildGetAcceptionApplicatonJson(String endpoint, String authToken)
builds a HttpGet request object for the given endpoint using authToken as basic authentication header.Optional<org.apache.http.client.methods.HttpGet>
buildGetRequestUsingFormUrlEncoding(String endpoint, String authToken)
Builds a HttpGet request object for the endpoint given by endpoint using authToken as basic authentication headerOptional<org.apache.http.client.methods.HttpGet>
buildGetRequestUsingFormUrlEncoding(String endpoint, String authToken, org.apache.http.NameValuePair... params)
builds a HttpGet request object for the given endpoint using authToken as basic authentication header and params as additional URL key/value parametersOptional<org.apache.http.client.methods.HttpPost>
buildPostRequestUsingApplicationJson(String endpoint, org.apache.http.HttpEntity body)
builds a HttpPost request object for the given endpoint containing the provided body content body will be posted using Content-Type of application/jsonOptional<org.apache.http.client.methods.HttpPost>
buildPostRequestUsingFormUrlEncoding(String endpoint, String authToken, org.apache.http.NameValuePair... params)
builds a HttpPost request object for the given endpoint containing the provided body content body will be posted using Content-Type as application/x-www-form-urlencodedstatic HttpClientService
createInstanceOrThrow(org.apache.http.client.HttpClient httpClient, ContentHelper contentHelper, LoggerFacade logger)
Optional<org.apache.http.HttpEntity>
executeEntityRequest(org.apache.http.client.methods.HttpRequestBase request)
executes the provided HttpRequestBase returning the result as a HttpEntityOptional<org.json.JSONObject>
executeJsonRequest(org.apache.http.client.methods.HttpRequestBase request)
executes the provided HttpRequestBase returning the result as a JSONObject
-
-
-
Method Detail
-
createInstanceOrThrow
public static HttpClientService createInstanceOrThrow(org.apache.http.client.HttpClient httpClient, ContentHelper contentHelper, LoggerFacade logger)
-
executeJsonRequest
public Optional<org.json.JSONObject> executeJsonRequest(org.apache.http.client.methods.HttpRequestBase request)
executes the provided HttpRequestBase returning the result as a JSONObject- Specified by:
executeJsonRequest
in interfaceClientService
- Parameters:
request
- the request to send/execute- Returns:
- on success an Optional containing a JSONObject; otherwise, Optional.empty()
-
executeEntityRequest
public Optional<org.apache.http.HttpEntity> executeEntityRequest(org.apache.http.client.methods.HttpRequestBase request)
executes the provided HttpRequestBase returning the result as a HttpEntity- Parameters:
request
- the request to send/execute- Returns:
- on success an Optional containing a HttpEntity; otherwise, Optional.empty()
-
buildGetRequestUsingFormUrlEncoding
public Optional<org.apache.http.client.methods.HttpGet> buildGetRequestUsingFormUrlEncoding(String endpoint, String authToken)
Builds a HttpGet request object for the endpoint given by endpoint using authToken as basic authentication header- Specified by:
buildGetRequestUsingFormUrlEncoding
in interfaceClientService
- Parameters:
endpoint
- endpoint to perform get request onauthToken
- authorization token for basic authentication- Returns:
- Optional of HttpGet containing the request object
- Throws:
IllegalArgumentException
- when either endpoint or authToken are null or empty
-
buildGetRequestUsingFormUrlEncoding
public Optional<org.apache.http.client.methods.HttpGet> buildGetRequestUsingFormUrlEncoding(String endpoint, String authToken, org.apache.http.NameValuePair... params)
builds a HttpGet request object for the given endpoint using authToken as basic authentication header and params as additional URL key/value parameters- Specified by:
buildGetRequestUsingFormUrlEncoding
in interfaceClientService
- Parameters:
endpoint
- endpoint to perform get request onauthToken
- authorization token for basic authenticationparams
- name/value pairs encoded and added to endpoint- Returns:
- Optional of HttpGet containing the request object
- Throws:
IllegalArgumentException
- when either endpoint or authToken are null or empty
-
buildGetAcceptionApplicatonJson
public Optional<org.apache.http.client.methods.HttpGet> buildGetAcceptionApplicatonJson(String endpoint, String authToken)
builds a HttpGet request object for the given endpoint using authToken as basic authentication header. Request is sent using Content-Type and Accept as Application/json- Specified by:
buildGetAcceptionApplicatonJson
in interfaceClientService
- Parameters:
endpoint
- endpoint to perform get request onauthToken
- authorization token for basic authentication- Returns:
- Optional of HttpGet containing the request object
- Throws:
IllegalArgumentException
- when either endpoint or authToken are null or empty
-
buildPostRequestUsingApplicationJson
public Optional<org.apache.http.client.methods.HttpPost> buildPostRequestUsingApplicationJson(String endpoint, org.apache.http.HttpEntity body)
builds a HttpPost request object for the given endpoint containing the provided body content body will be posted using Content-Type of application/json- Specified by:
buildPostRequestUsingApplicationJson
in interfaceClientService
- Parameters:
endpoint
- endpoint to perform post request onbody
- JSON body to be sent with the request- Returns:
- Optional of HttpPost containg the request object
-
buildPostRequestUsingFormUrlEncoding
public Optional<org.apache.http.client.methods.HttpPost> buildPostRequestUsingFormUrlEncoding(String endpoint, String authToken, org.apache.http.NameValuePair... params)
builds a HttpPost request object for the given endpoint containing the provided body content body will be posted using Content-Type as application/x-www-form-urlencoded- Specified by:
buildPostRequestUsingFormUrlEncoding
in interfaceClientService
- Parameters:
endpoint
- endpoint to perform post request onauthToken
- authorization token for basic authenticationparams
- name/value pairs sent as the entity of the request- Returns:
- Optional of HttpPost containg the request object
-
-