org.apache.commons.httpclient

Class HttpMethodBase

Implemented Interfaces:
HttpMethod
Known Direct Subclasses:
ConnectMethod, DeleteMethod, ExpectContinueMethod, GetMethod, HeadMethod, OptionsMethod, TraceMethod

public abstract class HttpMethodBase
extends Object
implements HttpMethod

An abstract base implementation of HttpMethod.

At minimum, subclasses will need to override:

When a method requires additional request headers, subclasses will typically want to override:

When a method expects specific response headers, subclasses may want to override:

Field Summary

protected HttpVersion
effectiveVersion
HTTP protocol version used for execution of this method.
protected StatusLine
statusLine
The Status-Line from the response.

Constructor Summary

HttpMethodBase()
No-arg constructor.
HttpMethodBase(String uri)
Constructor specifying a URI.

Method Summary

void
abort()
Aborts the execution of this method.
protected void
addCookieRequestHeader(HttpState state, HttpConnection conn)
Generates Cookie request headers for those cookies that match the given host, port and path.
protected void
addHostRequestHeader(HttpState state, HttpConnection conn)
Generates Host request header, as long as no Host request header already exists.
protected void
addProxyConnectionHeader(HttpState state, HttpConnection conn)
Generates Proxy-Connection: Keep-Alive request header when communicating via a proxy server.
void
addRequestHeader(String headerName, String headerValue)
Adds the specified request header, NOT overwriting any previous value.
void
addRequestHeader(Header header)
Adds the specified request header, NOT overwriting any previous value.
protected void
addRequestHeaders(HttpState state, HttpConnection conn)
Generates all the required request headers to be submitted via the given connection.
void
addResponseFooter(Header footer)
Use this method internally to add footers.
protected void
addUserAgentRequestHeader(HttpState state, HttpConnection conn)
Generates default User-Agent request header, as long as no User-Agent request header already exists.
protected void
checkNotUsed()
Throws an IllegalStateException if the HTTP method has been already executed, but not recycled.
protected void
checkUsed()
Throws an IllegalStateException if the HTTP method has not been executed since last recycle.
int
execute(HttpState state, HttpConnection conn)
Executes this method using the specified HttpConnection and HttpState.
protected static String
generateRequestLine(HttpConnection connection, String name, String requestPath, String query, String version)
Generates HTTP request line according to the specified attributes.
String
getAuthenticationRealm()
Deprecated. use #getHostAuthState()
protected String
getContentCharSet(Header contentheader)
Returns the character set from the Content-Type header.
boolean
getDoAuthentication()
Returns true if the HTTP method should automatically handle HTTP authentication challenges (status code 401, etc.), false otherwise
HttpVersion
getEffectiveVersion()
Returns the HTTP version used with this method (may be null if undefined, that is, the method has not been executed)
boolean
getFollowRedirects()
Returns true if the HTTP method should automatically follow HTTP redirects (status code 302, etc.), false otherwise.
AuthState
getHostAuthState()
Returns the target host authentication state
HostConfiguration
getHostConfiguration()
Deprecated. no longer applicable
MethodRetryHandler
getMethodRetryHandler()
Deprecated. use HttpMethodParams
abstract String
getName()
Obtains the name of the HTTP method as used in the HTTP request line, for example "GET" or "POST".
HttpMethodParams
getParams()
Returns HTTP protocol parameters associated with this method.
String
getPath()
Gets the path of this HTTP method.
AuthState
getProxyAuthState()
Returns the proxy authentication state
String
getProxyAuthenticationRealm()
Deprecated. use #getProxyAuthState()
String
getQueryString()
Gets the query string of this HTTP method.
int
getRecoverableExceptionCount()
Deprecated. no longer used Returns the number of "recoverable" exceptions thrown and handled, to allow for monitoring the quality of the connection.
String
getRequestCharSet()
Returns the character encoding of the request from the Content-Type header.
Header
getRequestHeader(String headerName)
Returns the specified request header.
protected HeaderGroup
getRequestHeaderGroup()
Gets the header group storing the request headers.
Header[]
getRequestHeaders()
Returns an array of the requests headers that the HTTP method currently has
Header[]
getRequestHeaders(String headerName)
byte[]
getResponseBody()
Returns the response body of the HTTP method, if any, as an array of bytes.
byte[]
getResponseBody(int maxlen)
Returns the response body of the HTTP method, if any, as an array of bytes.
InputStream
getResponseBodyAsStream()
Returns the response body of the HTTP method, if any, as an InputStream.
String
getResponseBodyAsString()
Returns the response body of the HTTP method, if any, as a String.
String
getResponseBodyAsString(int maxlen)
Returns the response body of the HTTP method, if any, as a String.
String
getResponseCharSet()
Returns the character encoding of the response from the Content-Type header.
long
getResponseContentLength()
Return the length (in bytes) of the response body, as specified in a Content-Length header.
Header
getResponseFooter(String footerName)
Gets the response footer associated with the given name.
Header[]
getResponseFooters()
Returns an array of the response footers that the HTTP method currently has in the order in which they were read.
Header
getResponseHeader(String headerName)
Gets the response header associated with the given name.
protected HeaderGroup
getResponseHeaderGroup()
Gets the header group storing the response headers.
Header[]
getResponseHeaders()
Returns an array of the response headers that the HTTP method currently has in the order in which they were read.
Header[]
getResponseHeaders(String headerName)
protected InputStream
getResponseStream()
Returns a stream from which the body of the current response may be read.
protected HeaderGroup
getResponseTrailerHeaderGroup()
Gets the header group storing the response trailer headers as per RFC 2616 section 3.6.1.
int
getStatusCode()
Returns the response status code.
StatusLine
getStatusLine()
Provides access to the response status line.
String
getStatusText()
Returns the status text (or "reason phrase") associated with the latest response.
URI
getURI()
Returns the URI of the HTTP method
boolean
hasBeenUsed()
Returns true if the HTTP method has been already executed, but not recycled.
boolean
isAborted()
Tests whether the execution of this method has been aborted
protected boolean
isConnectionCloseForced()
Tests if the connection should be force-closed when no longer needed.
boolean
isHttp11()
Deprecated. Use HttpMethodParams.getVersion()
boolean
isRequestSent()
Returns true if the HTTP has been transmitted to the target server in its entirety, false otherwise.
boolean
isStrictMode()
Deprecated. Use HttpParams.setParameter(String,Object) to exercise a more granular control over HTTP protocol strictness.
protected void
processCookieHeaders(CookieSpec parser, Header[] headers, HttpState state, HttpConnection conn)
This method processes the specified cookie headers.
protected void
processResponseBody(HttpState state, HttpConnection conn)
This method is invoked immediately after readResponseBody(HttpState,HttpConnection) and can be overridden by sub-classes in order to provide custom body processing.
protected void
processResponseHeaders(HttpState state, HttpConnection conn)
This method is invoked immediately after readResponseHeaders(HttpState,HttpConnection) and can be overridden by sub-classes in order to provide custom response headers processing.
protected void
processStatusLine(HttpState state, HttpConnection conn)
This method is invoked immediately after readStatusLine(HttpState,HttpConnection) and can be overridden by sub-classes in order to provide custom response status line processing.
protected void
readResponse(HttpState state, HttpConnection conn)
Reads the response from the given connection.
protected void
readResponseBody(HttpState state, HttpConnection conn)
Read the response body from the given HttpConnection.
protected void
readResponseHeaders(HttpState state, HttpConnection conn)
Reads the response headers from the given connection.
protected void
readStatusLine(HttpState state, HttpConnection conn)
Read the status line from the given HttpConnection, setting my status code and status text.
void
recycle()
Deprecated. no longer supported and will be removed in the future version of HttpClient
void
releaseConnection()
Releases the connection being used by this HTTP method.
void
removeRequestHeader(String headerName)
Remove the request header associated with the given name.
void
removeRequestHeader(Header header)
Removes the given request header.
protected void
responseBodyConsumed()
A response has been consumed.
protected void
setConnectionCloseForced(boolean b)
Sets whether or not the connection should be force-closed when no longer needed.
void
setDoAuthentication(boolean doAuthentication)
Sets whether or not the HTTP method should automatically handle HTTP authentication challenges (status code 401, etc.)
void
setFollowRedirects(boolean followRedirects)
Sets whether or not the HTTP method should automatically follow HTTP redirects (status code 302, etc.)
void
setHostConfiguration(HostConfiguration hostconfig)
Deprecated. no longer applicable
void
setHttp11(boolean http11)
Deprecated. Use HttpMethodParams.setVersion(HttpVersion)
void
setMethodRetryHandler(MethodRetryHandler handler)
Deprecated. use HttpMethodParams
void
setParams(HttpMethodParams params)
Assigns HTTP protocol parameters for this method.
void
setPath(String path)
Sets the path of the HTTP method.
void
setQueryString(String queryString)
Sets the query string of this HTTP method.
void
setQueryString(NameValuePair[] params)
Sets the query string of this HTTP method.
void
setRequestHeader(String headerName, String headerValue)
Set the specified request header, overwriting any previous value.
void
setRequestHeader(Header header)
Sets the specified request header, overwriting any previous value.
protected void
setResponseStream(InputStream responseStream)
Sets the response stream.
void
setStrictMode(boolean strictMode)
Deprecated. Use HttpParams.setParameter(String,Object) to exercise a more granular control over HTTP protocol strictness.
void
setURI(URI uri)
Sets the URI for this method.
protected boolean
shouldCloseConnection(HttpConnection conn)
Tests if the connection should be closed after the method has been executed.
boolean
validate()
Returns true the method is ready to execute, false otherwise.
protected void
writeRequest(HttpState state, HttpConnection conn)
Sends the request via the given connection.
protected boolean
writeRequestBody(HttpState state, HttpConnection conn)
Writes the request body to the given connection.
protected void
writeRequestHeaders(HttpState state, HttpConnection conn)
Writes the request headers to the given connection.
protected void
writeRequestLine(HttpState state, HttpConnection conn)
Writes the request line to the given connection.

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Details

