After you complete the registration and initialize the secure store, you can request data from the back end.
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 }
... 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(); …
/** * Logon channel identifiers * */ public enum Channel { REST, GATEWAY };
... 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.
getServiceDoc.setRequestMethod(SDMBaseRequest.REQUEST_METHOD_GET); getServiceDoc.setListener(this); reqMan.makeRequest(getServiceDoc);
You must handle exceptions as well.
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.
final class MySSlChallangeListener implements ISSLChallengeListener { @Override public boolean isServerTrusted(X509Certificate[] cer) { return true; } }