Class Request

java.lang.Object
com.dougnoel.sentinel.apis.Request

public class Request extends Object
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected 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
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addHeader(String name, String value)
    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
    Returns a URI that includes any parameters if it is set.
    void
    Construct a request, send it to the active API, and store the response for retrieval.
    protected void
    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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • log

      private static final org.apache.logging.log4j.Logger log
    • httpRequest

      protected org.apache.http.client.methods.HttpRequestBase httpRequest
    • parameters

      protected List<org.apache.http.NameValuePair> parameters
    • headers

      protected List<org.apache.http.NameValuePair> headers
    • body

      protected org.apache.http.HttpEntity body
    • bodyType

      protected HttpBodyType bodyType
  • Constructor Details

    • Request

      public Request()
  • Method Details

    • addParameter

      public void addParameter(String parameter, String value)
      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 passed
      value - 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

      public void addHeader(String name, String value)
      Set a header and its value for a request.
      Parameters:
      name - String the name being passed
      value - String the value to be passed
    • setBody

      public void setBody(String body)
      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

      public void createAndSendRequest(RequestType type, String endpoint)
      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 send
      endpoint - 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.