Class WLClient
- java.lang.Object
-
- com.worklight.wlclient.api.WLClient
-
public class WLClient extends java.lang.ObjectThis singleton class exposes methods that you use to communicate with the MobileFirst Platform server.
-
-
Field Summary
Fields Modifier and Type Field and Description static java.lang.ObjectWAIT_LOCK
-
Method Summary
Methods Modifier and Type Method and Description voidaddGlobalHeader(java.lang.String headerName, java.lang.String value)You use this method to add a global header, which is sent on each request.voidconnect(WLResponseListener responseListener)Deprecated.Use WLAuthorizationManager.obtainAccessToken("", listener) This method sends an initialization request to the MobileFirst Platform Server, establishes a connection with the server, validates the application version and provides and Access Token.voidconnect(WLResponseListener responseListener, WLRequestOptions options)Deprecated.Use WLAuthorizationManager.obtainAccessToken("", listener) This method sends an initialization request to the MobileFirst Platform Server, establishes a connection with the server, validates the application version and provides and Access Token.static WLClientcreateInstance(Context context)This method creates the singleton instance of WLClient.protected java.util.HashtablegetchMap()java.net.CookieStoregetCookieStore()Retrieves the cookie store that is used by the framework when communicating with the server.voidgetDeviceDisplayName(DeviceDisplayNameListener listener)Gets the display name of the device.protected java.util.MapgetGlobalHeaders()static WLClientgetInstance()This method gets the singleton instance ofWLClient.java.net.URLgetServerUrl()Returns the current MobileFirst Platform server URLprotected java.lang.StringgetWLServerURL()voidinvokeProcedure(WLProcedureInvocationData invocationData, WLResponseListener responseListener)Deprecated.As of MobileFirst v8.0, replaced byWLResourceRequest.
Invokes an adapter procedure (similar toJavaScript WL.Client.invokeProcedure).The response is returned to the provided listener callback functions. Upon a successful response from the server, the listener's
onSuccess
is called.onFailure
is called in case of an error, including a login form response from the server, which is also considered an error.Example
The following code invokes a procedure "getStoriesFiltered" in the adapter "RSSReader" using a parameter "Africa":
String adapterName = "RSSReader"; String procedureName = "getStoriesFiltered"; WLProcedureInvocationData invocationData = new WLProcedureInvocationData(adapterName, procedureName); Object[] parameters = new Object[] {"africa"}; invocationData.setParameters(parameters); WLClient client = WLClient.getInstance(); client.invokeProcedure(invocationData, new MyInvokeListener(), options);voidinvokeProcedure(WLProcedureInvocationData invocationData, WLResponseListener responseListener, WLRequestOptions requestOptions)Deprecated.As of MobileFirst v8.0, replaced byWLResourceRequest
This method sends an asynchronous call to an adapter procedure. The response is returned to the callback functions of the specifiedWLResponseListener.
If the invocation succeeds,WLResponseListener.onSuccess(WLResponse)is called. If it fails,WLResponseListener.onFailure(WLFailResponse)is called.static booleanisApplicationSentToBackground()voidpinTrustedCertificatePublicKey(java.lang.String certificateFilename)Pins the host X509 certificate public key to the client application.voidpinTrustedCertificatePublicKey(java.lang.String[] certificateFileNames)Pins multiple X509 certificates' public key to the client application.voidregisterChallengeHandler(BaseChallengeHandler challengeHandler)You can use this method to register a challenge handler in the client.protected static voidreleaseInstance()voidremoveGlobalHeader(java.lang.String headerName)You use this method to remove a global header.voidsetDeviceDisplayName(java.lang.String deviceDisplayName, com.worklight.wlclient.WLRequestListener listener)Sets the display name of the device.voidsetHeartBeatInterval(int newInterval)Sets heart beat interval.voidsetServerUrl(java.net.URL url)Sets the MobileFirst Platform server URL to the specified URL
-
-
-
Method Detail
-
getGlobalHeaders
protected java.util.Map getGlobalHeaders()
-
getchMap
protected java.util.Hashtable getchMap()
-
createInstance
public static WLClient createInstance(Context context)
This method creates the singleton instance of WLClient.Note: This method is the first
WLClientmethod that you use.
It must be called before subsequent calls to getInstance.
It is advised to call this method from the context of Android application class onCreate method.
-
getInstance
public static WLClient getInstance()
This method gets the singleton instance ofWLClient.- Returns:
WLClient
-
releaseInstance
protected static void releaseInstance()
-
addGlobalHeader
public void addGlobalHeader(java.lang.String headerName, java.lang.String value)You use this method to add a global header, which is sent on each request.- Parameters:
headerName- Name of the headervalue- Value of the header
-
removeGlobalHeader
public void removeGlobalHeader(java.lang.String headerName)
You use this method to remove a global header. Then, the header is no longer sent on each request.- Parameters:
headerName- Name of the header
-
invokeProcedure
public void invokeProcedure(WLProcedureInvocationData invocationData, WLResponseListener responseListener, WLRequestOptions requestOptions)
Deprecated. As of MobileFirst v8.0, replaced byWLResourceRequest
This method sends an asynchronous call to an adapter procedure. The response is returned to the callback functions of the specifiedWLResponseListener.
If the invocation succeeds,WLResponseListener.onSuccess(WLResponse)is called. If it fails,WLResponseListener.onFailure(WLFailResponse)is called.- Parameters:
invocationData- Invocation data for the procedure call.responseListener- Listener object whose callback methodsWLResponseListener.onSuccess(WLResponse)andWLResponseListener.onFailure(WLFailResponse)are called.requestOptions- (optional) InvocationWLRequestOptionsoptions.
-
connect
public void connect(WLResponseListener responseListener)
Deprecated. Use WLAuthorizationManager.obtainAccessToken("", listener) This method sends an initialization request to the MobileFirst Platform Server, establishes a connection with the server, validates the application version and provides and Access Token.- Parameters:
responseListener- When a successful response is returned from the server, theWLResponseListener.onSuccess(WLResponse)method is called. If an error occurs, theWLResponseListener.onFailure(WLFailResponse)method is called.
-
connect
public void connect(WLResponseListener responseListener, WLRequestOptions options)
Deprecated. Use WLAuthorizationManager.obtainAccessToken("", listener) This method sends an initialization request to the MobileFirst Platform Server, establishes a connection with the server, validates the application version and provides and Access Token.- Parameters:
responseListener- When a successful response is returned from the server, theWLResponseListener.onSuccess(WLResponse)method is called. If an error occurs, theWLResponseListener.onFailure(WLFailResponse)method is called.options- WLRequestOptions instance
-
invokeProcedure
public void invokeProcedure(WLProcedureInvocationData invocationData, WLResponseListener responseListener)
Deprecated. As of MobileFirst v8.0, replaced byWLResourceRequest.
Invokes an adapter procedure (similar toJavaScript WL.Client.invokeProcedure).The response is returned to the provided listener callback functions. Upon a successful response from the server, the listener's
onSuccess
is called.onFailure
is called in case of an error, including a login form response from the server, which is also considered an error.Example
The following code invokes a procedure "getStoriesFiltered" in the adapter "RSSReader" using a parameter "Africa":
String adapterName = "RSSReader"; String procedureName = "getStoriesFiltered"; WLProcedureInvocationData invocationData = new WLProcedureInvocationData(adapterName, procedureName); Object[] parameters = new Object[] {"africa"}; invocationData.setParameters(parameters); WLClient client = WLClient.getInstance(); client.invokeProcedure(invocationData, new MyInvokeListener(), options);- Parameters:
invocationData- Invocation data parameters to send on the request.responseListener- Listener that will handle the response when returned from the server (on success or failure).
-
pinTrustedCertificatePublicKey
public void pinTrustedCertificatePublicKey(java.lang.String certificateFilename) throws java.lang.IllegalArgumentExceptionPins the host X509 certificate public key to the client application. Secured calls to the pinned remote host will be checked for a public key match. Secured calls to other hosts containing other certificates will be rejected. Some mobile operating systems might cache the certificate validation check results. Your app must call the certificate pinning method before making a secured request. Calling this method a second time overrides any previous pinning operation.- Parameters:
certificateFilename- path to the certificate under the assets folder.- Throws:
java.lang.IllegalArgumentException- ifcertificateFilenameis null, not found or is not in DER format.
-
pinTrustedCertificatePublicKey
public void pinTrustedCertificatePublicKey(java.lang.String[] certificateFileNames) throws java.lang.IllegalArgumentExceptionPins multiple X509 certificates' public key to the client application. Secured calls to the pinned remote hosts will be checked for a public key match. Secured calls to other hosts containing other certificates will be rejected. Some mobile operating systems might cache the certificate validation check results. Your app must call the certificate pinning method before making a secured request. Calling this method a second time overrides any previous pinning operation.- Parameters:
certificateFileNames- path to the certificates under the assets folder.- Throws:
java.lang.IllegalArgumentException- ifcertificateFileNamesis null, not found or is not in DER format.
-
setHeartBeatInterval
public void setHeartBeatInterval(int newInterval)
Sets heart beat interval.- Parameters:
newInterval- Interval value in seconds
-
isApplicationSentToBackground
public static boolean isApplicationSentToBackground()
-
registerChallengeHandler
public void registerChallengeHandler(BaseChallengeHandler challengeHandler)
You can use this method to register a challenge handler in the client. You must use this method when you implement custom challenge handlers. The challenge handler must extends eitherSecurityCheckChallengeHandlerorGatewayChallengeHandler.
Important: you must call this method at the beginning of your application after you initializeWLClient. Each challenge handler should only be registered once in the lifetime of the application.- Parameters:
challengeHandler- An instance of a challenge handler that extends eitherSecurityCheckChallengeHandlerorGatewayChallengeHandler.
-
getWLServerURL
protected java.lang.String getWLServerURL()
-
setServerUrl
public void setServerUrl(java.net.URL url)
Sets the MobileFirst Platform server URL to the specified URLChanges the MobileFirst Platform server URL to the new URL and cleans the HTTP client context. After calling this method, the application is not logged in to any server.
Notes:
- The responsibility for checking the validity of the URL is on the developer.
- This call does not clean the HTTP client context saved in JavaScript.
For hybrid applications, it is recommended to set the server URL by using the following JavaScript function:
WL.App.setServerUrl.
WLClient.getInstance().setServerUrl(new URL("http://9.148.23.88:10080/context"));- Parameters:
url- URL of the new server, including protocol, IP, port, and context.
-
getServerUrl
public java.net.URL getServerUrl()
Returns the current MobileFirst Platform server URL- Returns:
- MobileFirst Platform server URL
-
getCookieStore
public java.net.CookieStore getCookieStore()
Retrieves the cookie store that is used by the framework when communicating with the server.- Returns:
- The cookie store object
-
getDeviceDisplayName
public void getDeviceDisplayName(DeviceDisplayNameListener listener)
Gets the display name of the device. The display name is retrieved from the MobileFirst Server registration data.- Parameters:
listener- Listener whoseonSuccessoronFailuremethod is called upon request completion. The display name of the device is returned in thedeviceDisplayNameparameter of the listener'sonSuccessmethod.
-
setDeviceDisplayName
public void setDeviceDisplayName(java.lang.String deviceDisplayName, com.worklight.wlclient.WLRequestListener listener)Sets the display name of the device. The display name is stored in the MobileFirst Server registration data.- Parameters:
deviceDisplayName- The device display name to set.listener- Listener whoseonSuccessoronFailuremethod is called upon request completion.
-
-