com.atlassian.sal.core.net
Class HttpClientRequest

java.lang.Object
  extended by com.atlassian.sal.core.net.HttpClientRequest
All Implemented Interfaces:
Request<HttpClientRequest,HttpClientResponse>

public class HttpClientRequest
extends Object
implements Request<HttpClientRequest,HttpClientResponse>

HttpClient implementation of Request interface


Nested Class Summary
 
Nested classes/interfaces inherited from interface com.atlassian.sal.api.net.Request
Request.MethodType
 
Field Summary
static int MAX_REDIRECTS
           
 
Constructor Summary
HttpClientRequest(org.apache.commons.httpclient.HttpClient httpClient, Request.MethodType methodType, String url, CertificateFactory certificateFactory, UserManager userManager)
           
 
Method Summary
 HttpClientRequest addAuthentication(Authenticator authenticator)
          Adds generic Authenticator to the request.
 HttpClientRequest addBasicAuthentication(String username, String password)
          Adds basic authentication to the request.
 HttpClientRequest addHeader(String headerName, String headerValue)
          Adds the specified header to the request, not overwriting any previous value.
 HttpClientRequest addHeaders(String... params)
           
 HttpClientRequest addRequestParameters(String... params)
          Sets parameters of the request.
 HttpClientRequest addSeraphAuthentication(String username, String password)
          Adds seraph authentication to the request.
 HttpClientRequest addTrustedTokenAuthentication()
          Adds TrustedTokenAuthentication to the request.
 HttpClientRequest addTrustedTokenAuthentication(String username)
          Adds TrustedTokenAuthentication to the request.
 String execute()
          Executes a request and if response is successful, returns response as a string.
 void execute(ResponseHandler<HttpClientResponse> responseHandler)
          Executes the request.
<E> E
executeAndReturn(ReturningResponseHandler<HttpClientResponse,E> httpClientResponseResponseHandler)
          Executes the request and returns a result value.
 Map<String,List<String>> getHeaders()
           
 Request.MethodType getMethodType()
           
protected  org.apache.commons.httpclient.HttpMethod makeMethod()
           
 HttpClientRequest setConnectionTimeout(int connectionTimeout)
          Setting connection timeout in milliseconds.
 HttpClientRequest setEntity(Object entity)
          Set an entity as the request body
 HttpClientRequest setHeader(String headerName, String headerValue)
          Sets the specified header to the request, overwriting any previous value.
 HttpClientRequest setRequestBody(String requestBody)
          Sets the body of the request.
 HttpClientRequest setRequestContentType(String requestContentType)
          Sets Content-Type of the body of the request.
 HttpClientRequest setSoTimeout(int soTimeout)
          Setting socket timeout in milliseconds.
 HttpClientRequest setUrl(String url)
           
static void shutdownStream(InputStream input)
          Unconditionally close an InputStream.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

MAX_REDIRECTS

public static final int MAX_REDIRECTS
See Also:
Constant Field Values
Constructor Detail

HttpClientRequest

public HttpClientRequest(org.apache.commons.httpclient.HttpClient httpClient,
                         Request.MethodType methodType,
                         String url,
                         CertificateFactory certificateFactory,
                         UserManager userManager)
Method Detail

setUrl

public HttpClientRequest setUrl(String url)
Specified by:
setUrl in interface Request<HttpClientRequest,HttpClientResponse>
Parameters:
url - the url to request
Returns:
a reference to this object.

addAuthentication

public HttpClientRequest addAuthentication(Authenticator authenticator)
Description copied from interface: Request
Adds generic Authenticator to the request.

Specified by:
addAuthentication in interface Request<HttpClientRequest,HttpClientResponse>
Parameters:
authenticator - the authenticator to use for authentication
Returns:
a reference to this object.

addTrustedTokenAuthentication

public HttpClientRequest addTrustedTokenAuthentication()
Description copied from interface: Request
Adds TrustedTokenAuthentication to the request. Trusted token authenticator uses current user to make a trusted application call.

Specified by:
addTrustedTokenAuthentication in interface Request<HttpClientRequest,HttpClientResponse>
Returns:
a reference to this object.

addTrustedTokenAuthentication

public HttpClientRequest addTrustedTokenAuthentication(String username)
Description copied from interface: Request
Adds TrustedTokenAuthentication to the request. Trusted token authenticator uses the passed user to make a trusted application call.

Specified by:
addTrustedTokenAuthentication in interface Request<HttpClientRequest,HttpClientResponse>
Parameters:
username - The user to make the request with
Returns:
this

addBasicAuthentication

public HttpClientRequest addBasicAuthentication(String username,
                                                String password)
Description copied from interface: Request
Adds basic authentication to the request.

Specified by:
addBasicAuthentication in interface Request<HttpClientRequest,HttpClientResponse>
Parameters:
username - The user name
password - The password
Returns:
a reference to this object.

addSeraphAuthentication

public HttpClientRequest addSeraphAuthentication(String username,
                                                 String password)
Description copied from interface: Request
Adds seraph authentication to the request.

