|
||||||||||
| 上一个类 下一个类 | 框架 无框架 | |||||||||
| 摘要: 嵌套 | 字段 | 构造方法 | 方法 | 详细信息: 字段 | 构造方法 | 方法 | |||||||||
java.lang.Objectcom.baidu.driver4j.bns.http.AbstractHttpRequestExecutor
com.baidu.driver4j.bns.http.SimpleHttpRequestExecutor
public class SimpleHttpRequestExecutor
SimpleHttpRequestExecutor implementation that uses standard J2SE facilities to execute POST requests, without support for HTTP authentication or advanced configuration options.
| 字段摘要 |
|---|
| 构造方法摘要 | |
|---|---|
SimpleHttpRequestExecutor()
|
|
| 方法摘要 | |
|---|---|
String |
doExecuteGETRequest(String serviceUrl)
Execute the given request through a standard J2SE HttpURLConnection. |
String |
doExecutePOSTRequest(String serviceUrl,
String content)
Execute the given request through a standard J2SE HttpURLConnection. |
protected boolean |
isGzipResponse(HttpURLConnection con)
Determine whether the given response is a GZIP response. |
protected HttpURLConnection |
openConnection(String serviceUrl)
Open an HttpURLConnection for the given remote invocation request. |
protected void |
prepareConnection(HttpURLConnection con,
int contentLength,
String method)
Prepare the given HTTP connection. |
protected InputStream |
readResponseBody(HttpURLConnection con)
Extract the response body from the given executed remote invocation request. |
protected void |
validateResponse(HttpURLConnection con)
Validate the given response as contained in the HttpURLConnection object, throwing an exception if it does not correspond to a successful HTTP response. |
protected void |
writeRequestBody(HttpURLConnection con,
ByteArrayOutputStream baos)
Set the given serialized remote invocation as request body. |
| 从类 com.baidu.driver4j.bns.http.AbstractHttpRequestExecutor 继承的方法 |
|---|
getConnectTimeout, getContentType, getReadTimeout, isAcceptGzipEncoding, setAcceptGzipEncoding, setConnectTimeout, setContentType, setReadTimeout |
| 从类 java.lang.Object 继承的方法 |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| 构造方法详细信息 |
|---|
public SimpleHttpRequestExecutor()
| 方法详细信息 |
|---|
public String doExecuteGETRequest(String serviceUrl)
throws IOException
This method implements the basic processing workflow: The actual work happens in this class's template methods.
invoker -
IOExceptionopenConnection(java.lang.String),
prepareConnection(java.net.HttpURLConnection, int, java.lang.String),
writeRequestBody(java.net.HttpURLConnection, java.io.ByteArrayOutputStream),
validateResponse(java.net.HttpURLConnection),
readResponseBody(java.net.HttpURLConnection)
public String doExecutePOSTRequest(String serviceUrl,
String content)
throws IOException
This method implements the basic processing workflow: The actual work happens in this class's template methods.
invoker -
IOExceptionopenConnection(java.lang.String),
prepareConnection(java.net.HttpURLConnection, int, java.lang.String),
writeRequestBody(java.net.HttpURLConnection, java.io.ByteArrayOutputStream),
validateResponse(java.net.HttpURLConnection),
readResponseBody(java.net.HttpURLConnection)
protected HttpURLConnection openConnection(String serviceUrl)
throws IOException
config - the HTTP invoker configuration that specifies the target service
IOException - if thrown by I/O methodsURL.openConnection()
protected void prepareConnection(HttpURLConnection con,
int contentLength,
String method)
throws IOException
The default implementation specifies POST as method, "application/x-java-serialized-object" as "Content-Type" header, and the given content length as "Content-Length" header.
con - the HTTP connection to preparecontentLength - the length of the content to send
IOException - if thrown by HttpURLConnection methodsHttpURLConnection.setRequestMethod(java.lang.String),
URLConnection.setRequestProperty(java.lang.String, java.lang.String)protected boolean isGzipResponse(HttpURLConnection con)
Default implementation checks whether the HTTP "Content-Encoding" header contains "gzip" (in any casing).
con - the HttpURLConnection to check
protected void validateResponse(HttpURLConnection con)
throws IOException
Default implementation rejects any HTTP status code beyond 2xx, to avoid parsing the response body and trying to deserialize from a corrupted stream.
con - the HttpURLConnection to validate
IOException - if validation failedHttpURLConnection.getResponseCode()
protected void writeRequestBody(HttpURLConnection con,
ByteArrayOutputStream baos)
throws IOException
The default implementation simply write the serialized invocation to the HttpURLConnection's OutputStream. This can be overridden, for example, to write a specific encoding and potentially set appropriate HTTP request headers.
con - the HttpURLConnection to write the request body tobaos - the ByteArrayOutputStream that contains the serialized RemoteInvocation object
IOException - if thrown by I/O methodsURLConnection.getOutputStream(),
URLConnection.setRequestProperty(java.lang.String, java.lang.String)
protected InputStream readResponseBody(HttpURLConnection con)
throws IOException
The default implementation simply reads the serialized invocation from the HttpURLConnection's InputStream. If the response is recognized as GZIP response, the InputStream will get wrapped in a GZIPInputStream.
con - the HttpURLConnection to read the response body from
IOException - if thrown by I/O methodsisGzipResponse(java.net.HttpURLConnection),
GZIPInputStream,
URLConnection.getInputStream(),
HttpURLConnection.getHeaderField(int),
HttpURLConnection.getHeaderFieldKey(int)
|
||||||||||
| 上一个类 下一个类 | 框架 无框架 | |||||||||
| 摘要: 嵌套 | 字段 | 构造方法 | 方法 | 详细信息: 字段 | 构造方法 | 方法 | |||||||||