SDMConnectivity

The Network layer handles all network layer related tasks, hides the complexity of network communication, and provides easy to use APIs to the applications.

List of Features

  • Provides interfaces for request handling
  • Handles the requests asynchronously
  • Can handle the requests by multiple number of threads (configurable)

Technical Details and SDMConnectivity Public APIs

Note: The SUP APIs and their descriptions are available after the installation of Sybase Unwired Platform at the following location within your installation folder: ...\UnwiredPlatform\ClientAPI\apidoc.
The SDMRequestManager class implements the ISDMRequestManager interface, which provides the following methods:
ISDMRequestManager

void makeRequest(final ISDMRequest aRequest);
void makeRequest(final ISDMBundleRequest aBundleRequest)
ISDMConnectivitiyParameters getConnectivityParameters()
Vector getAllRequests()
int getQueueSize()
byte[] getRootContextID()
void terminate()
void pause()
void resume()
The number of working threads in the RequestManager class is configurable via the initialize(final SDMConnectivityParameters aParameters, final int aThreadNumber) method. The number of threads is maximized in four by the connectivity layer, because of performance related issues. If the client initializes the layer with more than the allowed threads, the implementation of the connectivity layer will decrease the thread number to the max allowed number. Methods defined by the SDMConnectivityParameters class:
ISDMConnectivityParameters

void setUserName(String aUserName)
String getUserName()
void setUserPassword(String aPassword)
String getUserPassword()
void setBaseUrl(String baseUrl)
String getBaseUrl()
String getLanguage()
void setLanguage(String language)
Sending requests with the connectivity layer consists of the following steps:
  1. Create the RequestManager class and initialize it with the required parameters.
  2. Create the request object. This can be done by implementing the ISDMRequest interface or by extending the SDMBaseRequest class which is the base implementation of the ISDMRequest interface. Both of them are provided by the connectivity layer.
  3. Add the request object to the SDMRequestManager.
Example

//create and fill parameters for Connectivity library
SDMConnectivityParameters params = new SDMConnectivityParameters();
params.setUserName("test");
params.setUserPassword("testpwd");
params.setLogger(Logger.getInstance()); //get the default Logger 
//create the RequestManager
SDMRequestManager reqManager = new SDMRequestManager();
//initialize it
reqManager.initialize(params, 2);//set the parameters and the thread number to be used
//create the request object
ISDMRequest testRequest = new SDMBaseRequest();
testRequest.setRequestUrl("http://test.de:8080/testpath");
testRequest.setRequestMethod(ISDMRequest.REQUEST_METHOD_GET);
testRequest.setPriority(ISDMRequest.PRIORITY_NORMAL);
//add the request to the connectivity layer
reManager.makeRequest(testRequest);

The tasks of the connectivity library have been divided into three main categories: managing the request queues, managing reading and writing to the input/output streams, and managing the platform specific connection creation.

The Connectivity component always performs the requests in asynchronous mode. The application’s role is to handle the request in sync mode. The component is able to perform HTTP and HTTPS requests, which you can use for developing and testing purposes, but the default is SUP Request. The threads in the connectivity library are responsible for taking the requests from the queue (FIFO - First in first out - algorithm) and performing the requests.

The number of working threads in the connection pool can be configured in the connectivity layer. There is only one queue, and this is handled by the SDMRequestManager, and the working threads take the requests from this queue. Applications are interacting only with the SDMRequestManager class; the other components of the connectivity library are not visible to them. The network component consists of three main parts:
  • SDMRequestManager: responsible for queuing the requests, managing the threads and keeping the connection with applications
  • ConnectionHandler: responsible for performing the request
  • ConnectionFactory: responsible for creating and managing platform dependent connections to the server

An application can have more than one SDMRequestManager, for example, when connecting to two different servers at the same time.

There is built-in support for setting the timeout for the socket connection, the application can use the SDMConnectivityParameters object to modify the value.
int TIMEOUT = 3500;

ISDMPreferences preferences = new SDMPreferences();

preferences.setPreference(ISDMPreferences.CONNECTION_TIMEOUT_MS, String.valueOf(TIMEOUT));

requestManager = new SDMRequestManager(logger, preferences, parameters, NUM_OF_HTTP_EXECUTION_THREADS);

SDMRequest Object

An SDMRequest object wraps all the information which is needed by the connectivity library to be able to perform the requests. The connectivity library interacts with the request object to query the necessary information about the headers, the post data, and so on.

The connectivity layer also uses the request object to notify the application about the result of the request using the ISDMNetListener interface. The connectivity component provides an interface called the ISDMRequest and a base implementation of it called the SDMBaseRequest. The applications have to extend this base class when creating new application specific requests. The ISDMRequest interface defines the following public APIs:
ISDMRequest

void setRequestUrl(final String aUrl)
String getRequestUrl()
void setRequestMethod(final int aRequestMethod)
int getRequestMethod()
byte[] getData()
void setPriority(final int aPriority)
int getPriority()
boolean useCookies()
void setListener(final ISDMNetListener aListener)
ISDMNetListener getListener()
boolean hasPostData()
void postData(OutputStream os)
void setHeaders(final Hashtable aHashtable)
Hashtable getHeaders()
void appendHeaders(final Hashtable aHashtable)
void appendHeader(final String aHeaderName, final String aHeaderValue)
The ISDMNetListener interface can be used by the client to be notified by the connectivity layer about the result of a request. Usage of this feature is not mandatory, however, you can handle incidental errors with it. Methods available in the ISDMNetListener interface:
ISDMNetListener

void onSuccess(ISDMRequest aRequest, IHttpResponse aResponse)
void onError(ISDMRequest aRequest, IHttpResponse aResponse, ISDMRequestStateElement aRequestStateElement)
The role of the SDMRequestStateElement object used by the connectivity library is to provide the application with more detail on the occurred error. Methods available in SDMRequestStateElement object:
ISDMRequestStateElement

int getErrorCode()
void setErrorCode(final int code)
int getHttpStatusCode()
void setHttpStatusCode(final int httpStatus)
Exception getException()
void setException(final Exception aException)
String getRedirectLocation()
IHttpResponse getResponse()
Example

public void onSuccess(ISDMRequest  aRequest, SDMHttpResponse aResponse) {
	 System.out.println("Http response status code:" + aResponse.getStatusCode());
	 System.out.println("Cookie string:" + aResponse.getCookieString());
	 byte[] content = aResponse.getContent();
	 String response = new String(content);
	 System.out.println("Received content:" + response);
	 //get the headers
	 Hashtable headers = aResponse.getHeaders();
}