public class HTTPMethod
extends java.lang.Object
implements java.io.Closeable
The arguments to the factory method are as follows.
Method URLs may be specified in any of three ways.
Legal url arguments to HTTPMethod are constrained by the URL specified in creating the HTTPSession instance, if any. If the session was constructed with a specified URL, then any url specified to HTTMethod (via the factory or via execute()) must be "compatible" with the session URL). The term "compatible" basically means that the session url's host+port is the same as that of the specified method url. This maintains the semantics of the Session but allows flexibility in accessing data from the server.
One-Shot Operation: A reasonably common use case is when a client wants to create a method, execute it, get the response, and close the method. For this use case, creating a session and making sure it gets closed can be a tricky proposition. To support this use case, HTTPMethod supports what amounts to a one-shot use. The steps are as follows:
Modifier and Type | Field and Description |
---|---|
protected boolean |
closed |
protected org.apache.http.HttpEntity |
content |
protected java.util.List<org.apache.http.Header> |
headers |
protected boolean |
localsession |
protected ucar.httpservices.HTTPSession.Methods |
methodkind |
protected HTTPMethodStream |
methodstream |
protected java.net.URI |
methodurl |
protected long[] |
range |
protected org.apache.http.client.methods.HttpRequestBase |
request |
protected org.apache.http.client.methods.CloseableHttpResponse |
response |
protected HTTPSession |
session |
protected java.lang.String |
userinfo |
Modifier and Type | Method and Description |
---|---|
protected org.apache.http.client.methods.RequestBuilder |
buildrequest() |
boolean |
canHoldContent() |
void |
close()
Calling close will force the method to close, and will
force any open stream to terminate.
|
org.apache.http.HttpMessage |
debugRequest() |
org.apache.http.HttpResponse |
debugResponse() |
int |
execute()
Create a request, add headers, and content,
then send to HTTPSession to do the bulk of the work.
|
static java.util.Set<java.lang.String> |
getAllowedMethods() |
java.lang.String |
getCharSet() |
org.apache.http.client.config.RequestConfig |
getDebugConfig() |
java.lang.String |
getMethodKind() |
java.lang.String |
getName()
Deprecated.
|
java.lang.String |
getPath() |
org.apache.http.Header |
getRequestHeader(java.lang.String name) |
org.apache.http.Header[] |
getRequestHeaders() |
java.lang.String |
getRequestLine() |
byte[] |
getResponseAsBytes() |
byte[] |
getResponseAsBytes(int maxbytes) |
java.io.InputStream |
getResponseAsStream() |
java.lang.String |
getResponseAsString() |
java.lang.String |
getResponseAsString(java.lang.String charset) |
java.io.InputStream |
getResponseBodyAsStream() |
java.lang.String |
getResponseCharSet() |
org.apache.http.Header |
getResponseHeader(java.lang.String name) |
org.apache.http.Header[] |
getResponseHeaders() |
HTTPSession |
getSession() |
int |
getStatusCode() |
java.lang.String |
getStatusLine() |
java.lang.String |
getStatusText() |
java.lang.String |
getURL() |
boolean |
hasStreamOpen() |
boolean |
isClosed() |
boolean |
isSessionLocal() |
protected boolean |
sessionCompatible(org.apache.http.auth.AuthScope other)
Test that the given url is "compatible" with the
session specified dataset.
|
protected boolean |
sessionCompatible(org.apache.http.HttpHost otherhost)
Deprecated.
|
protected boolean |
sessionCompatible(java.net.URI otheruri) |
HTTPMethod |
setCompression(java.lang.String compressors) |
protected void |
setcontent(org.apache.http.client.methods.RequestBuilder rb) |
HTTPMethod |
setFollowRedirects(boolean tf) |
protected void |
setheaders(org.apache.http.client.methods.RequestBuilder rb) |
HTTPMethod |
setMethodHeaders(java.util.List<org.apache.http.Header> headers)
Deprecated.
|
HTTPMethod |
setRange(long lo,
long hi) |
HTTPMethod |
setRequestContent(org.apache.http.HttpEntity content) |
protected HTTPMethod |
setRequestHeader(org.apache.http.Header h)
Deprecated.
|
HTTPMethod |
setRequestHeader(java.lang.String name,
java.lang.String value)
Deprecated.
|
HTTPMethod |
setUserAgent(java.lang.String agent) |
HTTPMethod |
setUseSessions(boolean tf) |
protected HTTPSession session
protected boolean localsession
protected java.net.URI methodurl
protected java.lang.String userinfo
protected org.apache.http.HttpEntity content
protected ucar.httpservices.HTTPSession.Methods methodkind
protected HTTPMethodStream methodstream
protected boolean closed
protected org.apache.http.client.methods.HttpRequestBase request
protected org.apache.http.client.methods.CloseableHttpResponse response
protected long[] range
protected java.util.List<org.apache.http.Header> headers
public static java.util.Set<java.lang.String> getAllowedMethods()
protected org.apache.http.client.methods.RequestBuilder buildrequest() throws HTTPException
HTTPException
protected void setheaders(org.apache.http.client.methods.RequestBuilder rb)
protected void setcontent(org.apache.http.client.methods.RequestBuilder rb)
public int execute() throws HTTPException
HTTPException
public void close()
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
public java.lang.String getMethodKind()
public int getStatusCode()
public java.lang.String getStatusLine()
public java.lang.String getRequestLine()
public java.lang.String getPath()
public boolean canHoldContent()
public java.io.InputStream getResponseBodyAsStream()
public java.io.InputStream getResponseAsStream()
public byte[] getResponseAsBytes(int maxbytes)
public byte[] getResponseAsBytes()
public java.lang.String getResponseAsString(java.lang.String charset)
public java.lang.String getResponseAsString()
public org.apache.http.Header getRequestHeader(java.lang.String name)
public org.apache.http.Header getResponseHeader(java.lang.String name)
public org.apache.http.Header[] getResponseHeaders()
public HTTPMethod setRequestContent(org.apache.http.HttpEntity content)
public java.lang.String getCharSet()
public java.lang.String getURL()
public java.lang.String getStatusText()
public java.lang.String getResponseCharSet()
public HTTPSession getSession()
public boolean isSessionLocal()
public boolean hasStreamOpen()
public boolean isClosed()
public HTTPMethod setRange(long lo, long hi)
public org.apache.http.Header[] getRequestHeaders()
public org.apache.http.client.config.RequestConfig getDebugConfig()
public HTTPMethod setCompression(java.lang.String compressors)
public HTTPMethod setFollowRedirects(boolean tf)
public HTTPMethod setUserAgent(java.lang.String agent)
public HTTPMethod setUseSessions(boolean tf)
protected boolean sessionCompatible(org.apache.http.auth.AuthScope other)
other
- to test for compatibility against this method'sprotected boolean sessionCompatible(java.net.URI otheruri)
@Deprecated protected boolean sessionCompatible(org.apache.http.HttpHost otherhost)
public org.apache.http.HttpMessage debugRequest()
public org.apache.http.HttpResponse debugResponse()
@Deprecated public java.lang.String getName()
@Deprecated public HTTPMethod setMethodHeaders(java.util.List<org.apache.http.Header> headers) throws HTTPException
HTTPException
@Deprecated public HTTPMethod setRequestHeader(java.lang.String name, java.lang.String value) throws HTTPException
HTTPException
@Deprecated protected HTTPMethod setRequestHeader(org.apache.http.Header h) throws HTTPException
HTTPException