Specified by:
addSeraphAuthentication in interface Request<HttpClientRequest,HttpClientResponse>
Parameters:
username - The user name
password - The password
Returns:
a reference to this object.

setConnectionTimeout

public HttpClientRequest setConnectionTimeout(int connectionTimeout)
Description copied from interface: Request
Setting connection timeout in milliseconds.

Specified by:
setConnectionTimeout in interface Request<HttpClientRequest,HttpClientResponse>
Parameters:
connectionTimeout - The timeout in milliseconds
Returns:
a reference to this object.

setSoTimeout

public HttpClientRequest setSoTimeout(int soTimeout)
Description copied from interface: Request
Setting socket timeout in milliseconds.

Specified by:
setSoTimeout in interface Request<HttpClientRequest,HttpClientResponse>
Parameters:
soTimeout - the timeout in milliseconds
Returns:
a reference to this object.

setRequestBody

public HttpClientRequest setRequestBody(String requestBody)
Description copied from interface: Request
Sets the body of the request. In default implementation only requests of type Request.MethodType.POST and Request.MethodType.POST can have request body.

Specified by:
setRequestBody in interface Request<HttpClientRequest,HttpClientResponse>
Parameters:
requestBody - the body of the request
Returns:
a reference to this object.

setEntity

public HttpClientRequest setEntity(Object entity)
Description copied from interface: Request
Set an entity as the request body

Specified by:
setEntity in interface Request<HttpClientRequest,HttpClientResponse>
Parameters:
entity - the request entity to be marshalled, not null
Returns:
this Request object

setRequestContentType

public HttpClientRequest setRequestContentType(String requestContentType)
Description copied from interface: Request
Sets Content-Type of the body of the request. In default implementation only requests of type Request.MethodType.POST and Request.MethodType.POST can have request body.

Specified by:
setRequestContentType in interface Request<HttpClientRequest,HttpClientResponse>
Parameters:
requestContentType - the contentType of the request
Returns:
a reference to this object.

addRequestParameters

public HttpClientRequest addRequestParameters(String... params)
Description copied from interface: Request
Sets parameters of the request. In default implementation only requests of type Request.MethodType.POST and Request.MethodType.POST can have parameters. For other requests include parameters in url. This method accepts an even number of arguments, in form of name, value, name, value, name, value, etc

Specified by:
addRequestParameters in interface Request<HttpClientRequest,HttpClientResponse>
Parameters:
params - parameters of the request in as name, value pairs
Returns:
a reference to this object.

addHeader

public HttpClientRequest addHeader(String headerName,
                                   String headerValue)
Description copied from interface: Request
Adds the specified header to the request, not overwriting any previous value. Support for this operation is optional.

Specified by:
addHeader in interface Request<HttpClientRequest,HttpClientResponse>
Parameters:
headerName - the header's name
headerValue - the header's value
Returns:
a reference to this object
See Also:
RequestFactory.supportsHeader()

setHeader

public HttpClientRequest setHeader(String headerName,
                                   String headerValue)
Description copied from interface: Request
Sets the specified header to the request, overwriting any previous value. Support for this operation is optional.

Specified by:
setHeader in interface Request<HttpClientRequest,HttpClientResponse>
Parameters:
headerName - the header's name
headerValue - the header's value
Returns:
a reference to this object
See Also:
RequestFactory.supportsHeader()

addHeaders

public HttpClientRequest addHeaders(String... params)

executeAndReturn

public <E> E executeAndReturn(ReturningResponseHandler<HttpClientResponse,E> httpClientResponseResponseHandler)
                   throws ResponseException
Description copied from interface: Request
Executes the request and returns a result value.

Specified by:
executeAndReturn in interface Request<HttpClientRequest,HttpClientResponse>
Parameters:
httpClientResponseResponseHandler - Callback handler of the response.
Throws:
ResponseException - If the response cannot be retrieved

execute

public void execute(ResponseHandler<HttpClientResponse> responseHandler)
             throws ResponseException
Description copied from interface: Request
Executes the request.

Specified by:
execute in interface Request<HttpClientRequest,HttpClientResponse>
Parameters:
responseHandler - Callback handler of the response.
Throws:
ResponseException - If the response cannot be retrieved

shutdownStream

public static void shutdownStream(InputStream input)
Unconditionally close an InputStream. Equivalent to InputStream.close(), except any exceptions will be ignored.

Parameters:
input - A (possibly null) InputStream

execute

public String execute()
               throws ResponseException
Description copied from interface: Request
Executes a request and if response is successful, returns response as a string. @see Response.getResponseBodyAsString()

Specified by:
execute in interface Request<HttpClientRequest,HttpClientResponse>
Returns:
response as String
Throws:
ResponseException - If the response cannot be retrieved

makeMethod

protected org.apache.commons.httpclient.HttpMethod makeMethod()

getHeaders

public Map<String,List<String>> getHeaders()
Specified by:
getHeaders in interface Request<HttpClientRequest,HttpClientResponse>
Returns:
an immutable Map of headers added to the request so far

getMethodType

public Request.MethodType getMethodType()

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2010 Atlassian. All Rights Reserved.