public class WLClient
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.lang.Object |
WAIT_LOCK |
Modifier and Type | Method and Description |
---|---|
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.
|
void |
backendService(java.lang.String service,
WLResponseListener responseListener) |
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.
|
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.
|
static WLClient |
createInstance(Context context)
This method creates the singleton instance of WLClient.
|
BaseChallengeHandler |
getBaseChallengeHandler(java.lang.String securityCheck) |
Context |
getContext() |
java.net.CookieStore |
getCookieStore()
Retrieves the cookie store that is used by the framework when communicating with the server.
|
void |
getDeviceDisplayName(DeviceDisplayNameListener listener)
Gets the display name of the device.
|
GatewayChallengeHandler |
getGatewayChallengeHandler(java.lang.String handlerName) |
GatewayChallengeHandler |
getGatewayChallengeHandler(WLResponse response) |
static WLClient |
getInstance()
This method gets the singleton instance of
WLClient . |
ClearableCookieJar |
getPersistentCookies()
Retrieves the persistent cookie that is used by the framework when communicating with the server.
|
SecurityCheckChallengeHandler |
getSecurityCheckChallengeHandler(java.lang.String securityCheck) |
java.net.URL |
getServerUrl()
Returns the current MobileFirst Platform server URL
|
void |
invokeProcedure(WLProcedureInvocationData invocationData,
WLResponseListener responseListener)
Deprecated.
As of MobileFirst v8.0, replaced by
WLResourceRequest . Invokes an adapter procedure (similar to JavaScript WL.Client.invokeProcedure ).
The response is returned to the provided listener callback functions. Upon a successful response from the server, the listener's onSuccessis called. onFailureis 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); |
void |
invokeProcedure(WLProcedureInvocationData invocationData,
WLResponseListener responseListener,
WLRequestOptions requestOptions)
Deprecated.
As of MobileFirst v8.0, replaced by
WLResourceRequest This method sends an asynchronous call to an adapter procedure. The response is returned to the callback functions of the specified WLResponseListener .
If the invocation succeeds, WLResponseListener.onSuccess(WLResponse) is called. If it fails, WLResponseListener.onFailure(WLFailResponse) is called. |
static boolean |
isApplicationSentToBackground() |
boolean |
isGatewayResponse(WLResponse response) |
void |
pinTrustedCertificatePublicKey(java.lang.String certificateFilename)
Pins the host X509 certificate public key to the client application.
|
void |
pinTrustedCertificatePublicKey(java.lang.String[] certificateFileNames)
Pins multiple X509 certificates' public key to the client application.
|
void |
registerChallengeHandler(BaseChallengeHandler challengeHandler)
You can use this method to register a challenge handler in the client.
|
void |
removeGlobalHeader(java.lang.String headerName)
You use this method to remove a global header.
|
java.lang.String |
resetDeviceID()
Resets Device ID in MobileFirst SDK
|
void |
setDeviceDisplayName(java.lang.String deviceDisplayName,
WLRequestListener listener)
Sets the display name of the device.
|
void |
setDeviceID(java.lang.String uuid)
Sets the Device ID MobileFirst SDK
|
void |
setHeartBeatInterval(int newInterval)
Sets heart beat interval.
|
void |
setServerUrl(java.net.URL url)
Sets the MobileFirst Platform server URL to the specified URL
|
public Context getContext()
public static WLClient createInstance(Context context)
Note: This method is the first WLClient
method 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.
public static WLClient getInstance()
WLClient
.WLClient
public void addGlobalHeader(java.lang.String headerName, java.lang.String value)
headerName
- Name of the headervalue
- Value of the headerpublic void removeGlobalHeader(java.lang.String headerName)
headerName
- Name of the headerpublic void invokeProcedure(WLProcedureInvocationData invocationData, WLResponseListener responseListener, WLRequestOptions requestOptions)
WLResourceRequest
WLResponseListener
.
If the invocation succeeds, WLResponseListener.onSuccess(WLResponse)
is called. If it fails, WLResponseListener.onFailure(WLFailResponse)
is called.invocationData
- Invocation data for the procedure call.responseListener
- Listener object whose callback methods WLResponseListener.onSuccess(WLResponse)
and WLResponseListener.onFailure(WLFailResponse)
are called.requestOptions
- (optional) Invocation WLRequestOptions
options.public void backendService(java.lang.String service, WLResponseListener responseListener)
public void connect(WLResponseListener responseListener)
responseListener
- When a successful response is returned from the server, the WLResponseListener.onSuccess(WLResponse)
method is called. If an error occurs,
the WLResponseListener.onFailure(WLFailResponse)
method is called.public void connect(WLResponseListener responseListener, WLRequestOptions options)
responseListener
- When a successful response is returned from the server, the WLResponseListener.onSuccess(WLResponse)
method is called. If an error occurs,
the WLResponseListener.onFailure(WLFailResponse)
method is called.options
- WLRequestOptions instancepublic void invokeProcedure(WLProcedureInvocationData invocationData, WLResponseListener responseListener)
WLResourceRequest
. JavaScript WL.Client.invokeProcedure
).
The response is returned to the provided listener callback functions. Upon a successful response from the server, the listener's
onSuccessis called.
onFailureis 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);
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).public void pinTrustedCertificatePublicKey(java.lang.String certificateFilename) throws java.lang.IllegalArgumentException
certificateFilename
- path to the certificate under the assets folder.java.lang.IllegalArgumentException
- if certificateFilename
is null, not found or is not in DER format.public void pinTrustedCertificatePublicKey(java.lang.String[] certificateFileNames) throws java.lang.IllegalArgumentException
certificateFileNames
- path to the certificates under the assets folder.java.lang.IllegalArgumentException
- if certificateFileNames
is null, not found or is not in DER format.public void setHeartBeatInterval(int newInterval)
newInterval
- Interval value in secondspublic static boolean isApplicationSentToBackground()
public void registerChallengeHandler(BaseChallengeHandler challengeHandler)
SecurityCheckChallengeHandler
or GatewayChallengeHandler
.
WLClient
. Each challenge handler should only be registered once in the lifetime of the application.
challengeHandler
- An instance of a challenge handler that extends either SecurityCheckChallengeHandler
or GatewayChallengeHandler
.public BaseChallengeHandler getBaseChallengeHandler(java.lang.String securityCheck)
public SecurityCheckChallengeHandler getSecurityCheckChallengeHandler(java.lang.String securityCheck)
public GatewayChallengeHandler getGatewayChallengeHandler(java.lang.String handlerName)
public GatewayChallengeHandler getGatewayChallengeHandler(WLResponse response)
public boolean isGatewayResponse(WLResponse response)
public void setServerUrl(java.net.URL url)
Changes 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:
WL.App.setServerUrl
.
WLClient.getInstance().setServerUrl(new URL("http://9.148.23.88:10080/context"));
url
- URL of the new server, including protocol, IP, port, and context.public java.net.URL getServerUrl()
public java.lang.String resetDeviceID()
public void setDeviceID(java.lang.String uuid)
public java.net.CookieStore getCookieStore()
public ClearableCookieJar getPersistentCookies()
public void getDeviceDisplayName(DeviceDisplayNameListener listener)
listener
- Listener whose onSuccess
or onFailure
method is called upon request completion.
The display name of the device is returned in the deviceDisplayName
parameter of the listener's onSuccess
method.public void setDeviceDisplayName(java.lang.String deviceDisplayName, WLRequestListener listener)
deviceDisplayName
- The device display name to set.listener
- Listener whose onSuccess
or onFailure
method is called upon request completion.