KIE Remote Services :: Common 6.2.0.Final

org.kie.remote.common.rest
Class KieRemoteHttpRequest

java.lang.Object
  extended by org.kie.remote.common.rest.KieRemoteHttpRequest

public class KieRemoteHttpRequest
extends Object

This class is only meant to be used internally by the kie-remote-client code! For interacting with the REST API, please use a proper REST framework such as RestEasy or Apache CXF.

Using this class to interact with the REST API will not be supported and any issues or problems that arise from such use will be dismissed with a referral to this exact text!

A fluid interface for making HTTP requests using an underlying HttpURLConnection (or sub-class).

Each instance supports making a single request and cannot be reused for further requests. This code was originally copied from Kevin Sawicki's HttpRequest project * project.

However, it has been extensively modified and rewritten to fit the use case in this code.


Nested Class Summary
static interface KieRemoteHttpRequest.ConnectionFactory
          Creates HTTP connections for urls.
static class KieRemoteHttpRequest.RequestOutputStream
          Request output stream
 
Field Summary
static String CHARSET_UTF8
           
static String HEADER_PROXY_AUTHORIZATION
           
static String HEADER_REFERER
           
static String HEADER_SERVER
           
static String PARAM_CHARSET
           
 
Method Summary
 KieRemoteHttpRequest accept(String accept)
          Set the 'Accept' header to given value
 KieRemoteHttpRequest acceptCharset(String acceptCharset)
          Set the 'Accept-Charset' header to given value
 KieRemoteHttpRequest acceptEncoding(String acceptEncoding)
          Set the 'Accept-Encoding' header to given value
 KieRemoteHttpRequest basicAuthorization(String name, String password)
          Set the 'Authorization' header to given values in Basic authentication format
 KieRemoteHttpRequest body(CharSequence value)
           
 int bufferSize()
           
 KieRemoteHttpRequest bufferSize(int size)
           
 KieRemoteHttpRequest clone()
           
 KieRemoteHttpRequest contentType(String contentType)
          Set the 'Content-Type' request header to the given value
 KieRemoteHttpRequest contentType(String contentType, String charset)
          Set the 'Content-Type' request header to the given value and charset
 KieRemoteHttpRequest delete()
           
 KieRemoteHttpRequest delete(String relativeUrl)
           
static KieRemoteHttpRequest deleteRequest(URL url)
           
 KieRemoteHttpRequest disconnect()
           
 KieRemoteHttpRequest followRedirects(boolean followRedirects)
           
 KieRemoteHttpRequest followRedirets(boolean followRedirects)
           
 KieRemoteHttpRequest form(Map<?,?> values)
           
 KieRemoteHttpRequest form(Map<?,?> values, String charset)
           
 KieRemoteHttpRequest form(Object name, Object value)
           
 KieRemoteHttpRequest form(Object name, Object value, String charset)
           
 KieRemoteHttpRequest get()
           
 KieRemoteHttpRequest get(String relativeUrl)
           
 String getHeader(String name)
           
 String getMethod()
           
static KieRemoteHttpRequest getRequest(String urlString)
           
static KieRemoteHttpRequest getRequest(URL url)
           
 List<String> getRequestHeader(String headerName)
           
 URI getUri()
           
 URL getUrl()
           
 KieRemoteHttpRequest header(String name, Object value)
           
 KieRemoteHttpRequest headers(Map<String,String> headers)
           
 boolean ignoreCloseExceptions()
           
 KieRemoteHttpRequest ignoreCloseExceptions(boolean ignore)
           
static KieRemoteHttpRequest newRequest(String url)
           
static KieRemoteHttpRequest newRequest(String url, String username, String password)
           
static KieRemoteHttpRequest newRequest(URL url)
           
static KieRemoteHttpRequest newRequest(URL url, String username, String password)
           
 KieRemoteHttpRequest post()
           
 KieRemoteHttpRequest post(String relativeUrl)
           
static KieRemoteHttpRequest postRequest(URL url)
           
 KieRemoteHttpRequest proxyAuthorization(String proxyAuthorization)
          Set the 'Proxy-Authorization' header to given value
 KieRemoteHttpRequest proxyBasic(String name, String password)
          Set the 'Proxy-Authorization' header to given values in Basic authentication format
 KieRemoteHttpRequest put()
           
 KieRemoteHttpRequest put(String relativeUrl)
           
static KieRemoteHttpRequest putRequest(URL url)
           
 KieRemoteHttpRequest query(Map<?,?> values)
           
 KieRemoteHttpRequest query(Object name, Object value)
           
 KieRemoteHttpRequest relativeRequest(String relativeUrlString)
           
 KieRemoteHttpRequest relativeRequest(String relativeUrlString, String httpMethod)
           
 KieRemoteHttpRequest resetStream()
           
 KieRemoteHttpResponse response()
           
static void setKeepAlive(boolean keepAlive)
           
static void setMaxConnections(int maxConnections)
           
static void setNonProxyHosts(String... hosts)
           
static void setProxyHost(String host)
           
