ucar.nc2.util.net
Class HttpClientManager

java.lang.Object
  extended by ucar.nc2.util.net.HttpClientManager

public class HttpClientManager
extends java.lang.Object

Manage Http Client protocol settings.

 Example:
   org.apache.commons.httpclient.auth.CredentialsProvider provider = new thredds.ui.UrlAuthenticatorDialog(frame);
 ucar.nc2.util.net.HttpClientManager.init(provider, "ToolsUI");
 

Author:
caron

Constructor Summary
HttpClientManager()
           
 
Method Summary
static void clearState()
           
static java.lang.String getContent(java.lang.String urlString)
          Get the content from a url.
static org.apache.commons.httpclient.HttpClient getHttpClient()
          Get the HttpClient object - a single instance is used.
static org.apache.commons.httpclient.HttpClient init(org.apache.commons.httpclient.auth.CredentialsProvider provider, java.lang.String userAgent)
          initialize the HttpClient layer.
static int putContent(java.lang.String urlString, java.lang.String content)
          Put content to a url, using HTTP PUT.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HttpClientManager

public HttpClientManager()
Method Detail

init

public static org.apache.commons.httpclient.HttpClient init(org.apache.commons.httpclient.auth.CredentialsProvider provider,
                                                            java.lang.String userAgent)
initialize the HttpClient layer.

Parameters:
provider - CredentialsProvider.
userAgent - Content of User-Agent header, may be null

getHttpClient

public static org.apache.commons.httpclient.HttpClient getHttpClient()
Get the HttpClient object - a single instance is used.

Returns:
the HttpClient object

clearState

public static void clearState()

getContent

public static java.lang.String getContent(java.lang.String urlString)
                                   throws java.io.IOException
Get the content from a url. For large returns, its better to use getResponseAsStream.

Parameters:
urlString - url as a String
Returns:
contents of url as a String
Throws:
java.io.IOException - on error

putContent

public static int putContent(java.lang.String urlString,
                             java.lang.String content)
                      throws java.io.IOException
Put content to a url, using HTTP PUT. Handles one level of 302 redirection.

Parameters:
urlString - url as a String
content - PUT this content at the given url.
Returns:
the HTTP status return code
Throws:
java.io.IOException - on error