com.ibm.team.git.build.hjplugin.http
Class HttpUtils

java.lang.Object
  extended by com.ibm.team.git.build.hjplugin.http.HttpUtils

public class HttpUtils
extends Object

Collection of methods to handle authentication and providing the response back. For a GET, the caller supplies uri and gets JSON back. For a PUT, the caller supplies uri & any stream data.


Nested Class Summary
static class HttpUtils.RtcHttpResult
           
 
Constructor Summary
HttpUtils()
           
 
Method Summary
static org.apache.http.client.protocol.HttpClientContext createHttpContext()
          Creates and returns a new HttpContext with a new cookie store, for use with the singleton HTTP_CLIENT.
static org.apache.http.impl.client.CloseableHttpClient getClient()
          Because the creation of the SSLConnectionSocketFactory is expensive (reads from disk the certs file) we will cache the client.
static HttpUtils.RtcHttpResult performGet(String serverURI, String uri, String userId, String password, int timeout, org.apache.http.client.protocol.HttpClientContext httpContext, hudson.model.TaskListener listener)
          Perform GET request against an RTC server
static HttpUtils.RtcHttpResult performPost(String serverURI, String uri, String userId, String password, int timeout, List<org.apache.http.NameValuePair> params, hudson.model.TaskListener listener, org.apache.http.client.protocol.HttpClientContext httpContext)
           
static org.apache.http.client.protocol.HttpClientContext performPut(String serverURI, String uri, String userId, String password, int timeout, net.sf.json.JSONObject json, org.apache.http.client.protocol.HttpClientContext httpContext, hudson.model.TaskListener listener)
          Perform PUT request against an RTC server
static void validateCredentials(String serverURI, String userId, String password, int timeout, org.apache.http.client.protocol.HttpClientContext httpContext)
          Only used to test connection.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HttpUtils

public HttpUtils()
Method Detail

performPost

public static HttpUtils.RtcHttpResult performPost(String serverURI,
                                                  String uri,
                                                  String userId,
                                                  String password,
                                                  int timeout,
                                                  List<org.apache.http.NameValuePair> params,
                                                  hudson.model.TaskListener listener,
                                                  org.apache.http.client.protocol.HttpClientContext httpContext)
                                           throws IOException,
                                                  org.apache.http.auth.InvalidCredentialsException,
                                                  GeneralSecurityException
Throws:
IOException
org.apache.http.auth.InvalidCredentialsException
GeneralSecurityException

performGet

public static HttpUtils.RtcHttpResult performGet(String serverURI,
                                                 String uri,
                                                 String userId,
                                                 String password,
                                                 int timeout,
                                                 org.apache.http.client.protocol.HttpClientContext httpContext,
                                                 hudson.model.TaskListener listener)
                                          throws IOException,
                                                 org.apache.http.auth.InvalidCredentialsException,
                                                 GeneralSecurityException
Perform GET request against an RTC server

Parameters:
serverURI - The RTC server
uri - The relative URI for the GET. It is expected it is already encoded if necessary.
userId - The userId to authenticate as
password - The password to authenticate with
timeout - The timeout period for the connection (in seconds)
httpContext - The context from the login if cycle is being managed by the caller Otherwise null and this call will handle the login.
listener - The listener to report errors to. May be null
Returns:
Result of the GET (JSON response)
Throws:
IOException - Thrown if things go wrong
org.apache.http.auth.InvalidCredentialsException
GeneralSecurityException

performPut

public static org.apache.http.client.protocol.HttpClientContext performPut(String serverURI,
                                                                           String uri,
                                                                           String userId,
                                                                           String password,
                                                                           int timeout,
                                                                           net.sf.json.JSONObject json,
                                                                           org.apache.http.client.protocol.HttpClientContext httpContext,
                                                                           hudson.model.TaskListener listener)
                                                                    throws IOException,
                                                                           org.apache.http.auth.InvalidCredentialsException,
                                                                           GeneralSecurityException
Perform PUT request against an RTC server

Parameters:
serverURI - The RTC server
uri - The relative URI for the PUT. It is expected that it is already encoded if necessary.
userId - The userId to authenticate as
password - The password to authenticate with
timeout - The timeout period for the connection (in seconds)
json - The JSON object to put to the RTC server
httpContext - The context from the login if cycle is being managed by the caller Otherwise null and this call will handle the login.
listener - The listener to report errors to. May be null if there is no listener.
Returns:
The HttpContext for the request. May be reused in subsequent requests for the same user
Throws:
IOException - Thrown if things go wrong
org.apache.http.auth.InvalidCredentialsException
GeneralSecurityException

validateCredentials

public static void validateCredentials(String serverURI,
                                       String userId,
                                       String password,
                                       int timeout,
                                       org.apache.http.client.protocol.HttpClientContext httpContext)
                                throws IOException,
                                       GeneralSecurityException,
                                       org.apache.http.auth.InvalidCredentialsException
Only used to test connection.

Parameters:
serverURI - The RTC server
userId - The userId to authenticate as
password - The password to authenticate with
timeout - The timeout period for the connection (in seconds)
Throws:
IOException - Thrown if things go wrong
org.apache.http.auth.InvalidCredentialsException - if authentication fails
GeneralSecurityException

getClient

public static org.apache.http.impl.client.CloseableHttpClient getClient()
                                                                 throws GeneralSecurityException
Because the creation of the SSLConnectionSocketFactory is expensive (reads from disk the certs file) we will cache the client. The client is re-used so doesn't have any target RTC server info associated with it.

Returns:
an HttpClient
Throws:
GeneralSecurityException

createHttpContext

public static org.apache.http.client.protocol.HttpClientContext createHttpContext()
Creates and returns a new HttpContext with a new cookie store, for use with the singleton HTTP_CLIENT.

Returns:
a new HttpContext


Copyright © 2004-2014. All Rights Reserved.