static void setProxyPort(int port)
           
 KieRemoteHttpRequest setUncompress(boolean uncompress)
          Set whether or not the response body should be automatically uncompressed when read from.
 KieRemoteHttpRequest timeout(long timeoutInMilliseconds)
           
 String toString()
           
 KieRemoteHttpRequest trustAllCerts()
          Configure HTTPS connection to trust all certificates This method does nothing if the current request is not a HTTPS request
 KieRemoteHttpRequest trustAllHosts()
          Configure HTTPS connection to trust all hosts using a custom HostnameVerifier that always returns true for each host verified This method does nothing if the current request is not a HTTPS request
 KieRemoteHttpRequest useProxy(String proxyHost, int proxyPort)
          Configure an HTTP proxy on this connection.
 OutputStreamWriter writer()
           
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

CHARSET_UTF8

public static final String CHARSET_UTF8
See Also:
Constant Field Values

HEADER_PROXY_AUTHORIZATION

public static final String HEADER_PROXY_AUTHORIZATION
See Also:
Constant Field Values

HEADER_REFERER

public static final String HEADER_REFERER
See Also:
Constant Field Values

HEADER_SERVER

public static final String HEADER_SERVER
See Also:
Constant Field Values

PARAM_CHARSET

public static final String PARAM_CHARSET
See Also:
Constant Field Values
Method Detail

setKeepAlive

public static void setKeepAlive(boolean keepAlive)

setMaxConnections

public static void setMaxConnections(int maxConnections)

deleteRequest

public static KieRemoteHttpRequest deleteRequest(URL url)
                                          throws KieRemoteHttpRequestException
Throws:
KieRemoteHttpRequestException

putRequest

public static KieRemoteHttpRequest putRequest(URL url)
                                       throws KieRemoteHttpRequestException
Throws:
KieRemoteHttpRequestException

getRequest

public static KieRemoteHttpRequest getRequest(String urlString)
                                       throws KieRemoteHttpRequestException
Throws:
KieRemoteHttpRequestException

getRequest

public static KieRemoteHttpRequest getRequest(URL url)
                                       throws KieRemoteHttpRequestException
Throws:
KieRemoteHttpRequestException

postRequest

public static KieRemoteHttpRequest postRequest(URL url)
                                        throws KieRemoteHttpRequestException
Throws:
KieRemoteHttpRequestException

newRequest

public static KieRemoteHttpRequest newRequest(String url)
                                       throws KieRemoteHttpRequestException
Throws:
KieRemoteHttpRequestException

newRequest

public static KieRemoteHttpRequest newRequest(URL url)
                                       throws KieRemoteHttpRequestException
Throws:
KieRemoteHttpRequestException

newRequest

public static KieRemoteHttpRequest newRequest(String url,
                                              String username,
                                              String password)
                                       throws KieRemoteHttpRequestException
Throws:
KieRemoteHttpRequestException

newRequest

public static KieRemoteHttpRequest newRequest(URL url,
                                              String username,
                                              String password)
                                       throws KieRemoteHttpRequestException
Throws:
KieRemoteHttpRequestException

get

public KieRemoteHttpRequest get(String relativeUrl)
                         throws KieRemoteHttpRequestException
Throws:
KieRemoteHttpRequestException

get

public KieRemoteHttpRequest get()
                         throws KieRemoteHttpRequestException
Throws:
KieRemoteHttpRequestException

post

public KieRemoteHttpRequest post(String relativeUrl)
                          throws KieRemoteHttpRequestException
Throws:
KieRemoteHttpRequestException

post

public KieRemoteHttpRequest post()
                          throws KieRemoteHttpRequestException
Throws:
KieRemoteHttpRequestException

put

public KieRemoteHttpRequest put(String relativeUrl)
                         throws KieRemoteHttpRequestException
Throws:
KieRemoteHttpRequestException

put

public KieRemoteHttpRequest put()
                         throws KieRemoteHttpRequestException
Throws:
KieRemoteHttpRequestException

delete

public KieRemoteHttpRequest delete(String relativeUrl)
                            throws KieRemoteHttpRequestException
Throws:
KieRemoteHttpRequestException

delete

public KieRemoteHttpRequest delete()
                            throws KieRemoteHttpRequestException
Throws:
KieRemoteHttpRequestException

ignoreCloseExceptions

public KieRemoteHttpRequest ignoreCloseExceptions(boolean ignore)

ignoreCloseExceptions

public boolean ignoreCloseExceptions()

bufferSize

public KieRemoteHttpRequest bufferSize(int size)

bufferSize

public int bufferSize()

setUncompress

public KieRemoteHttpRequest setUncompress(boolean uncompress)
Set whether or not the response body should be automatically uncompressed when read from.

This will only affect requests that have the 'Content-Encoding' response header set to 'gzip'.

This causes all receive methods to use a GZIPInputStream when applicable so that higher level streams and readers can read the data uncompressed.

Setting this option does not cause any request headers to be set automatically so #acceptGzipEncoding() should be used in conjunction with this setting to tell the server to gzip the response.

Parameters:
uncompress -
Returns:
this request

followRedirects

public KieRemoteHttpRequest followRedirects(boolean followRedirects)

