Oracle Fusion Middleware Java API Reference for Oracle Mobile Application Framework
2.0.0.0.0

E36392-01

oracle.adfmf.dc.ws.rest
Interface RestServiceAdapter


public interface RestServiceAdapter


Field Summary
static String REQUEST_TYPE_DELETE
           
static String REQUEST_TYPE_GET
           
static String REQUEST_TYPE_POST
           
static String REQUEST_TYPE_PUT
           
 
Method Summary
 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()
           
 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
 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.
 

Field Detail

REQUEST_TYPE_GET

static final String REQUEST_TYPE_GET
See Also:
Constant Field Values

REQUEST_TYPE_POST

static final String REQUEST_TYPE_POST
See Also:
Constant Field Values

REQUEST_TYPE_PUT

static final String REQUEST_TYPE_PUT
See Also:
Constant Field Values

REQUEST_TYPE_DELETE

static final String REQUEST_TYPE_DELETE
See Also:
Constant Field Values
Method Detail

addRequestProperty

void addRequestProperty(String key,
                        String value)
Add request property to the request header

Parameters:
key -
value -

clearRequestProperties

void clearRequestProperties()
Clear all previously set request properties


removeRequestProperty

void removeRequestProperty(String key)
Remove a request property from the request header

Parameters:
key -

getRequestProperties

java.util.HashMap getRequestProperties()
Returns:
all previously set request properties

getResponseHeader

String getResponseHeader(String key)
Retrieve response header

Parameters:
key -
Returns:
the value of this response header, or null if the key does not exist

getResponseHeaders

java.util.HashMap getResponseHeaders()
Returns:
all response headers

setRequestType

void setRequestType(String getPostPutDelete)
Set the request type for the REST call

Parameters:
getPostPutDelete - should be either GET, POST, PUT, or DELETE

getRequestType

String getRequestType()
Returns:
either GET, POST, PUT, or DELETE

getRetryLimit

int getRetryLimit()
Returns:
the maximum retries any request should attempt before determining the request will not succeed.

setRetryLimit

void setRetryLimit(int retries)
Set the maximum retries any request should attempt before determining the request will not succeed.

Parameters:
retries -

getConnectionName

String getConnectionName()
Set the connection name (referenced in connections.xml) that REST requests should be directed to.

Returns:
the connection name (referenced in connections.xml) that requests should be directed to

setConnectionName

void setConnectionName(String name)
Set the connection name (referenced in connections.xml) that REST requests should be directed to.

Parameters:
name -

send

String send(String payload)
            throws Exception
Send the REST request with the given payload

Parameters:
payload -
Returns:
the response as a string
Throws:
Exception
See Also:
RestWebServiceOperation.invoke(java.lang.String, java.util.Map), ADFbcRestWebServiceOperation.invoke(java.lang.String, java.util.Map)

sendReceive

byte[] sendReceive(String payload)
                   throws Exception
Send the REST request with the given payload

Parameters:
payload -
Returns:
the response as a byte[]
Throws:
Exception
See Also:
RestWebServiceOperation.invoke(java.lang.String, java.util.Map), ADFbcRestWebServiceOperation.invoke(java.lang.String, java.util.Map)

getHttpConnection

javax.microedition.io.HttpConnection getHttpConnection(String requestMethod,
                                                       String request,
                                                       Object httpHeadersValue)
                                                       throws Exception
Initializes and returns an HttpConnection, using the provided request method, request, and HTTP headers value. This also injects basic authentication into the request headers, from the credential store.
 
  // 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);
 
 

Parameters:
requestMethod - should be either GET, POST, PUT, or DELETE
request - 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.
Returns:
the connection
Throws:
Exception
See Also:
HttpConnection

getOutputStream

java.io.OutputStream getOutputStream(javax.microedition.io.HttpConnection connection)
                                     throws Exception
Open and return an output stream for the provided connection. Use this to stream your request from your application.

Parameters:
connection -
Returns:
the output stream for the connection
Throws:
Exception
See Also:
HttpConnection

getInputStream

java.io.InputStream getInputStream(javax.microedition.io.HttpConnection connection)
                                   throws Exception
Open and return an input stream for the provided connection. Use this to stream the result into your application. Use the HttpConnection getResponseStatus to determine the status of the request. The request status, response headers, and response content type are stored in this rest service adapter. If the response status is "OK" (200), the cookies in the cookie store will be updated from the contents of "Set-Cookie" in the response headers.

Parameters:
connection -
Returns:
the input stream for the connection
Throws:
Exception
See Also:
HttpConnection

close

void close(javax.microedition.io.HttpConnection connection)
Close the provided connection. Call this when using streams to send a REST request, or receive a REST response, with a custom payload.

Parameters:
connection -
Throws:
Exception
See Also:
HttpConnection

getConnectionEndPoint

String getConnectionEndPoint(String connName)
                             throws Exception
Return the end point of the connection, for the specified connection name, found in connections.xml. Also, apply the connection's credential store key, if any, to this rest service adapter.

Parameters:
connName - the connection name of the connection to find in connections.xml
Returns:
the end point of the connection
Throws:
Exception

getResponseStatus

int getResponseStatus()
Returns:
the response status corresponding to the last response received

getResponseContentType

String getResponseContentType()
Retrieve the content type of the response

Returns:
the response content type

setRequestURI

void setRequestURI(String uri)
Set the additional request URI

Parameters:
uri -

getRequestURI

String getRequestURI()
Returns:
the additional request URI

Oracle Fusion Middleware Java API Reference for Oracle Mobile Application Framework
2.0.0.0.0

E36392-01

Copyright © 2014 Oracle. All Rights Reserved.