|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.yosokumo.core.YosokumoRequest
class YosokumoRequest
Implements all HTTP requests to the Yosokumo web service. These are the basic methods:
Field Summary | |
---|---|
private java.lang.String |
auxHeaderName
|
private java.lang.String |
auxHeaderValue
|
private java.lang.String |
contentType
|
private Credentials |
credentials
|
private byte[] |
entity
|
private ServiceException |
exception
|
private java.lang.String |
hostName
|
private int |
port
|
private int |
statusCode
|
private boolean |
trace
|
Constructor Summary | |
---|---|
YosokumoRequest(Credentials credentials,
java.lang.String hostName,
int port,
java.lang.String contentType)
Initializes a newly created YosokumoRequest object with
attributes specified by the input parameters. |
Method Summary | |
---|---|
private void |
appendHeaderValue(org.apache.http.HttpRequest r,
java.lang.String headerName,
java.lang.StringBuilder s)
Append an HTTP header value. |
boolean |
deleteFromServer(java.lang.String resourceUri)
Issue an HTTP DELETE request. |
byte[] |
getEntity()
Return the entity from an HTTP response. |
ServiceException |
getException()
Return the exception from an HTTP process. |
boolean |
getFromServer(java.lang.String resourceUri)
Issue an HTTP GET request. |
private boolean |
getResponse(org.apache.http.client.methods.HttpRequestBase httpRequest,
java.lang.String traceName)
Execute an HTTP request and process the response. |
int |
getStatusCode()
Return the status code from an HTTP response. |
boolean |
getTrace()
Return the trace flag. |
void |
initForOperation()
Initialize for an HTTP operation. |
private java.lang.String |
makeDigest(org.apache.http.client.methods.HttpRequestBase request)
Make a digest of an HTTP request. |
private boolean |
makeRequest(org.apache.http.client.methods.HttpRequestBase httpRequest,
byte[] entityToSend,
java.lang.String traceName)
Make an HTTP request. |
private java.lang.String |
makeRequestString(org.apache.http.client.methods.HttpRequestBase r)
Make a string from an HTTP request. |
private java.lang.String |
normalizeResourceUri(java.lang.String resourceUri,
java.lang.String hostName,
int port)
Normalize a resource URI. |
boolean |
postToServer(java.lang.String resourceUri,
byte[] entityToPost)
Issue an HTTP POST request. |
boolean |
putToServer(java.lang.String resourceUri,
byte[] entityToPut)
Issue an HTTP PUT request. |
void |
setAuxHeader(java.lang.String name,
java.lang.String value)
Set the auxiliary header. |
void |
setCredentials(Credentials credentials)
Set the credentials. |
void |
setTrace(boolean traceOn)
Set the trace flag. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private boolean trace
private Credentials credentials
private java.lang.String hostName
private int port
private java.lang.String contentType
private java.lang.String auxHeaderName
private java.lang.String auxHeaderValue
private int statusCode
private byte[] entity
private ServiceException exception
Constructor Detail |
---|
public YosokumoRequest(Credentials credentials, java.lang.String hostName, int port, java.lang.String contentType)
YosokumoRequest
object with
attributes specified by the input parameters.
credentials
- specifies user id and key for authentication.hostName
- is the name of the Yosokumo server.port
- is the port to use to access the Yosokumo service.contentType
- is the content type to use in HTTP communications
with the Yosokumo server (e.g., application/yosokumo+protobuf).Method Detail |
---|
public void initForOperation()
public void setCredentials(Credentials credentials)
credentials
- to use in HTTP communications to authorize the
user on the Yokosumo server.public void setAuxHeader(java.lang.String name, java.lang.String value)
name
- is the name of the auxiliary header, e.g.,
"x-yosokumo-full-entries".value
- is the value of the auxiliary header, e.g., "on".public void setTrace(boolean traceOn)
traceOn
- is the value to assign to the trace flag.public boolean getTrace()
public int getStatusCode()
public byte[] getEntity()
public ServiceException getException()
null
means there is no exception. Otherwise the return
value is an exception from an HTTP response.public boolean getFromServer(java.lang.String resourceUri)
resourceUri
- is the URI of the resource to get.
false
means there was a problem (call
getStatusCode()
, getEntity()
, and
getException()
for more information).
true
means the request was successful. Call
getStatusCode()
and getEntity()
to obtain the data returned from the server.public boolean postToServer(java.lang.String resourceUri, byte[] entityToPost)
resourceUri
- is the URI of the resource to post to.
false
means there was a problem (call
getStatusCode()
, getEntity()
, and
getException()
for more information).
true
means the request was successful. Call
getStatusCode()
and getEntity()
to obtain the data returned from the server.public boolean deleteFromServer(java.lang.String resourceUri)
resourceUri
- is the URI of the resource to delete.
false
means there was a problem (call
getStatusCode()
, getEntity()
, and
getException()
for more information).
true
means the request was successful. Call
getStatusCode()
and getEntity()
for more information.public boolean putToServer(java.lang.String resourceUri, byte[] entityToPut)
resourceUri
- is the URI where to put the resource.entityToPut
- is entity to put to the server.
false
means there was a problem (call
getStatusCode()
, getEntity()
, and
getException()
for more information).
true
means the request was successful. Call
getStatusCode()
and getEntity()
for more information.private boolean makeRequest(org.apache.http.client.methods.HttpRequestBase httpRequest, byte[] entityToSend, java.lang.String traceName)
httpRequest
- is HttpGet, HttpPut, HttpPost, or HttpDelete.entityToSend
- is an entity to put to the server.traceName
- is the name of the request to be used in trace output.
false
means there was a problem (call
getStatusCode()
, getEntity()
, and
getException()
for more information).
true
means the request was successful. Call
getStatusCode()
and getEntity()
for more information.private boolean getResponse(org.apache.http.client.methods.HttpRequestBase httpRequest, java.lang.String traceName)
httpRequest
- is an HTTP request, ready to be executedtraceName
- is the name of the request to be used in trace output.
false
means there was a problem (call
getStatusCode()
, getEntity()
, and
getException()
for more information).
true
means the request was successful. Call
getStatusCode()
and getEntity()
for more information.private java.lang.String normalizeResourceUri(java.lang.String resourceUri, java.lang.String hostName, int port)
"http://"
but the next part of
the URI is not the host name: Return the URI as is.
"http://"
+hostname: Return the
URI with ":"+port
inserted after the host name.
"http://"
prepended.
"http://"+hostName+":"+port
prepended.
"http://"+hostName
prefix, despite the
fact that the HTTP request lines created by these classes strip the
prefix and use only the resource URI. This normalization method
allows the programmer to use only the URI, or the fully-prefixed
URI, whichever is more convenient.
resourceUri
- the input URI to normalize.hostName
- the host name to use.port
- the port to use.
private java.lang.String makeDigest(org.apache.http.client.methods.HttpRequestBase request)
request
- is the HTTP request to digest.
null
means there was a problem; exception
is set. Otherwise the return value is a digest of the
input request.private java.lang.String makeRequestString(org.apache.http.client.methods.HttpRequestBase r)
r
- is the input HTTP request.
private void appendHeaderValue(org.apache.http.HttpRequest r, java.lang.String headerName, java.lang.StringBuilder s)
r
- is the input HTTP request.headerName
- is the name of the header whose value is wanted.s
- is the string to append the header value to.
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |