Class RESTCall<M extends org.apache.http.client.methods.HttpRequestBase>

    • Constructor Detail

      • RESTCall

        protected RESTCall​(org.apache.http.client.HttpClient client,
                           M method)
      • RESTCall

        protected RESTCall​(M method)
    • Method Detail

      • getHttpClientWithTimeout

        public static org.apache.http.client.HttpClient getHttpClientWithTimeout​(String scheme)
        Parameters:
        scheme - target scheme for the REST call, e.g. 'http' or 'https', required to properly set up proxy settings
      • setMarshalledClasses

        public void setMarshalledClasses​(Class... classes)
                                  throws javax.xml.bind.JAXBException
        Throws:
        javax.xml.bind.JAXBException
      • marshal

        protected void marshal​(Object obj,
                               OutputStream out)
                        throws javax.xml.bind.JAXBException
        Throws:
        javax.xml.bind.JAXBException
      • unmarshal

        protected Object unmarshal​(InputStream in)
                            throws javax.xml.bind.JAXBException
        Throws:
        javax.xml.bind.JAXBException
      • unmarshal

        public <T> T unmarshal​(Class<T> responseType)
                        throws IOException,
                               javax.xml.bind.JAXBException
        Throws:
        IOException
        javax.xml.bind.JAXBException
      • setBasicCredentials

        public void setBasicCredentials​(String username,
                                        String password)
        Configured this call to use Basic HTTP Authentication using the specified username and password. This eliminates the need to manually encode the Basic authentication string in Authorization request header.
        Parameters:
        username -
        password -
      • addRequestHeader

        public void addRequestHeader​(String key,
                                     String value)
      • execute

        public void execute()
      • beforeExecute

        protected void beforeExecute()
      • getStatusCode

        public int getStatusCode()
      • getStatusLine

        public org.apache.http.StatusLine getStatusLine()
      • getResponseBody

        public byte[] getResponseBody()
        Returns the response body as a byte array.

        This assertion must be called after the call has been executed successfully, or it will fail the test.

        Returns:
        the response body as a byte array.
      • getResponseAsStream

        public InputStream getResponseAsStream()
      • getResponseAsString

        public String getResponseAsString()
      • getURI

        public URI getURI()
      • getResponseHeaders

        public com.google.common.collect.Multimap<String,​String> getResponseHeaders()
      • release

        public void release()
        Releases the resources held by the underlying HTTP request. Always call this method (e.g. in a finally clause) to ensure all HTTP connections are properly closed.
      • assertExecuted

        protected void assertExecuted()
      • assertNotExecuted

        protected void assertNotExecuted()
      • getMethod

        public M getMethod()