getUri

public URI getUri()

timeout

public KieRemoteHttpRequest timeout(long timeoutInMilliseconds)

relativeRequest

public KieRemoteHttpRequest relativeRequest(String relativeUrlString,
                                            String httpMethod)

relativeRequest

public KieRemoteHttpRequest relativeRequest(String relativeUrlString)

disconnect

public KieRemoteHttpRequest disconnect()

resetStream

public KieRemoteHttpRequest resetStream()
                                 throws IOException
Throws:
IOException

followRedirets

public KieRemoteHttpRequest followRedirets(boolean followRedirects)

getUrl

public URL getUrl()

getMethod

public String getMethod()

getHeader

public String getHeader(String name)

header

public KieRemoteHttpRequest header(String name,
                                   Object value)

headers

public KieRemoteHttpRequest headers(Map<String,String> headers)

getRequestHeader

public List<String> getRequestHeader(String headerName)

acceptEncoding

public KieRemoteHttpRequest acceptEncoding(String acceptEncoding)
Set the 'Accept-Encoding' header to given value

Parameters:
acceptEncoding -
Returns:
this request

acceptCharset

public KieRemoteHttpRequest acceptCharset(String acceptCharset)
Set the 'Accept-Charset' header to given value

Parameters:
acceptCharset -
Returns:
this request

basicAuthorization

public KieRemoteHttpRequest basicAuthorization(String name,
                                               String password)
Set the 'Authorization' header to given values in Basic authentication format

Parameters:
name -
password -
Returns:
this request

contentType

public KieRemoteHttpRequest contentType(String contentType)
Set the 'Content-Type' request header to the given value

Parameters:
contentType -
Returns:
this request

contentType

public KieRemoteHttpRequest contentType(String contentType,
                                        String charset)
Set the 'Content-Type' request header to the given value and charset

Parameters:
contentType -
charset -
Returns:
this request

accept

public KieRemoteHttpRequest accept(String accept)
Set the 'Accept' header to given value

Parameters:
accept -
Returns:
this request

body

public KieRemoteHttpRequest body(CharSequence value)
                          throws KieRemoteHttpRequestException
Throws:
KieRemoteHttpRequestException

writer

public OutputStreamWriter writer()
                          throws KieRemoteHttpRequestException
Throws:
KieRemoteHttpRequestException

query

public KieRemoteHttpRequest query(Object name,
                                  Object value)
                           throws KieRemoteHttpRequestException
Throws:
KieRemoteHttpRequestException

query

public KieRemoteHttpRequest query(Map<?,?> values)
                           throws KieRemoteHttpRequestException
Throws:
KieRemoteHttpRequestException

form

public KieRemoteHttpRequest form(Object name,
                                 Object value,
                                 String charset)
                          throws KieRemoteHttpRequestException
Throws:
KieRemoteHttpRequestException

form

public KieRemoteHttpRequest form(Object name,
                                 Object value)
                          throws KieRemoteHttpRequestException
Throws:
KieRemoteHttpRequestException

form

public KieRemoteHttpRequest form(Map<?,?> values,
                                 String charset)
                          throws KieRemoteHttpRequestException
Throws:
KieRemoteHttpRequestException

form

public KieRemoteHttpRequest form(Map<?,?> values)
                          throws KieRemoteHttpRequestException
Throws:
KieRemoteHttpRequestException

response

public KieRemoteHttpResponse response()

trustAllCerts

public KieRemoteHttpRequest trustAllCerts()
                                   throws KieRemoteHttpRequestException
Configure HTTPS connection to trust all certificates

This method does nothing if the current request is not a HTTPS request

Returns:
this request
Throws:
KieRemoteHttpRequestException

trustAllHosts

public KieRemoteHttpRequest trustAllHosts()
Configure HTTPS connection to trust all hosts using a custom HostnameVerifier that always returns true for each host verified

This method does nothing if the current request is not a HTTPS request

Returns:
this request

setProxyHost

public static void setProxyHost(String host)

setProxyPort

public static void setProxyPort(int port)

setNonProxyHosts

public static void setNonProxyHosts(String... hosts)

useProxy

public KieRemoteHttpRequest useProxy(String proxyHost,
                                     int proxyPort)
Configure an HTTP proxy on this connection. Use {proxyBasic(String, String) if this proxy requires basic authentication.

Parameters:
proxyHost -
proxyPort -
Returns:
this request

proxyAuthorization

public KieRemoteHttpRequest proxyAuthorization(String proxyAuthorization)
Set the 'Proxy-Authorization' header to given value

Parameters:
proxyAuthorization -
Returns:
this request

proxyBasic

public KieRemoteHttpRequest proxyBasic(String name,
                                       String password)
Set the 'Proxy-Authorization' header to given values in Basic authentication format

Parameters:
name -
password -
Returns:
this request

toString

public String toString()
Overrides:
toString in class Object

clone

public KieRemoteHttpRequest clone()
Overrides:
clone in class Object

KIE Remote Services :: Common 6.2.0.Final

Copyright © 2001-2015 JBoss by Red Hat. All Rights Reserved.