effectiveVersion

protected HttpVersion effectiveVersion
HTTP protocol version used for execution of this method.

statusLine

protected StatusLine statusLine
The Status-Line from the response.

Constructor Details

HttpMethodBase

public HttpMethodBase()
No-arg constructor.
Usages and Demos :

View More Examples of HttpMethodBase()
   1:             curi.putObject(CoreAttributeConstants.A_HTTP_TRANSACTION,
   2:                 new HttpMethodBase() {
   3:                     public String getName() {
   4:                         return this.getClass().getName() + "_method";
   5:                     }

View Full Code Here

HttpMethodBase

public HttpMethodBase(String uri)
            throws IllegalArgumentException,
                   IllegalStateException
Constructor specifying a URI. It is responsibility of the caller to ensure that URI elements (path & query parameters) are properly encoded (URL safe).
Parameters:
uri - either an absolute or relative URI. The URI is expected to be URL-encoded
Throws:
IllegalArgumentException - when URI is invalid
IllegalStateException - when protocol of the absolute URI is not recognised

Method Details

abort

public void abort()
Aborts the execution of this method.
Specified by:
abort in interface HttpMethod
Since:
3.0
Usages and Demos :

View More Examples of abort()
   1: import org.apache.commons.httpclient.HttpMethod;
   2: import org.apache.commons.httpclient.HttpMethodBase;
   3: import org.apache.commons.httpclient.HttpState;
   4:         ...
   5:         String curiString = curi.getUURI().toString();
   6:         HttpMethodBase method = null;
   7:         if (curi.isPost()) {
   8:         ...
   9:         curi.getHttpRecorder().close();
  10:         method.abort();
  11:     }
  12:         ...
  13:         try {
  14:             encoding = ((HttpMethodBase) method).getResponseCharSet();

View Full Code Here

addCookieRequestHeader

protected void addCookieRequestHeader(HttpState state,
                                      HttpConnection conn)
            throws IOException,
                   HttpException
Generates Cookie request headers for those cookies that match the given host, port and path.
Parameters:
state - the state information associated with this method
conn - the connection used to execute this HTTP method
Throws:
IOException - if an I/O (transport) error occurs. Some transport exceptions can be recovered from.
HttpException - if a protocol exception occurs. Usually protocol exceptions cannot be recovered from.

addHostRequestHeader

protected void addHostRequestHeader(HttpState state,
                                    HttpConnection conn)
            throws IOException,
                   HttpException
Generates Host request header, as long as no Host request header already exists.
Parameters:
state - the state information associated with this method
conn - the connection used to execute this HTTP method
Throws:
IOException - if an I/O (transport) error occurs. Some transport exceptions can be recovered from.
HttpException - if a protocol exception occurs. Usually protocol exceptions cannot be recovered from.

addProxyConnectionHeader

protected void addProxyConnectionHeader(HttpState state,
                                        HttpConnection conn)
            throws IOException,
                   HttpException
Generates Proxy-Connection: Keep-Alive request header when communicating via a proxy server.
Parameters:
state - the state information associated with this method
conn - the connection used to execute this HTTP method
Throws:
IOException - if an I/O (transport) error occurs. Some transport exceptions can be recovered from.
HttpException - if a protocol exception occurs. Usually protocol exceptions cannot be recovered from.

addRequestHeader

public void addRequestHeader(String headerName,
                             String headerValue)
Adds the specified request header, NOT overwriting any previous value. Note that header-name matching is case insensitive.
Specified by:
addRequestHeader in interface HttpMethod
Parameters:
headerName - the header's name
headerValue - the header's value
Usages and Demos :

View More Examples of addRequestHeader(String headerName,String headerValue)
   1: import org.apache.commons.httpclient.HttpClient;
   2: import org.apache.commons.httpclient.HttpMethodBase;
   3: import org.apache.commons.httpclient.methods.PostMethod;
   4:         ...
   5:     
   6:     protected HttpMethodBase getHttpMethod(HttpClient client, String uri, Map params, String formMethod, RenderRequest request) throws IOException
   7:     {
   8:         ...
   9:         HttpClient client = new HttpClient();
  10:         HttpMethodBase httpMethod = null;
  11:         httpMethod = new PostMethod();
  12:         ...
  13:         httpMethod.addRequestHeader( "User-Agent", "Firefox" );

View Full Code Here
   1: import org.apache.commons.httpclient.HttpException;
   2: import org.apache.commons.httpclient.HttpMethodBase;
   3: import org.apache.commons.httpclient.HttpStatus;
   4:         ...
   5:     
   6:     private void setHeaders(Map<String,String>headers, HttpMethodBase method) {
   7:         if (headers != null) {
   8:         ...
   9:             for (String key : headers.keySet()) {
  10:                 method.addRequestHeader(key, headers.get(key));
  11:             }

View Full Code Here
   1: import org.apache.commons.httpclient.HttpMethod;
   2: import org.apache.commons.httpclient.HttpMethodBase;
   3: import org.apache.commons.httpclient.NameValuePair;
   4:         ...
   5:             BufferedInputStream bis = new BufferedInputStream(httpMethod.getResponseBodyAsStream());
   6:             String encoding = ((HttpMethodBase)httpMethod).getResponseCharSet();
   7:             if (encoding == null)
   8:         ...
   9:     
  10:     protected HttpMethodBase getHttpMethod(HttpClient client, String uri, Map params, String formMethod, RenderRequest request) throws IOException
  11:     {
  12:         ...
  13:         
  14:         httpMethod.addRequestHeader( "User-Agent", useragentProperty );

View Full Code Here

addRequestHeader

public void addRequestHeader(Header header)
Adds the specified request header, NOT overwriting any previous value. Note that header-name matching is case insensitive.
Specified by:
addRequestHeader in interface HttpMethod
Parameters:
header - the header to add to the request
Usages and Demos :

View More Examples of addRequestHeader(Header header)
   1: import org.apache.commons.httpclient.HttpMethod;
   2: import org.apache.commons.httpclient.HttpMethodBase;
   3: import org.apache.commons.httpclient.HttpState;
   4:         ...
   5:         String curiString = curi.getUURI().toString();
   6:         HttpMethodBase method = null;
   7:         if (curi.isPost()) {
   8:         ...
   9:         try {
  10:             encoding = ((HttpMethodBase) method).getResponseCharSet();
  11:             if (encoding == null ||
  12:         ...
  13:                 ATTR_SEND_CONNECTION_CLOSE)).booleanValue()) {
  14:             method.addRequestHeader(HEADER_SEND_CONNECTION_CLOSE);

View Full Code Here

addRequestHeaders

protected void addRequestHeaders(HttpState state,
                                 HttpConnection conn)
            throws IOException,
                   HttpException
Generates all the required request headers to be submitted via the given connection.

This implementation adds User-Agent, Host, Cookie, Authorization, Proxy-Authorization and Proxy-Connection headers, when appropriate.

Subclasses may want to override this method to to add additional headers, and may choose to invoke this implementation (via super) to add the "standard" headers.

Parameters:
state - the state information associated with this method
conn - the connection used to execute this HTTP method
Throws:
IOException - if an I/O (transport) error occurs. Some transport exceptions can be recovered from.
HttpException - if a protocol exception occurs. Usually protocol exceptions cannot be recovered from.

addResponseFooter

public void addResponseFooter(Header footer)
Use this method internally to add footers.
Specified by:
addResponseFooter in interface HttpMethod
Parameters:
footer - The footer to add.

addUserAgentRequestHeader

protected void addUserAgentRequestHeader(HttpState state,
                                         HttpConnection conn)
            throws IOException,
                   HttpException
Generates default User-Agent request header, as long as no User-Agent request header already exists.
Parameters:
state - the state information associated with this method
conn - the connection used to execute this HTTP method
Throws:
IOException - if an I/O (transport) error occurs. Some transport exceptions can be recovered from.
HttpException - if a protocol exception occurs. Usually protocol exceptions cannot be recovered from.

checkNotUsed

protected void checkNotUsed()
            throws IllegalStateException
Throws an IllegalStateException if the HTTP method has been already executed, but not recycled.
Throws:
IllegalStateException - if the method has been used and not recycled

checkUsed

protected void checkUsed()
            throws IllegalStateException
Throws an IllegalStateException if the HTTP method has not been executed since last recycle.
Throws:
IllegalStateException - if not used

execute

public int execute(HttpState state,
                   HttpConnection conn)
            throws HttpException,
                   IOException
Executes this method using the specified HttpConnection and HttpState.
Specified by:
execute in interface HttpMethod
Parameters:
state - state information to associate with this request. Must be non-null.
conn - the connection to used to execute this HTTP method. Must be non-null.
Returns:
the integer status code if one was obtained, or -1
Throws:
IOException - if an I/O (transport) error occurs
HttpException - if a protocol exception occurs.

generateRequestLine

protected static String generateRequestLine(HttpConnection connection,
                                            String name,
                                            String requestPath,
                                            String query,
                                            String version)
Generates HTTP request line according to the specified attributes.
Parameters:
connection - the connection used to execute this HTTP method
name - the method name generate a request for
requestPath - the path string for the request
query - the query string for the request
version - the protocol version to use (e.g. HTTP/1.0)
Returns:
HTTP request line

getAuthenticationRealm

public String getAuthenticationRealm()

Deprecated. use #getHostAuthState()

Returns authentication realm, if it has been used during authentication process. Otherwise returns null.
Returns:
authentication realm

getContentCharSet

protected String getContentCharSet(Header contentheader)
Returns the character set from the Content-Type header.
Parameters:
contentheader - The content header.
Returns:
String The character set.

getDoAuthentication

public boolean getDoAuthentication()
Returns true if the HTTP method should automatically handle HTTP authentication challenges (status code 401, etc.), false otherwise
Specified by:
getDoAuthentication in interface HttpMethod
Returns:
true if authentication challenges will be processed automatically, false otherwise.
Since:
2.0

getEffectiveVersion

public HttpVersion getEffectiveVersion()
Returns the HTTP version used with this method (may be null if undefined, that is, the method has not been executed)
Returns:
HTTP version.
Since:
3.0

getFollowRedirects

public boolean getFollowRedirects()
Returns true if the HTTP method should automatically follow HTTP redirects (status code 302, etc.), false otherwise.
Specified by:
getFollowRedirects in interface HttpMethod
Returns:
true if the method will automatically follow HTTP redirects, false otherwise.

getHostAuthState

public AuthState getHostAuthState()
Returns the target host authentication state
Specified by:
getHostAuthState in interface HttpMethod
Returns:
host authentication state
Since:
3.0

getHostConfiguration

public HostConfiguration getHostConfiguration()

Deprecated. no longer applicable

Returns the host configuration.
Specified by:
getHostConfiguration in interface HttpMethod
Returns:
the host configuration

getMethodRetryHandler

public MethodRetryHandler getMethodRetryHandler()

Deprecated. use HttpMethodParams

Returns the retry handler for this HTTP method
Returns:
the methodRetryHandler

getName

public abstract String getName()
Obtains the name of the HTTP method as used in the HTTP request line, for example "GET" or "POST".
Specified by:
getName in interface HttpMethod
Returns:
the name of this method

getParams

public HttpMethodParams getParams()
Returns HTTP protocol parameters associated with this method.
Specified by:
getParams in interface HttpMethod
Returns:
HTTP parameters.
Since:
3.0
Usages and Demos :

View More Examples of getParams()
   1: import org.apache.commons.httpclient.HttpMethod;
   2: import org.apache.commons.httpclient.HttpMethodBase;
   3: import org.apache.commons.httpclient.HttpMethodRetryHandler;
   4:         ...
   5:         try {
   6:             final HttpMethodBase httpMethod = makeHttpMethod(webRequestSettings);
   7:             final HostConfiguration hostConfiguration = getHostConfiguration(webRequestSettings);
   8:         ...
   9: 
  10:     private HttpMethodBase makeHttpMethod(final WebRequestSettings webRequestSettings)
  11:         throws
  12:         ...
  13:             final PostMethod postMethod = new PostMethod( path );
  14:             postMethod.getParams().setContentCharset(webRequestSettings.getCharset());

View Full Code Here
   1: import org.apache.commons.httpclient.HttpMethod;
   2: import org.apache.commons.httpclient.HttpMethodBase;
   3: import org.apache.commons.httpclient.HttpState;
   4:         ...
   5:             File input = new File(filename);
   6:             post.setRequestEntity(new MultipartRequestEntity(parts, post.getParams()));
   7:         } else {
   8:         ...
   9:      
  10:     private HttpClient setupConnection(URL u, HttpMethodBase httpMethod, HTTPSampleResult res) throws IOException {
  11: 
  12:         ...
  13: 
  14:         HttpMethodParams params = httpMethod.getParams();

View Full Code Here
   1: import org.apache.commons.httpclient.HttpMethod;
   2: import org.apache.commons.httpclient.HttpMethodBase;
   3: import org.apache.commons.httpclient.HttpState;
   4:         ...
   5:         String curiString = curi.getUURI().toString();
   6:         HttpMethodBase method = null;
   7:         if (curi.isPost()) {
   8:         ...
   9:         try {
  10:             encoding = ((HttpMethodBase) method).getResponseCharSet();
  11:             if (encoding == null ||
  12:         ...
  13:         
  14:         method.getParams().setCookiePolicy(

View Full Code Here

getPath

public String getPath()
Gets the path of this HTTP method. Calling this method after the request has been executed will return the actual path, following any redirects automatically handled by this HTTP method.
Specified by:
getPath in interface HttpMethod
Returns:
the path to request or "/" if the path is blank.
Usages and Demos :

View More Examples of getPath()
   1: import org.apache.commons.httpclient.HttpMethod;
   2: import org.apache.commons.httpclient.HttpMethodBase;
   3: import org.apache.commons.httpclient.NameValuePair;
   4:         ...
   5:             
   6:             rewriter.setBaseUrl( rewriter.getBaseRelativeUrl( httpMethod.getPath() )) ;
   7:             
   8:         ...
   9:                 {
  10:                     log.info("WebContentPortlet.doHttpWebContent() - retrying: "+httpMethod.getPath()+", response code: "+responseCode);
  11:                     
  12:         ...
  13:                 {
  14:                     throw new PortletException("Failure reading: "+httpMethod.getPath()+", response code: "+responseCode);

View Full Code Here

getProxyAuthState

public AuthState getProxyAuthState()
Returns the proxy authentication state
Specified by:
getProxyAuthState in interface HttpMethod
Returns:
host authentication state
Since:
3.0

getProxyAuthenticationRealm

public String getProxyAuthenticationRealm()

Deprecated. use #getProxyAuthState()

Returns proxy authentication realm, if it has been used during authentication process. Otherwise returns null.
Returns:
proxy authentication realm

getQueryString

public String getQueryString()
Gets the query string of this HTTP method.
Specified by:
getQueryString in interface HttpMethod
Returns:
The query string

getRecoverableExceptionCount

public int getRecoverableExceptionCount()

Deprecated. no longer used Returns the number of "recoverable" exceptions thrown and handled, to allow for monitoring the quality of the connection.

Returns:
The number of recoverable exceptions handled by the method.

getRequestCharSet

public String getRequestCharSet()
Returns the character encoding of the request from the Content-Type header.
Returns:
String The character set.

getRequestHeader

public Header getRequestHeader(String headerName)
Returns the specified request header. Note that header-name matching is case insensitive. null will be returned if either headerName is null or there is no matching header for headerName.
Specified by:
getRequestHeader in interface HttpMethod
Parameters:
headerName - The name of the header to be returned.
Returns:
The specified request header.
Since:
3.0

getRequestHeaderGroup

protected HeaderGroup getRequestHeaderGroup()
Gets the header group storing the request headers.
Returns:
a HeaderGroup
Since:
2.0beta1

getRequestHeaders

public Header[] getRequestHeaders()
Returns an array of the requests headers that the HTTP method currently has
Specified by:
getRequestHeaders in interface HttpMethod
Returns:
an array of my request headers.

getRequestHeaders

public Header[] getRequestHeaders(String headerName)
Specified by:
getRequestHeaders in interface HttpMethod

getResponseBody

public byte[] getResponseBody()
            throws IOException
Returns the response body of the HTTP method, if any, as an array of bytes. If response body is not available or cannot be read, returns null. Buffers the response and this method can be called several times yielding the same result each time. Note: This will cause the entire response body to be buffered in memory. A malicious server may easily exhaust all the VM memory. It is strongly recommended, to use getResponseAsStream if the content length of the response is unknown or resonably large.
Specified by:
getResponseBody in interface HttpMethod
Returns:
The response body.
Throws:
IOException - If an I/O (transport) problem occurs while obtaining the response body.

getResponseBody

public byte[] getResponseBody(int maxlen)
            throws IOException
Returns the response body of the HTTP method, if any, as an array of bytes. If response body is not available or cannot be read, returns null. Buffers the response and this method can be called several times yielding the same result each time. Note: This will cause the entire response body to be buffered in memory. This method is safe if the content length of the response is unknown, because the amount of memory used is limited.

If the response is large this method involves lots of array copying and many object allocations, which makes it unsuitable for high-performance / low-footprint applications. Those applications should use getResponseBodyAsStream().

Parameters:
maxlen - the maximum content length to accept (number of bytes).
Returns:
The response body.
Throws:
IOException - If an I/O (transport) problem occurs while obtaining the response body.

getResponseBodyAsStream

public InputStream getResponseBodyAsStream()
            throws IOException
Returns the response body of the HTTP method, if any, as an InputStream. If response body is not available, returns null. If the response has been buffered this method returns a new stream object on every call. If the response has not been buffered the returned stream can only be read once.
Specified by:
getResponseBodyAsStream in interface HttpMethod
Returns:
The response body or null.
Throws:
IOException - If an I/O (transport) problem occurs while obtaining the response body.

getResponseBodyAsString

public String getResponseBodyAsString()
            throws IOException
Returns the response body of the HTTP method, if any, as a String. If response body is not available or cannot be read, returns null The string conversion on the data is done using the character encoding specified in Content-Type header. Buffers the response and this method can be called several times yielding the same result each time. Note: This will cause the entire response body to be buffered in memory. A malicious server may easily exhaust all the VM memory. It is strongly recommended, to use getResponseAsStream if the content length of the response is unknown or resonably large.
Specified by:
getResponseBodyAsString in interface HttpMethod
Returns:
The response body or null.
Throws:
IOException - If an I/O (transport) problem occurs while obtaining the response body.
Usages and Demos :

View More Examples of getResponseBodyAsString()
   1: import org.apache.commons.httpclient.HttpException;
   2: import org.apache.commons.httpclient.HttpMethodBase;
   3: import org.apache.commons.httpclient.NTCredentials;
   4:         ...
   5:             
   6:             HttpMethodBase method = new GetMethod( strUrl );
   7:             method.setFollowRedirects( true );
   8:         ...
   9:                 client.executeMethod( method );
  10:                 strResponseBody = method.getResponseBodyAsString(  );
  11:             }

View Full Code Here

getResponseBodyAsString

public String getResponseBodyAsString(int maxlen)
            throws IOException
Returns the response body of the HTTP method, if any, as a String. If response body is not available or cannot be read, returns null The string conversion on the data is done using the character encoding specified in Content-Type header. Buffers the response and this method can be called several times yielding the same result each time. Note: This will cause the entire response body to be buffered in memory. This method is safe if the content length of the response is unknown, because the amount of memory used is limited.

If the response is large this method involves lots of array copying and many object allocations, which makes it unsuitable for high-performance / low-footprint applications. Those applications should use getResponseBodyAsStream().

Parameters:
maxlen - the maximum content length to accept (number of bytes). Note that, depending on the encoding, this is not equal to the number of characters.
Returns:
The response body or null.
Throws:
IOException - If an I/O (transport) problem occurs while obtaining the response body.

getResponseCharSet

public String getResponseCharSet()
Returns the character encoding of the response from the Content-Type header.
Returns:
String The character set.

getResponseContentLength

public long getResponseContentLength()
Return the length (in bytes) of the response body, as specified in a Content-Length header.

Return -1 when the content-length is unknown.

Returns:
content length, if Content-Length header is available. 0 indicates that the request has no body. If Content-Length header is not present, the method returns -1.
Usages and Demos :

View More Examples of getResponseContentLength()
   1: import org.apache.commons.httpclient.HttpMethod;
   2: import org.apache.commons.httpclient.HttpMethodBase;
   3: import org.apache.commons.httpclient.HttpState;
   4:         ...
   5:         String curiString = curi.getUURI().toString();
   6:         HttpMethodBase method = null;
   7:         if (curi.isPost()) {
   8:         ...
   9:         
  10:         long softMax = method.getResponseContentLength();
  11:         
  12:         ...
  13:         try {
  14:             encoding = ((HttpMethodBase) method).getResponseCharSet();

View Full Code Here

getResponseFooter

public Header getResponseFooter(String footerName)
Gets the response footer associated with the given name. Footer name matching is case insensitive. null will be returned if either footerName is null or there is no matching footer for footerName or there are no footers available. If there are multiple footers with the same name, there values will be combined with the ',' separator as specified by RFC2616.
Specified by:
getResponseFooter in interface HttpMethod
Parameters:
footerName - the footer name to match
Returns:
the matching footer

getResponseFooters

public Header[] getResponseFooters()
Returns an array of the response footers that the HTTP method currently has in the order in which they were read.
Specified by:
getResponseFooters in interface HttpMethod
Returns:
an array of footers

getResponseHeader

public Header getResponseHeader(String headerName)
Gets the response header associated with the given name. Header name matching is case insensitive. null will be returned if either headerName is null or there is no matching header for headerName.
Specified by:
getResponseHeader in interface HttpMethod
Parameters:
headerName - the header name to match
Returns:
the matching header
Usages and Demos :

View More Examples of getResponseHeader(String headerName)
   1: import org.apache.commons.httpclient.HttpMethod;
   2: import org.apache.commons.httpclient.HttpMethodBase;
   3: import org.apache.commons.httpclient.HttpState;
   4:         ...
   5:      
   6:     private HttpClient setupConnection(URL u, HttpMethodBase httpMethod, HTTPSampleResult res) throws IOException {
   7: 
   8:         ...
   9: 
  10:         HttpMethodBase httpMethod = null;
  11: 
  12:         ...
  13:             
  14:                 Header responseHeader = httpMethod.getResponseHeader(TRANSFER_ENCODING);

View Full Code Here
   1: import org.apache.commons.httpclient.HttpMethod;
   2: import org.apache.commons.httpclient.HttpMethodBase;
   3: import org.apache.commons.httpclient.HttpState;
   4:         ...
   5:         String curiString = curi.getUURI().toString();
   6:         HttpMethodBase method = null;
   7:         if (curi.isPost()) {
   8:         ...
   9:             if (logger.isLoggable(Level.FINE)) {
  10:                 Header setCookie = method.getResponseHeader("set-cookie");
  11:                 if (setCookie != null) {
  12:         ...
  13:         curi.setFetchStatus(method.getStatusCode());
  14:         Header ct = method.getResponseHeader("content-type");

View Full Code Here

getResponseHeaderGroup

protected HeaderGroup getResponseHeaderGroup()
Gets the header group storing the response headers.
Returns:
a HeaderGroup
Since:
2.0beta1

getResponseHeaders

public Header[] getResponseHeaders()
Returns an array of the response headers that the HTTP method currently has in the order in which they were read.
Specified by:
getResponseHeaders in interface HttpMethod
Returns:
an array of response headers.

getResponseHeaders

public Header[] getResponseHeaders(String headerName)
Specified by:
getResponseHeaders in interface HttpMethod
Since:
3.0

getResponseStream

protected InputStream getResponseStream()
Returns a stream from which the body of the current response may be read. If the method has not yet been executed, if responseBodyConsumed has been called, or if the stream returned by a previous call has been closed, null will be returned.
Returns:
the current response stream

getResponseTrailerHeaderGroup

protected HeaderGroup getResponseTrailerHeaderGroup()
Gets the header group storing the response trailer headers as per RFC 2616 section 3.6.1.
Returns:
a HeaderGroup
Since:
2.0beta1

getStatusCode

public int getStatusCode()
Returns the response status code.
Specified by:
getStatusCode in interface HttpMethod
Returns:
the status code associated with the latest response.
Usages and Demos :

View More Examples of getStatusCode()
   1: import org.apache.commons.httpclient.HttpClient;
   2: import org.apache.commons.httpclient.HttpMethodBase;
   3: import org.apache.commons.httpclient.methods.PostMethod;
   4:         ...
   5:     
   6:     protected HttpMethodBase getHttpMethod(HttpClient client, String uri, Map params, String formMethod, RenderRequest request) throws IOException
   7:     {
   8:         ...
   9:         HttpClient client = new HttpClient();
  10:         HttpMethodBase httpMethod = null;
  11:         httpMethod = new PostMethod();
  12:         ...
  13:             client.executeMethod(httpMethod);
  14:             int responseCode  = httpMethod.getStatusCode();

View Full Code Here
   1: import org.apache.commons.httpclient.HttpMethod;
   2: import org.apache.commons.httpclient.HttpMethodBase;
   3: import org.apache.commons.httpclient.NameValuePair;
   4:         ...
   5: 
   6:             int responseCode = httpMethod.getStatusCode();
   7:             if (responseCode >= 300 && responseCode <= 399)
   8:         ...
   9:             BufferedInputStream bis = new BufferedInputStream(httpMethod.getResponseBodyAsStream());
  10:             String encoding = ((HttpMethodBase)httpMethod).getResponseCharSet();
  11:             if (encoding == null)
  12:         ...
  13:     
  14:     protected HttpMethodBase getHttpMethod(HttpClient client, String uri, Map params, String formMethod, RenderRequest request) throws IOException

View Full Code Here
   1: import org.apache.commons.httpclient.HttpMethod;
   2: import org.apache.commons.httpclient.HttpMethodBase;
   3: import org.apache.commons.httpclient.HttpState;
   4:         ...
   5:         String curiString = curi.getUURI().toString();
   6:         HttpMethodBase method = null;
   7:         if (curi.isPost()) {
   8:         ...
   9:             logger.info((curi.isPost()? "POST": "GET") + " " +
  10:                 curi.getUURI().toString() + " " + method.getStatusCode() +
  11:                 " " + rec.getRecordedInput().getSize() + " " +
  12:         ...
  13:             }
  14:         } else if (method.getStatusCode() == HttpStatus.SC_UNAUTHORIZED) {

View Full Code Here

getStatusLine

public StatusLine getStatusLine()
Provides access to the response status line.
Specified by:
getStatusLine in interface HttpMethod
Returns:
the status line object from the latest response.
Since:
2.0

getStatusText

public String getStatusText()
Returns the status text (or "reason phrase") associated with the latest response.
Specified by:
getStatusText in interface HttpMethod
Returns:
The status text.
Usages and Demos :

View More Examples of getStatusText()
   1: import org.apache.commons.httpclient.HttpMethod;
   2: import org.apache.commons.httpclient.HttpMethodBase;
   3: import org.apache.commons.httpclient.HttpState;
   4:         ...
   5:      
   6:     private HttpClient setupConnection(URL u, HttpMethodBase httpMethod, HTTPSampleResult res) throws IOException {
   7: 
   8:         ...
   9: 
  10:         HttpMethodBase httpMethod = null;
  11: 
  12:         ...
  13: 
  14:             res.setResponseMessage(httpMethod.getStatusText());

View Full Code Here

getURI

public URI getURI()
            throws URIException
Returns the URI of the HTTP method
Specified by:
getURI in interface HttpMethod
Returns:
The URI
Throws:
URIException - If the URI cannot be created.
Usages and Demos :

View More Examples of getURI()
   1: import org.apache.commons.httpclient.HttpMethod;
   2: import org.apache.commons.httpclient.HttpMethodBase;
   3: import org.apache.commons.httpclient.HttpState;
   4:         ...
   5:      
   6:     private HttpClient setupConnection(URL u, HttpMethodBase httpMethod, HTTPSampleResult res) throws IOException {
   7: 
   8:         ...
   9: 
  10:         HttpMethodBase httpMethod = null;
  11: 
  12:         ...
  13: 
  14:             res.setSampleLabel(httpMethod.getURI().toString());

View Full Code Here

hasBeenUsed

public boolean hasBeenUsed()
Returns true if the HTTP method has been already executed, but not recycled.
Specified by:
hasBeenUsed in interface HttpMethod
Returns:
true if the method has been executed, false otherwise

isAborted

public boolean isAborted()
Tests whether the execution of this method has been aborted
Returns:
true if the execution of this method has been aborted, false otherwise
Since:
3.0

isConnectionCloseForced

protected boolean isConnectionCloseForced()
Tests if the connection should be force-closed when no longer needed.
Returns:
true if the connection must be closed

isHttp11

public boolean isHttp11()

Deprecated. Use HttpMethodParams.getVersion()

Returns true if version 1.1 of the HTTP protocol should be used per default, false if version 1.0 should be used.
Returns:
true to use HTTP/1.1, false to use 1.0

isRequestSent

public boolean isRequestSent()
Returns true if the HTTP has been transmitted to the target server in its entirety, false otherwise. This flag can be useful for recovery logic. If the request has not been transmitted in its entirety, it is safe to retry the failed method.
Specified by:
isRequestSent in interface HttpMethod
Returns:
true if the request has been sent, false otherwise

isStrictMode

public boolean isStrictMode()

Deprecated. Use HttpParams.setParameter(String,Object) to exercise a more granular control over HTTP protocol strictness.

Specified by:
isStrictMode in interface HttpMethod
Returns:
false

processCookieHeaders

protected void processCookieHeaders(CookieSpec parser,
                                    Header[] headers,
                                    HttpState state,
                                    HttpConnection conn)
This method processes the specified cookie headers. It is invoked from within processResponseHeaders(HttpState,HttpConnection)
Parameters:
headers - cookie Headers to be processed
state - the state information associated with this HTTP method
conn - the connection used to execute this HTTP method

processResponseBody

protected void processResponseBody(HttpState state,
                                   HttpConnection conn)
This method is invoked immediately after readResponseBody(HttpState,HttpConnection) and can be overridden by sub-classes in order to provide custom body processing.

This implementation does nothing.

Parameters:
state - the state information associated with this method
conn - the connection used to execute this HTTP method

processResponseHeaders

protected void processResponseHeaders(HttpState state,
                                      HttpConnection conn)
This method is invoked immediately after readResponseHeaders(HttpState,HttpConnection) and can be overridden by sub-classes in order to provide custom response headers processing.

This implementation will handle the Set-Cookie and Set-Cookie2 headers, if any, adding the relevant cookies to the given HttpState.

Parameters:
state - the state information associated with this method
conn - the connection used to execute this HTTP method

processStatusLine

protected void processStatusLine(HttpState state,
                                 HttpConnection conn)
This method is invoked immediately after readStatusLine(HttpState,HttpConnection) and can be overridden by sub-classes in order to provide custom response status line processing.
Parameters:
state - the state information associated with this method
conn - the connection used to execute this HTTP method

readResponse

protected void readResponse(HttpState state,
                            HttpConnection conn)
            throws IOException,
                   HttpException
Reads the response from the given connection.

The response is processed as the following sequence of actions:

  1. readStatusLine(HttpState,HttpConnection) is invoked to read the request line.
  2. processStatusLine(HttpState,HttpConnection) is invoked, allowing the method to process the status line if desired.
  3. readResponseHeaders(HttpState,HttpConnection) is invoked to read the associated headers.
  4. processResponseHeaders(HttpState,HttpConnection) is invoked, allowing the method to process the headers if desired.
  5. readResponseBody(HttpState,HttpConnection) is invoked to read the associated body (if any).
  6. processResponseBody(HttpState,HttpConnection) is invoked, allowing the method to process the response body if desired.
Subclasses may want to override one or more of the above methods to to customize the processing. (Or they may choose to override this method if dramatically different processing is required.)
Parameters:
state - the state information associated with this method
conn - the connection used to execute this HTTP method
Throws:
IOException - if an I/O (transport) error occurs. Some transport exceptions can be recovered from.
HttpException - if a protocol exception occurs. Usually protocol exceptions cannot be recovered from.

readResponseBody

protected void readResponseBody(HttpState state,
                                HttpConnection conn)
            throws IOException,
                   HttpException
Read the response body from the given HttpConnection.

The current implementation wraps the socket level stream with an appropriate stream for the type of response (chunked, content-length, or auto-close). If there is no response body, the connection associated with the request will be returned to the connection manager.

Subclasses may want to override this method to to customize the processing.

Parameters:
state - the state information associated with this method
conn - the connection used to execute this HTTP method
Throws:
IOException - if an I/O (transport) error occurs. Some transport exceptions can be recovered from.
HttpException - if a protocol exception occurs. Usually protocol exceptions cannot be recovered from.

readResponseHeaders

protected void readResponseHeaders(HttpState state,
                                   HttpConnection conn)
            throws IOException,
                   HttpException
Reads the response headers from the given connection.

Subclasses may want to override this method to to customize the processing.

"It must be possible to combine the multiple header fields into one "field-name: field-value" pair, without changing the semantics of the message, by appending each subsequent field-value to the first, each separated by a comma." - HTTP/1.0 (4.3)

Parameters:
state - the state information associated with this method
conn - the connection used to execute this HTTP method
Throws:
IOException - if an I/O (transport) error occurs. Some transport exceptions can be recovered from.
HttpException - if a protocol exception occurs. Usually protocol exceptions cannot be recovered from.

readStatusLine

protected void readStatusLine(HttpState state,
                              HttpConnection conn)
            throws IOException,
                   HttpException
Read the status line from the given HttpConnection, setting my status code and status text.

Subclasses may want to override this method to to customize the processing.

Parameters:
state - the state information associated with this method
conn - the connection used to execute this HTTP method
Throws:
IOException - if an I/O (transport) error occurs. Some transport exceptions can be recovered from.
HttpException - if a protocol exception occurs. Usually protocol exceptions cannot be recovered from.
See Also:
StatusLine

recycle

public void recycle()

Deprecated. no longer supported and will be removed in the future version of HttpClient

Recycles the HTTP method so that it can be used again. Note that all of the instance variables will be reset once this method has been called. This method will also release the connection being used by this HTTP method.
Specified by:
recycle in interface HttpMethod

releaseConnection

public void releaseConnection()
Releases the connection being used by this HTTP method. In particular the connection is used to read the response(if there is one) and will be held until the response has been read. If the connection can be reused by other HTTP methods it is NOT closed at this point.
Specified by:
releaseConnection in interface HttpMethod
Since:
2.0
Usages and Demos :

View More Examples of releaseConnection()
   1: import org.apache.commons.httpclient.HttpException;
   2: import org.apache.commons.httpclient.HttpMethodBase;
   3: import org.apache.commons.httpclient.NTCredentials;
   4:         ...
   5:             
   6:             HttpMethodBase method = new GetMethod( strUrl );
   7:             method.setFollowRedirects( true );
   8:         ...
   9:             {
  10:                 method.releaseConnection(  );
  11:             }

View Full Code Here
   1: import org.apache.commons.httpclient.HttpMethod;
   2: import org.apache.commons.httpclient.HttpMethodBase;
   3: import org.apache.commons.httpclient.HttpState;
   4:         ...
   5:      
   6:     private HttpClient setupConnection(URL u, HttpMethodBase httpMethod, HTTPSampleResult res) throws IOException {
   7: 
   8:         ...
   9: 
  10:         HttpMethodBase httpMethod = null;
  11: 
  12:         ...
  13:             if (httpMethod != null)
  14:                 httpMethod.releaseConnection();

View Full Code Here
   1: import org.apache.commons.httpclient.HttpMethod;
   2: import org.apache.commons.httpclient.HttpMethodBase;
   3: import org.apache.commons.httpclient.NameValuePair;
   4:         ...
   5:             if (httpMethod != null)
   6:                 httpMethod.releaseConnection();
   7:         }
   8:         ...
   9:             BufferedInputStream bis = new BufferedInputStream(httpMethod.getResponseBodyAsStream());
  10:             String encoding = ((HttpMethodBase)httpMethod).getResponseCharSet();
  11:             if (encoding == null)
  12:         ...
  13:     
  14:     protected HttpMethodBase getHttpMethod(HttpClient client, String uri, Map params, String formMethod, RenderRequest request) throws IOException

View Full Code Here
   1: import org.apache.commons.httpclient.HttpMethod;
   2: import org.apache.commons.httpclient.HttpMethodBase;
   3: import org.apache.commons.httpclient.HttpState;
   4:         ...
   5:         String curiString = curi.getUURI().toString();
   6:         HttpMethodBase method = null;
   7:         if (curi.isPost()) {
   8:         ...
   9:             if (!method.isAborted()) {
  10:                 method.releaseConnection();
  11:             }
  12:         ...
  13:         try {
  14:             encoding = ((HttpMethodBase) method).getResponseCharSet();

View Full Code Here

removeRequestHeader

public void removeRequestHeader(String headerName)
Remove the request header associated with the given name. Note that header-name matching is case insensitive.
Specified by:
removeRequestHeader in interface HttpMethod
Parameters:
headerName - the header name

removeRequestHeader

public void removeRequestHeader(Header header)
Removes the given request header.
Specified by:
removeRequestHeader in interface HttpMethod
Parameters:
header - the header

responseBodyConsumed

protected void responseBodyConsumed()
A response has been consumed.

The default behavior for this class is to check to see if the connection should be closed, and close if need be, and to ensure that the connection is returned to the connection manager - if and only if we are not still inside the execute call.


setConnectionCloseForced

protected void setConnectionCloseForced(boolean b)
Sets whether or not the connection should be force-closed when no longer needed. This value should only be set to true in abnormal circumstances, such as HTTP protocol violations.
Parameters:
b - true if the connection must be closed, false otherwise.

setDoAuthentication

public void setDoAuthentication(boolean doAuthentication)
Sets whether or not the HTTP method should automatically handle HTTP authentication challenges (status code 401, etc.)
Specified by:
setDoAuthentication in interface HttpMethod
Parameters:
doAuthentication - true to process authentication challenges authomatically, false otherwise.
Since:
2.0
Usages and Demos :

View More Examples of setDoAuthentication(boolean doAuthentication)
   1: import org.apache.commons.httpclient.HttpException;
   2: import org.apache.commons.httpclient.HttpMethodBase;
   3: import org.apache.commons.httpclient.NTCredentials;
   4:         ...
   5:             
   6:             HttpMethodBase method = new GetMethod( strUrl );
   7:             method.setFollowRedirects( true );
   8:         ...
   9:                 client.getState(  ).setAuthenticationPreemptive( true );
  10:                 method.setDoAuthentication( true );
  11:             }

View Full Code Here
   1: import org.apache.commons.httpclient.HttpMethod;
   2: import org.apache.commons.httpclient.HttpMethodBase;
   3: import org.apache.commons.httpclient.HttpState;
   4:         ...
   5:         String curiString = curi.getUURI().toString();
   6:         HttpMethodBase method = null;
   7:         if (curi.isPost()) {
   8:         ...
   9:         boolean addedCredentials = populateCredentials(curi, method);
  10:         method.setDoAuthentication(addedCredentials);
  11:         
  12:         ...
  13:         try {
  14:             encoding = ((HttpMethodBase) method).getResponseCharSet();

View Full Code Here

setFollowRedirects

public void setFollowRedirects(boolean followRedirects)
Sets whether or not the HTTP method should automatically follow HTTP redirects (status code 302, etc.)
Specified by:
setFollowRedirects in interface HttpMethod
Parameters:
followRedirects - true if the method will automatically follow redirects, false otherwise.
Usages and Demos :

View More Examples of setFollowRedirects(boolean followRedirects)
   1: import org.apache.commons.httpclient.HttpException;
   2: import org.apache.commons.httpclient.HttpMethodBase;
   3: import org.apache.commons.httpclient.NTCredentials;
   4:         ...
   5:             
   6:             HttpMethodBase method = new GetMethod( strUrl );
   7:         ...
   8:             method.setFollowRedirects( true );
   9:             

View Full Code Here
   1: import org.apache.commons.httpclient.HttpMethod;
   2: import org.apache.commons.httpclient.HttpMethodBase;
   3: import org.apache.commons.httpclient.HttpMethodRetryHandler;
   4:         ...
   5:         try {
   6:             final HttpMethodBase httpMethod = makeHttpMethod(webRequestSettings);
   7:             final HostConfiguration hostConfiguration = getHostConfiguration(webRequestSettings);
   8:         ...
   9: 
  10:     private HttpMethodBase makeHttpMethod(final WebRequestSettings webRequestSettings)
  11:         throws
  12:         ...
  13:         writeRequestHeadersToHttpMethod(httpMethod, webRequestSettings.getAdditionalHeaders());
  14:         httpMethod.setFollowRedirects(false);

View Full Code Here
   1: import org.apache.commons.httpclient.HttpMethod;
   2: import org.apache.commons.httpclient.HttpMethodBase;
   3: import org.apache.commons.httpclient.HttpState;
   4:         ...
   5:      
   6:     private HttpClient setupConnection(URL u, HttpMethodBase httpMethod, HTTPSampleResult res) throws IOException {
   7: 
   8:         ...
   9: 
  10:         httpMethod.setFollowRedirects(getAutoRedirects());
  11: 
  12:         ...
  13: 
  14:         HttpMethodBase httpMethod = null;

View Full Code Here
   1: import org.apache.commons.httpclient.HttpMethod;
   2: import org.apache.commons.httpclient.HttpMethodBase;
   3: import org.apache.commons.httpclient.NameValuePair;
   4:         ...
   5:             BufferedInputStream bis = new BufferedInputStream(httpMethod.getResponseBodyAsStream());
   6:             String encoding = ((HttpMethodBase)httpMethod).getResponseCharSet();
   7:             if (encoding == null)
   8:         ...
   9:     
  10:     protected HttpMethodBase getHttpMethod(HttpClient client, String uri, Map params, String formMethod, RenderRequest request) throws IOException
  11:     {
  12:         ...
  13:             
  14:             httpMethod.setFollowRedirects(true);

View Full Code Here
   1: import org.apache.commons.httpclient.HttpMethod;
   2: import org.apache.commons.httpclient.HttpMethodBase;
   3: import org.apache.commons.httpclient.HttpState;
   4:         ...
   5:         String curiString = curi.getUURI().toString();
   6:         HttpMethodBase method = null;
   7:         if (curi.isPost()) {
   8:         ...
   9:         try {
  10:             encoding = ((HttpMethodBase) method).getResponseCharSet();
  11:             if (encoding == null ||
  12:         ...
  13:     protected HostConfiguration configureMethod(CrawlURI curi, HttpMethod method) {
  14:         method.setFollowRedirects(false);

View Full Code Here

setHostConfiguration

public void setHostConfiguration(HostConfiguration hostconfig)

Deprecated. no longer applicable

Sets the host configuration.
Parameters:
hostconfig - The hostConfiguration to set

setHttp11

public void setHttp11(boolean http11)

Deprecated. Use HttpMethodParams.setVersion(HttpVersion)

Sets whether version 1.1 of the HTTP protocol should be used per default.
Parameters:
http11 - true to use HTTP/1.1, false to use 1.0

setMethodRetryHandler

public void setMethodRetryHandler(MethodRetryHandler handler)

Deprecated. use HttpMethodParams

Sets the retry handler for this HTTP method
Parameters:
handler - the methodRetryHandler to use when this method executed

setParams

public void setParams(HttpMethodParams params)
Assigns HTTP protocol parameters for this method.
Specified by:
setParams in interface HttpMethod
Since:
3.0

setPath

public void setPath(String path)
Sets the path of the HTTP method. It is responsibility of the caller to ensure that the path is properly encoded (URL safe).
Specified by:
setPath in interface HttpMethod
Parameters:
path - the path of the HTTP method. The path is expected to be URL-encoded
Usages and Demos :

View More Examples of setPath(String path)
   1: import org.apache.commons.httpclient.HttpClient;
   2: import org.apache.commons.httpclient.HttpMethodBase;
   3: import org.apache.commons.httpclient.methods.PostMethod;
   4:         ...
   5:     
   6:     protected HttpMethodBase getHttpMethod(HttpClient client, String uri, Map params, String formMethod, RenderRequest request) throws IOException
   7:     {
   8:         ...
   9:         HttpClient client = new HttpClient();
  10:         HttpMethodBase httpMethod = null;
  11:         httpMethod = new PostMethod();
  12:         ...
  13:         httpMethod.addRequestHeader( "User-Agent", "Firefox" );
  14:         httpMethod.setPath(url);

View Full Code Here

setQueryString

public void setQueryString(String queryString)
Sets the query string of this HTTP method. The caller must ensure that the string is properly URL encoded. The query string should not start with the question mark character.
Specified by:
setQueryString in interface HttpMethod
Parameters:
queryString - the query string
Usages and Demos :

View More Examples of setQueryString(String queryString)
   1: import org.apache.commons.httpclient.HttpMethod;
   2: import org.apache.commons.httpclient.HttpMethodBase;
   3: import org.apache.commons.httpclient.NameValuePair;
   4:         ...
   5:         } else if (method instanceof GetMethod) {
   6:             HttpMethodBase hmb = (HttpMethodBase)method;
   7:             String currentQuery = hmb.getQueryString();
   8:         ...
   9:             hmb.setQueryString(data);
  10:             String newQuery = hmb.getQueryString();
  11:         ...
  12:             hmb.setQueryString(((currentQuery != null)? currentQuery: "") +

View Full Code Here
   1: import org.apache.commons.httpclient.HttpMethod;
   2: import org.apache.commons.httpclient.HttpMethodBase;
   3: import org.apache.commons.httpclient.HttpMethodRetryHandler;
   4:         ...
   5:         try {
   6:             final HttpMethodBase httpMethod = makeHttpMethod(webRequestSettings);
   7:             final HostConfiguration hostConfiguration = getHostConfiguration(webRequestSettings);
   8:         ...
   9: 
  10:     private HttpMethodBase makeHttpMethod(final WebRequestSettings webRequestSettings)
  11:         throws
  12:         ...
  13:                 final String queryString = webRequestSettings.getURL().getQuery();
  14:                 httpMethod.setQueryString( queryString );

View Full Code Here
   1: import org.apache.commons.httpclient.HttpMethod;
   2: import org.apache.commons.httpclient.HttpMethodBase;
   3: import org.apache.commons.httpclient.NameValuePair;
   4:         ...
   5:             BufferedInputStream bis = new BufferedInputStream(httpMethod.getResponseBodyAsStream());
   6:             String encoding = ((HttpMethodBase)httpMethod).getResponseCharSet();
   7:             if (encoding == null)
   8:         ...
   9:     
  10:     protected HttpMethodBase getHttpMethod(HttpClient client, String uri, Map params, String formMethod, RenderRequest request) throws IOException
  11:     {
  12:         ...
  13:                 }
  14:                 httpMethod.setQueryString((NameValuePair[])pairs.toArray(new NameValuePair[pairs.size()]));

View Full Code Here

setQueryString

public void setQueryString(NameValuePair[] params)
Sets the query string of this HTTP method. The pairs are encoded as UTF-8 characters. To use a different charset the parameters can be encoded manually using EncodingUtil and set as a single String.
Specified by:
setQueryString in interface HttpMethod
Parameters:
params - an array of NameValuePairs to add as query string parameters. The name/value pairs will be automcatically URL encoded
Usages and Demos :

View More Examples of setQueryString(NameValuePair[] params)
   1: import org.apache.commons.httpclient.HttpMethod;
   2: import org.apache.commons.httpclient.HttpMethodBase;
   3: import org.apache.commons.httpclient.NameValuePair;
   4:         ...
   5:         } else if (method instanceof GetMethod) {
   6:             HttpMethodBase hmb = (HttpMethodBase)method;
   7:             String currentQuery = hmb.getQueryString();
   8:         ...
   9:             hmb.setQueryString(data);
  10:             String newQuery = hmb.getQueryString();
  11:         ...
  12:             hmb.setQueryString(((currentQuery != null)? currentQuery: "") +

View Full Code Here
   1: import org.apache.commons.httpclient.HttpMethod;
   2: import org.apache.commons.httpclient.HttpMethodBase;
   3: import org.apache.commons.httpclient.HttpMethodRetryHandler;
   4:         ...
   5:         try {
   6:             final HttpMethodBase httpMethod = makeHttpMethod(webRequestSettings);
   7:             final HostConfiguration hostConfiguration = getHostConfiguration(webRequestSettings);
   8:         ...
   9: 
  10:     private HttpMethodBase makeHttpMethod(final WebRequestSettings webRequestSettings)
  11:         throws
  12:         ...
  13:                 final String queryString = webRequestSettings.getURL().getQuery();
  14:                 httpMethod.setQueryString( queryString );

View Full Code Here
   1: import org.apache.commons.httpclient.HttpMethod;
   2: import org.apache.commons.httpclient.HttpMethodBase;
   3: import org.apache.commons.httpclient.NameValuePair;
   4:         ...
   5:             BufferedInputStream bis = new BufferedInputStream(httpMethod.getResponseBodyAsStream());
   6:             String encoding = ((HttpMethodBase)httpMethod).getResponseCharSet();
   7:             if (encoding == null)
   8:         ...
   9:     
  10:     protected HttpMethodBase getHttpMethod(HttpClient client, String uri, Map params, String formMethod, RenderRequest request) throws IOException
  11:     {
  12:         ...
  13:                 }
  14:                 httpMethod.setQueryString((NameValuePair[])pairs.toArray(new NameValuePair[pairs.size()]));

View Full Code Here

setRequestHeader

public void setRequestHeader(String headerName,
                             String headerValue)
Set the specified request header, overwriting any previous value. Note that header-name matching is case-insensitive.
Specified by:
setRequestHeader in interface HttpMethod
Parameters:
headerName - the header's name
headerValue - the header's value
Usages and Demos :

View More Examples of setRequestHeader(String headerName,String headerValue)
   1: import org.apache.commons.httpclient.HttpMethod;
   2: import org.apache.commons.httpclient.HttpMethodBase;
   3: import org.apache.commons.httpclient.HttpState;
   4:         ...
   5:      
   6:     private HttpClient setupConnection(URL u, HttpMethodBase httpMethod, HTTPSampleResult res) throws IOException {
   7: 
   8:         ...
   9:         if (getUseKeepAlive()) {
  10:             httpMethod.setRequestHeader(HEADER_CONNECTION, KEEP_ALIVE);
  11:         } else {
  12:         ...
  13:             httpMethod.setRequestHeader(HEADER_CONNECTION, CONNECTION_CLOSE);

View Full Code Here
   1: import org.apache.commons.httpclient.HttpMethod;
   2: import org.apache.commons.httpclient.HttpMethodBase;
   3: import org.apache.commons.httpclient.HttpState;
   4:         ...
   5:         String curiString = curi.getUURI().toString();
   6:         HttpMethodBase method = null;
   7:         if (curi.isPost()) {
   8:         ...
   9:         try {
  10:             encoding = ((HttpMethodBase) method).getResponseCharSet();
  11:             if (encoding == null ||
  12:         ...
  13:         }
  14:         method.setRequestHeader("User-Agent", userAgent);

View Full Code Here

setRequestHeader

public void setRequestHeader(Header header)
Sets the specified request header, overwriting any previous value. Note that header-name matching is case insensitive.
Specified by:
setRequestHeader in interface HttpMethod
Parameters:
header - the header
Usages and Demos :

View More Examples of setRequestHeader(Header header)
   1: import org.apache.commons.httpclient.HttpMethod;
   2: import org.apache.commons.httpclient.HttpMethodBase;
   3: import org.apache.commons.httpclient.HttpMethodRetryHandler;
   4:         ...
   5:         try {
   6:             final HttpMethodBase httpMethod = makeHttpMethod(webRequestSettings);
   7:             final HostConfiguration hostConfiguration = getHostConfiguration(webRequestSettings);
   8:         ...
   9: 
  10:     private HttpMethodBase makeHttpMethod(final WebRequestSettings webRequestSettings)
  11:         throws
  12:         ...
  13:                 final Map.Entry entry = ( Map.Entry )iterator.next();
  14:                 httpMethod.setRequestHeader( ( String )entry.getKey(), ( String )entry.getValue() );

View Full Code Here

setResponseStream

protected void setResponseStream(InputStream responseStream)
Sets the response stream.
Parameters:
responseStream - The new response stream.

setStrictMode

public void setStrictMode(boolean strictMode)

Deprecated. Use HttpParams.setParameter(String,Object) to exercise a more granular control over HTTP protocol strictness.

Defines how strictly HttpClient follows the HTTP protocol specification (RFC 2616 and other relevant RFCs). In the strict mode HttpClient precisely implements the requirements of the specification, whereas in non-strict mode it attempts to mimic the exact behaviour of commonly used HTTP agents, which many HTTP servers expect.
Specified by:
setStrictMode in interface HttpMethod
Parameters:
strictMode - true for strict mode, false otherwise

setURI

public void setURI(URI uri)
            throws URIException
Sets the URI for this method.
Specified by:
setURI in interface HttpMethod
Parameters:
uri - URI to be set
Throws:
URIException - if a URI cannot be set
Since:
3.0

shouldCloseConnection

protected boolean shouldCloseConnection(HttpConnection conn)
Tests if the connection should be closed after the method has been executed. The connection will be left open when using HTTP/1.1 or if Connection: keep-alive header was sent.
Parameters:
conn - the connection in question
Returns:
boolean true if we should close the connection.

validate

public boolean validate()
Returns true the method is ready to execute, false otherwise.
Specified by:
validate in interface HttpMethod
Returns:
This implementation always returns true.

writeRequest

protected void writeRequest(HttpState state,
                            HttpConnection conn)
            throws IOException,
                   HttpException
Sends the request via the given connection.

The request is written as the following sequence of actions:

  1. writeRequestLine(HttpState,HttpConnection) is invoked to write the request line.
  2. writeRequestHeaders(HttpState,HttpConnection) is invoked to write the associated headers.
  3. \r\n is sent to close the head part of the request.
  4. writeRequestBody(HttpState,HttpConnection) is invoked to write the body part of the request.

Subclasses may want to override one or more of the above methods to to customize the processing. (Or they may choose to override this method if dramatically different processing is required.)

Parameters:
state - the state information associated with this method
conn - the connection used to execute this HTTP method
Throws:
IOException - if an I/O (transport) error occurs. Some transport exceptions can be recovered from.
HttpException - if a protocol exception occurs. Usually protocol exceptions cannot be recovered from.

writeRequestBody

protected boolean writeRequestBody(HttpState state,
                                   HttpConnection conn)
            throws IOException,
                   HttpException
Writes the request body to the given connection.

This method should return true if the request body was actually sent (or is empty), or false if it could not be sent for some reason.

This implementation writes nothing and returns true.

Parameters:
state - the state information associated with this method
conn - the connection used to execute this HTTP method
Returns:
true
Throws:
IOException - if an I/O (transport) error occurs. Some transport exceptions can be recovered from.
HttpException - if a protocol exception occurs. Usually protocol exceptions cannot be recovered from.

writeRequestHeaders

protected void writeRequestHeaders(HttpState state,
                                   HttpConnection conn)
            throws IOException,
                   HttpException
Writes the request headers to the given connection.

This implementation invokes addRequestHeaders(HttpState,HttpConnection), and then writes each header to the request stream.

Subclasses may want to override this method to to customize the processing.

Parameters:
state - the state information associated with this method
conn - the connection used to execute this HTTP method
Throws:
IOException - if an I/O (transport) error occurs. Some transport exceptions can be recovered from.
HttpException - if a protocol exception occurs. Usually protocol exceptions cannot be recovered from.

writeRequestLine

protected void writeRequestLine(HttpState state,
                                HttpConnection conn)
            throws IOException,
                   HttpException
Writes the request line to the given connection.

Subclasses may want to override this method to to customize the processing.

Parameters:
state - the state information associated with this method
conn - the connection used to execute this HTTP method
Throws:
IOException - if an I/O (transport) error occurs. Some transport exceptions can be recovered from.
HttpException - if a protocol exception occurs. Usually protocol exceptions cannot be recovered from.