Package com.dougnoel.sentinel.apis
Class Request
java.lang.Object
com.dougnoel.sentinel.apis.Request
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected org.apache.http.HttpEntity
protected HttpBodyType
protected List<org.apache.http.NameValuePair>
protected org.apache.http.client.methods.HttpRequestBase
private static final org.apache.logging.log4j.Logger
protected List<org.apache.http.NameValuePair>
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Set a header and its value for a request.void
addParameter
(String parameter, String value) Set a parameter and its value for a request.protected org.apache.http.client.methods.HttpRequestBase
buildURI()
Returns a URI that includes any parameters if it is set.void
createAndSendRequest
(RequestType type, String endpoint) Construct a request, send it to the active API, and store the response for retrieval.protected void
reset()
Reset all values so we can make a new request.protected void
Send the request, store the response for later retrieval, and reset the request so it can be used again by the API for another request.void
Creates a StringEntity to hold the json body.protected void
Sets this as a json request.void
setMultipartFormDataBody
(String nameOfInput, String boundary, InputStream inputStream, String filename) Sets the body to a multipart/form-data body, using the given name, boundary, input stream, and filename.
-
Field Details
-
log
private static final org.apache.logging.log4j.Logger log -
httpRequest
protected org.apache.http.client.methods.HttpRequestBase httpRequest -
parameters
-
headers
-
body
protected org.apache.http.HttpEntity body -
bodyType
-
-
Constructor Details
-
Request
public Request()
-
-
Method Details
-
addParameter
Set a parameter and its value for a request. They will show up as part of the query string in the API request.- Parameters:
parameter
- String the parameter being passedvalue
- String the value to be passed
-
buildURI
protected org.apache.http.client.methods.HttpRequestBase buildURI()Returns a URI that includes any parameters if it is set. Otherwise it returns the existing URI.- Returns:
- HttpRequestBase the new request object
-
setHeaders
protected void setHeaders()Sets this as a json request. -
addHeader
Set a header and its value for a request.- Parameters:
name
- String the name being passedvalue
- String the value to be passed
-
setBody
Creates a StringEntity to hold the json body.- Parameters:
body
- String the JSON to encode.
-
setMultipartFormDataBody
public void setMultipartFormDataBody(String nameOfInput, String boundary, InputStream inputStream, String filename) Sets the body to a multipart/form-data body, using the given name, boundary, input stream, and filename. Also sets a header with the Content-Type set to 'multipart/form-data' and specifies the boundary string passed to this method.- Parameters:
nameOfInput
- String name of the multipart segment. Sometimes applications require this parameter to be a specific value in order to accept file uploads.boundary
- String the multipart boundary. This method also adds a header specifying this value.inputStream
- InputStream input stream of the file to upload.filename
- String name of the file being uploaded.
-
createAndSendRequest
Construct a request, send it to the active API, and store the response for retrieval. Parameterization is handled at the cucumber step level.- Parameters:
type
- com.dougnoel.sentinel.enums.RequestType the type of request to sendendpoint
- the endpoint to send the request
-
sendRequest
protected void sendRequest()Send the request, store the response for later retrieval, and reset the request so it can be used again by the API for another request. -
reset
protected void reset()Reset all values so we can make a new request.
-