public interface RestServiceAdapter
Modifier and Type | Field and Description |
---|---|
static String |
REQUEST_TYPE_DELETE |
static String |
REQUEST_TYPE_GET |
static String |
REQUEST_TYPE_POST |
static String |
REQUEST_TYPE_PUT |
Modifier and Type | Method and Description |
---|---|
void |
addRequestProperty(String key,
String value)
Add request property to the request header
|
void |
clearRequestProperties()
Clear all previously set request properties
|
void |
close(javax.microedition.io.HttpConnection connection)
Close the provided connection.
|
String |
getConnectionEndPoint(String connName)
Return the end point of the connection, for the specified connection name,
found in connections.xml.
|
String |
getConnectionName()
Set the connection name (referenced in connections.xml) that REST requests
should be directed to.
|
javax.microedition.io.HttpConnection |
getHttpConnection(String requestMethod,
String request,
Object httpHeadersValue)
Initializes and returns an HttpConnection, using the provided request
method, request, and HTTP headers value.
|
java.io.InputStream |
getInputStream(javax.microedition.io.HttpConnection connection)
Open and return an input stream for the provided connection.
|
java.io.OutputStream |
getOutputStream(javax.microedition.io.HttpConnection connection)
Open and return an output stream for the provided connection.
|
java.util.HashMap |
getRequestProperties() |
String |
getRequestType() |
String |
getRequestURI() |
String |
getResponseContentType()
Retrieve the content type of the response
|
String |
getResponseHeader(String key)
Retrieve response header
|
java.util.HashMap |
getResponseHeaders() |
String |
getResponseMessage() |
int |
getResponseStatus() |
int |
getRetryLimit() |
void |
removeRequestProperty(String key)
Remove a request property from the request header
|
String |
send(String payload)
Send the REST request with the given payload
|
byte[] |
sendReceive(String payload)
Send the REST request with the given payload
|
java.io.InputStream |
sendRequest(String payload)
Send a REST request with the given payload.
|
void |
setConnectionName(String name)
Set the connection name (referenced in connections.xml) that REST requests
should be directed to.
|
void |
setRequestType(String getPostPutDelete)
Set the request type for the REST call
|
void |
setRequestURI(String uri)
Set the additional request URI
|
void |
setRetryLimit(int retries)
Set the maximum retries any request should attempt before determining the
request will not succeed.
|
static final String REQUEST_TYPE_GET
static final String REQUEST_TYPE_POST
static final String REQUEST_TYPE_PUT
static final String REQUEST_TYPE_DELETE
void addRequestProperty(String key, String value)
key
- value
- void clearRequestProperties()
void removeRequestProperty(String key)
key
- java.util.HashMap getRequestProperties()
String getResponseHeader(String key)
key
- java.util.HashMap getResponseHeaders()
void setRequestType(String getPostPutDelete)
getPostPutDelete
- should be either GET, POST, PUT, or DELETEString getRequestType()
int getRetryLimit()
void setRetryLimit(int retries)
retries
- String getConnectionName()
void setConnectionName(String name)
name
- String send(String payload) throws Exception
payload
- Exception
RestWebServiceOperation.invoke(java.lang.String,
java.util.Map)
,
ADFbcRestWebServiceOperation.invoke(java.lang.String,
java.util.Map)
byte[] sendReceive(String payload) throws Exception
payload
- Exception
RestWebServiceOperation.invoke(java.lang.String,
java.util.Map)
,
ADFbcRestWebServiceOperation.invoke(java.lang.String,
java.util.Map)
java.io.InputStream sendRequest(String payload) throws java.io.IOException
ChunkedInputStream
class to read the
stream.
See .6.1
payload
- the payload to send to the server.java.io.IOException
javax.microedition.io.HttpConnection getHttpConnection(String requestMethod, String request, Object httpHeadersValue) throws Exception
// Create an instance of a RestServiceAdapter
RestServiceAdapter restServiceAdapter = Model.createRestServiceAdapter();
// Clear any previously set request properties, if any
restServiceAdapter.clearRequestProperties();
// Specify the type of request
String requestMethod = RestServiceAdapter.REQUEST_TYPE_GET;
// Get the connection end point from connections.xml
String requestEndPoint = restServiceAdapter.getConnectionEndPoint("GeoIP");
// Get the URI which is defined after the end point
String requestURI = "/xml/" + someIpAddress;
// The request is the end point + the URI being set
String request = requestEndPoint + requestURI;
// Specify some custom request headers
HashMap httpHeadersValue = new HashMap();
httpHeadersValue.put("Accept-Language", "en-US");
httpHeadersValue.put("My-Custom-Header-Item", "CustomItem1");
// Get the connection
HttpConnection connection = restServiceAdapter.getHttpConnection(requestMethod, request, httpHeadersValue);
requestMethod
- should be either GET, POST, PUT, or DELETErequest
- the fully qualified request (end point + request URI)httpHeadersValue
- An Object that implements the Map interface. Its key/value pairs
are assigned as request properties to the returned connection.Exception
HttpConnection
java.io.OutputStream getOutputStream(javax.microedition.io.HttpConnection connection) throws Exception
connection
- Exception
HttpConnection
java.io.InputStream getInputStream(javax.microedition.io.HttpConnection connection) throws Exception
connection
- Exception
HttpConnection
void close(javax.microedition.io.HttpConnection connection)
connection
- Exception
HttpConnection
String getConnectionEndPoint(String connName) throws Exception
connName
- the connection name of the connection to find in connections.xmlException
int getResponseStatus()
String getResponseMessage()
String getResponseContentType()
void setRequestURI(String uri)
uri
- String getRequestURI()