@NotThreadSafe public class HTTPMethod extends java.lang.Object implements java.io.Closeable, java.lang.Comparable<HTTPMethod>
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 the session was constructed with a specified URL, then any url specified to HTTMethod (via the factory) 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 tedious proposition. To support this use case, HTTPMethod supports what amounts to a one-shot use. The steps are as follows:
For testing purposes, it is possible to set a special execution action (see executeRaw).
Modifier and Type | Class and Description |
---|---|
static interface |
HTTPMethod.Executor |
Modifier and Type | Field and Description |
---|---|
protected boolean |
closed |
protected org.apache.http.HttpEntity |
content |
protected org.apache.http.client.config.RequestConfig |
debugconfig |
protected boolean |
executed |
protected java.util.Map<java.lang.String,java.lang.String> |
headers |
protected boolean |
islocalsession |
protected org.apache.http.client.methods.HttpRequestBase |
lastrequest |
protected org.apache.http.HttpResponse |
lastresponse |
protected HTTPSession.Methods |
methodkind |
protected HTTPMethodStream |
methodstream |
protected java.net.URI |
methodurl |
protected long[] |
range |
protected HTTPSession |
session |
protected java.util.Map<ucar.httpservices.HTTPSession.Prop,java.lang.Object> |
settings |
static boolean |
TESTING |
protected java.lang.String |
userinfo |
Modifier | Constructor and Description |
---|---|
protected |
HTTPMethod() |
Modifier and Type | Method and Description |
---|---|
protected org.apache.http.client.methods.HttpRequestBase |
buildRequest(org.apache.http.client.methods.RequestBuilder rb,
java.util.Map<ucar.httpservices.HTTPSession.Prop,java.lang.Object> settings) |
protected org.apache.http.client.config.RequestConfig |
buildRequestConfig(java.util.Map<ucar.httpservices.HTTPSession.Prop,java.lang.Object> settings) |
boolean |
canHoldContent() |
void |
close()
Calling close will force the method to close, and will
force any open stream to terminate.
|
int |
compareTo(HTTPMethod o) |
protected void |
configClient(org.apache.http.impl.client.HttpClientBuilder cb,
java.util.Map<ucar.httpservices.HTTPSession.Prop,java.lang.Object> settings) |
org.apache.http.client.methods.HttpRequestBase |
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.
|
org.apache.http.HttpResponse |
executeRaw()
Create a request, add headers, and content,
then send to HTTPSession to do the bulk of the work.
|
java.lang.String |
getCharSet() |
org.apache.http.client.config.RequestConfig |
getDebugConfig() |
java.lang.String |
getMethodKind() |
java.lang.String |
getName()
Deprecated.
|
java.lang.String |
getPath() |
protected org.apache.http.client.methods.RequestBuilder |
getRequestBuilder() |
com.google.common.collect.Multimap<java.lang.String,java.lang.String> |
getRequestHeaders()
Get all Request headers as a map of name to list of values.
|
java.util.Optional<java.lang.String> |
getRequestHeaderValue(java.lang.String name) |
com.google.common.collect.ImmutableSortedMap<java.lang.String,com.google.common.collect.ImmutableList<HttpNameValue>> |
getRequestHeaderValues() |
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() |
com.google.common.collect.Multimap<java.lang.String,java.lang.String> |
getResponseHeaders()
Get all Response headers as a map of name to list of values.
|
java.util.Optional<java.lang.String> |
getResponseHeaderValue(java.lang.String name) |
com.google.common.collect.ImmutableSortedMap<java.lang.String,com.google.common.collect.ImmutableList<HttpNameValue>> |
getResponseHeaderValues() |
HTTPSession |
getSession() |
int |
getStatusCode() |
java.lang.String |
getStatusLine() |
java.lang.String |
getStatusText() |
java.net.URI |
getURI() |
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,
java.util.Map<java.lang.String,java.lang.String> headers) |
HTTPMethod |
setMaxRedirects(int n) |
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 |
setSOTimeout(int n) |
HTTPMethod |
setUserAgent(java.lang.String agent) |
HTTPMethod |
setUseSessions(boolean tf) |
public static boolean TESTING
protected HTTPSession session
protected boolean islocalsession
protected java.net.URI methodurl
protected java.lang.String userinfo
protected org.apache.http.HttpEntity content
protected HTTPSession.Methods methodkind
protected HTTPMethodStream methodstream
protected org.apache.http.client.methods.HttpRequestBase lastrequest
protected org.apache.http.HttpResponse lastresponse
protected long[] range
protected boolean closed
protected boolean executed
protected java.util.Map<java.lang.String,java.lang.String> headers
protected java.util.Map<ucar.httpservices.HTTPSession.Prop,java.lang.Object> settings
protected org.apache.http.client.config.RequestConfig debugconfig
protected HTTPMethod() throws HTTPException
HTTPException
public int compareTo(HTTPMethod o)
compareTo
in interface java.lang.Comparable<HTTPMethod>
protected void setcontent(org.apache.http.client.methods.RequestBuilder rb)
public void close()
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
public int execute() throws HTTPException
HTTPException
public org.apache.http.HttpResponse executeRaw() throws HTTPException
HTTPException
protected org.apache.http.client.config.RequestConfig buildRequestConfig(java.util.Map<ucar.httpservices.HTTPSession.Prop,java.lang.Object> settings) throws HTTPException
HTTPException
protected void configClient(org.apache.http.impl.client.HttpClientBuilder cb, java.util.Map<ucar.httpservices.HTTPSession.Prop,java.lang.Object> settings) throws HTTPException
HTTPException
protected void setheaders(org.apache.http.client.methods.RequestBuilder rb, java.util.Map<java.lang.String,java.lang.String> headers)
protected org.apache.http.client.methods.RequestBuilder getRequestBuilder() throws HTTPException
HTTPException
protected org.apache.http.client.methods.HttpRequestBase buildRequest(org.apache.http.client.methods.RequestBuilder rb, java.util.Map<ucar.httpservices.HTTPSession.Prop,java.lang.Object> settings) throws HTTPException
HTTPException
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 java.util.Optional<java.lang.String> getRequestHeaderValue(java.lang.String name)
public com.google.common.collect.Multimap<java.lang.String,java.lang.String> getRequestHeaders()
public java.util.Optional<java.lang.String> getResponseHeaderValue(java.lang.String name)
public com.google.common.collect.Multimap<java.lang.String,java.lang.String> getResponseHeaders()
public com.google.common.collect.ImmutableSortedMap<java.lang.String,com.google.common.collect.ImmutableList<HttpNameValue>> getRequestHeaderValues()
public com.google.common.collect.ImmutableSortedMap<java.lang.String,com.google.common.collect.ImmutableList<HttpNameValue>> getResponseHeaderValues()
public HTTPMethod setRequestContent(org.apache.http.HttpEntity content)
public java.lang.String getCharSet()
public java.net.URI getURI()
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 HTTPMethod setCompression(java.lang.String compressors)
public HTTPMethod setFollowRedirects(boolean tf)
public HTTPMethod setMaxRedirects(int n)
public HTTPMethod setSOTimeout(int n)
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.client.config.RequestConfig getDebugConfig()
public org.apache.http.client.methods.HttpRequestBase 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