Data Requests

After you complete the registration and initialize the secure store, you can request data from the back end.

Copy this code in any activity to execute a service document request. This example places the code in the main Activity class, which also implements the INetListener interface:
	private final String LOG_TAG = "MAIN_ACTIVITY";
	
	private void downloadServiceDocument() throws PreferencesException {
		ILogger logger = new Logger();
		
		
		LogonCore lcCore = LogonCore.getInstance();
		
		Channel channel = lcCore.getLogonContext().getChannel();
		
		boolean isHttpsConnection = lcCore.getLogonContext().isHttps(); 
		String host = lcCore.getLogonContext().getHost();
		int port = lcCore.getLogonContext().getPort();
		String suffix = lcCore.getLogonContext().getResourcePath();
		String appID = lcCore.getLogonContext().getAppId();
		String addr;
				
		IPreferences pref = new Preferences(this, logger);
		ConnectivityParameters param = new ConnectivityParameters();
		BaseRequest getServiceDoc = new BaseRequest();
		RequestManager reqMan = null;				
		try {
			
			LogonContext lgContext = LogonManager.getInstance().getLogonContext(this);
			param.setUserName(lgContext.getEndPointUser());
			param.setUserPassword(lgContext.getEndPointPassword());
			reqMan = new RequestManager(logger, pref, param, 1);
			MySSlChallangeListener mscl = new MySSlChallangeListener();
			reqMan.setSSLChallengeListener(mscl);

			
			if (channel == Channel.REST) {
				
				if (isHttpsConnection) {
					addr = "https://" + host + ":" + port + suffix + "/"
							+ appID;
					MAFLogger.i(LOG_TAG, "REST getServiceDoc request sent to: "
							+ addr);
				} else {
					addr = "http://" + host + ":" + port + suffix + "/" + appID
							+ "/";
					MAFLogger.i(LOG_TAG, "REST getServiceDoc request sent to: "
							+ addr);
				}
				getServiceDoc.setRequestUrl(addr);
			
			} else if (channel == Channel.GATEWAY) {
			
				addr = "http://<GW_HOST>:<PORT>/<GW_CONTENT_URL>/";
				MAFLogger.i(LOG_TAG, "GATEWAY getServiceDoc request sent to: "
						+ addr);
				getServiceDoc.setRequestUrl(addr);
			
		} catch (LogonManagerException e) {
			e.printStackTrace();
			runOnUiThread(new Runnable() {
				@Override
				public void run() {
					MAFToast.makeText(act, "Failed to download service document", MAFToast.LENGTH_SHORT).show();
				}
			});
		}
		getServiceDoc.setRequestMethod(BaseRequest.REQUEST_METHOD_GET);
		getServiceDoc.setListener(this);
				
		reqMan.makeRequest(getServiceDoc);	
	}
	
	
	final class MySSlChallangeListener implements com.sap.mobile.lib.request.HttpChannelListeners.ISSLChallengeListener {

		@Override
		public boolean isServerTrusted(java.security.cert.X509Certificate[] arg0) {
			return true;
		}
	}


	@Override
	public void onError(IRequest arg0, IResponse arg1, IRequestStateElement arg2) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onSuccess(IRequest arg0, IResponse arg1) {
		// TODO Auto-generated method stub
		
	}
First, get an MAFLogonCore instance in the downloadServiceDocument method:
...
LogonCore lcCore = LogonCore.getInstance();
…
Then, you can get additional information about the earlier registration:
	…
	Channel channel = lcCore.getLogonContext().getChannel();
	boolean isHttpsConnection = lcCore.getLogonContext().isHttps(); 
	String host = lcCore.getLogonContext().getHost();
	int port = lcCore.getLogonContext().getPort();
	String suffix = lcCore.getLogonContext().getResourcePath();
	String appID = lcCore.getLogonContext().getAppId();
	…
The Channel class contains information about the registration type:
	/**
	 * Logon channel identifiers
	 * 
	 */
	public enum Channel {
		REST, GATEWAY
	};
Based on the information, you can construct a request address:
...
String addr;
…
pref = new Preferences(this, logger);
param = new ConnectivityParameters();
getServiceDoc = new BaseRequest();
…
if(channel == Channel.REST){
		if (isHttpsConnection) {
			addr = "https://" + host + ":" + port + suffix + "/" + appID;
			MAFLogger.i(TAG, "REST getServiceDoc request sent to: " + addr);
		} else {
			addr = "http://" + host + ":" + port + suffix + "/" + appID+"/";
			MAFLogger.i(TAG, "REST getServiceDoc request sent to: " + addr);
		}
		getServiceDoc.setRequestUrl(addr);
	} else if(channel == Channel.GATEWAY){
		addr = "http://<GW_HOST>:<PORT>/<GW_CONTENT_URL>/";
		MAFLogger.i(TAG, "GATEWAY getServiceDoc request sent to: " + addr);
		getServiceDoc.setRequestUrl(addr);
	}	else if(channel == Channel.IMO){
		getServiceDoc.setRequestUrl(lgContext.getEndPointUrl());
	}

This way you can prepare for all Channel types. getServiceDoc is an instance of the BaseRequest class, for which you can set the constructed service address.

You can now start your requests:
	getServiceDoc.setRequestMethod(SDMBaseRequest.REQUEST_METHOD_GET);
	getServiceDoc.setListener(this);
			
	reqMan.makeRequest(getServiceDoc);

You must handle exceptions as well.

Mutual Certificate Handling

MAF supports mutual certificate-based data requests. To execute requests with certificates, set an identity into the SAP Mobile Platform RequestManager:
reqMan = new RequestManager(logger, pref, param, 1);
MySSlChallangeListener mscl = new MySSlChallangeListener();
	if(lgcCtx.getUserCreationPolicy().equals(UserCreationPolicy.certificate)){
	HttpsClientCertInfo certInfo = LogonUIFacade.getClientCertInfo(appID);
		if(certInfo != null){
			MutualCertificateHandler mch = new MutualCertificateHandler(certInfo);
				reqMan.setMutualSSLChallengeListener(mch);
		}
}
	reqMan.setSSLChallengeListener(mscl);
In this code, the MySSLChallengeListener is the class that the application must implement. MAF calls this listener when the user creation policy is set to certificate and SAP Mobile Platform server-side security configuration used during registration is set to support mutual certificate handling.
A sample implementation of the listener:
final class MySSlChallangeListener implements ISSLChallengeListener {

		@Override
		public boolean isServerTrusted(X509Certificate[] cer) {

			return true;
		}
	}