@NotThreadSafe public class HTTPMethod extends Object implements Closeable, 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, and to allow use of Spring Servlet Mocking, 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 Map<String,String> |
headers |
protected org.apache.http.client.methods.HttpRequestBase |
lastrequest |
protected org.apache.http.HttpResponse |
lastresponse |
protected boolean |
localsession |
protected HTTPSession.Methods |
methodkind |
protected HTTPMethodStream |
methodstream |
protected URI |
methodurl |
static HTTPMethod.Executor |
MOCKEXECUTOR |
protected long[] |
range |
protected HTTPSession |
session |
protected Map<ucar.httpservices.HTTPSession.Prop,Object> |
settings |
static boolean |
TESTING |
protected 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,
Map<ucar.httpservices.HTTPSession.Prop,Object> settings) |
protected org.apache.http.client.config.RequestConfig |
buildRequestConfig(Map<ucar.httpservices.HTTPSession.Prop,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,
Map<ucar.httpservices.HTTPSession.Prop,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.
|
String |
getCharSet() |
org.apache.http.client.config.RequestConfig |
getDebugConfig() |
String |
getMethodKind() |
String |
getName()
Deprecated.
|
String |
getPath() |
protected org.apache.http.client.methods.RequestBuilder |
getRequestBuilder() |
org.apache.http.Header |
getRequestHeader(String name) |
org.apache.http.Header[] |
getRequestHeaders() |
String |
getRequestLine() |
byte[] |
getResponseAsBytes() |
byte[] |
getResponseAsBytes(int maxbytes) |
InputStream |
getResponseAsStream() |
String |
getResponseAsString() |
String |
getResponseAsString(String charset) |
InputStream |
getResponseBodyAsStream() |
String |
getResponseCharSet() |
org.apache.http.Header |
getResponseHeader(String name) |
org.apache.http.Header[] |
getResponseHeaders() |
HTTPSession |
getSession() |
int |
getStatusCode() |
String |
getStatusLine() |
String |
getStatusText() |
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(URI otheruri) |
HTTPMethod |
setCompression(String compressors) |
protected void |
setcontent(org.apache.http.client.methods.RequestBuilder rb) |
HTTPMethod |
setCredentials(org.apache.http.auth.Credentials creds) |
HTTPMethod |
setCredentials(org.apache.http.auth.Credentials creds,
org.apache.http.auth.AuthScope scope) |
HTTPMethod |
setFollowRedirects(boolean tf) |
protected void |
setheaders(org.apache.http.client.methods.RequestBuilder rb,
Map<String,String> headers) |
HTTPMethod |
setMaxRedirects(int n) |
HTTPMethod |
setMethodHeaders(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(String name,
String value)
Deprecated.
|
HTTPMethod |
setSOTimeout(int n) |
HTTPMethod |
setUserAgent(String agent) |
HTTPMethod |
setUseSessions(boolean tf) |
public static boolean TESTING
public static HTTPMethod.Executor MOCKEXECUTOR
protected HTTPSession session
protected boolean localsession
protected URI methodurl
protected 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 org.apache.http.client.config.RequestConfig debugconfig
protected HTTPMethod()
throws HTTPException
HTTPExceptionpublic int compareTo(HTTPMethod o)
compareTo in interface Comparable<HTTPMethod>protected void setcontent(org.apache.http.client.methods.RequestBuilder rb)
public void close()
close in interface Closeableclose in interface AutoCloseablepublic int execute()
throws HTTPException
HTTPExceptionpublic org.apache.http.HttpResponse executeRaw()
throws HTTPException
HTTPExceptionprotected org.apache.http.client.config.RequestConfig buildRequestConfig(Map<ucar.httpservices.HTTPSession.Prop,Object> settings) throws HTTPException
HTTPExceptionprotected void configClient(org.apache.http.impl.client.HttpClientBuilder cb,
Map<ucar.httpservices.HTTPSession.Prop,Object> settings)
throws HTTPException
HTTPExceptionprotected void setheaders(org.apache.http.client.methods.RequestBuilder rb,
Map<String,String> headers)
protected org.apache.http.client.methods.RequestBuilder getRequestBuilder()
throws HTTPException
HTTPExceptionprotected org.apache.http.client.methods.HttpRequestBase buildRequest(org.apache.http.client.methods.RequestBuilder rb,
Map<ucar.httpservices.HTTPSession.Prop,Object> settings)
throws HTTPException
HTTPExceptionpublic String getMethodKind()
public int getStatusCode()
public String getStatusLine()
public String getRequestLine()
public String getPath()
public boolean canHoldContent()
public InputStream getResponseBodyAsStream()
public InputStream getResponseAsStream()
public byte[] getResponseAsBytes(int maxbytes)
public byte[] getResponseAsBytes()
public String getResponseAsString()
public org.apache.http.Header getRequestHeader(String name)
public org.apache.http.Header getResponseHeader(String name)
public org.apache.http.Header[] getResponseHeaders()
public HTTPMethod setRequestContent(org.apache.http.HttpEntity content)
public String getCharSet()
public URI getURI()
public String getStatusText()
public 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 HTTPMethod setCompression(String compressors)
public HTTPMethod setFollowRedirects(boolean tf)
public HTTPMethod setMaxRedirects(int n)
public HTTPMethod setSOTimeout(int n)
public HTTPMethod setUserAgent(String agent)
public HTTPMethod setUseSessions(boolean tf)
public HTTPMethod setCredentials(org.apache.http.auth.Credentials creds) throws HTTPException
HTTPExceptionpublic HTTPMethod setCredentials(org.apache.http.auth.Credentials creds, org.apache.http.auth.AuthScope scope) throws HTTPException
HTTPExceptionprotected boolean sessionCompatible(org.apache.http.auth.AuthScope other)
other - to test for compatibility against this method'sprotected boolean sessionCompatible(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 String getName()
@Deprecated public HTTPMethod setMethodHeaders(List<org.apache.http.Header> headers) throws HTTPException
HTTPException@Deprecated public HTTPMethod setRequestHeader(String name, String value) throws HTTPException
HTTPException@Deprecated protected HTTPMethod setRequestHeader(org.apache.http.Header h) throws HTTPException
HTTPException