com.worklight.wlclient.api

Class WLClient

  • java.lang.Object
    • com.worklight.wlclient.api.WLClient


  • public class WLClient
    extends java.lang.Object
    This 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.Object WAIT_LOCK 
    • Method Summary

      Methods 
      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 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.
      protected java.util.Hashtable getchMap() 
      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.
      protected java.util.Map getGlobalHeaders() 
      static WLClient getInstance()
      This method gets the singleton instance of WLClient.
      java.net.URL getServerUrl()
      Returns the current MobileFirst Platform server URL
      protected java.lang.String getWLServerURL() 
      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

      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);
       
      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() 
      void pinTrustedCertificatePublicKey(java.lang.String certificateFilename)
      Pins the host X509 certificate public key to the client application.
      void pinTrustedCertificatePublicKey(java.lang.String[] certificateFileNames)
      Pins a set of host X509 certificates(multiple certificate's) public keys to the client application.
      void registerChallengeHandler(BaseChallengeHandler challengeHandler)
      You can use this method to register a challenge handler in the client.
      protected static void releaseInstance() 
      void removeGlobalHeader(java.lang.String headerName)
      You use this method to remove a global header.
      void setDeviceDisplayName(java.lang.String deviceDisplayName, WLRequestListener listener)
      Sets the display name of the device.
      void setHeartBeatInterval(int newInterval)
      Sets heart beat interval.
      void setServerUrl(java.net.URL url)
      Sets the MobileFirst Platform server URL to the specified URL
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • WAIT_LOCK

        public static final java.lang.Object WAIT_LOCK
    • 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 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.

        Parameters:
        context - Android Context, for example the Android Activity that creates the WLClient.
        Returns:
        WLClient
      • getInstance

        public static WLClient getInstance()
        This method gets the singleton instance of WLClient.
        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 header
        value - 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
      • 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, the WLResponseListener.onSuccess(WLResponse) method is called. If an error occurs, the WLResponseListener.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, the WLResponseListener.onSuccess(WLResponse) method is called. If an error occurs, the WLResponseListener.onFailure(WLFailResponse) method is called.
        options - WLRequestOptions instance
      • invokeProcedure

        public 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

        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.IllegalArgumentException
        Pins 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 - if certificateFilename is null, not found or is not in DER format.
      • pinTrustedCertificatePublicKey

        public void pinTrustedCertificatePublicKey(java.lang.String[] certificateFileNames)
                                            throws java.lang.IllegalArgumentException
        Pins a set of host X509 certificates(multiple certificate's) public keys to the client application. Secured calls to the pinned remote host will be checked for a public keys 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 - if certificateFilesname is 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 either SecurityCheckChallengeHandler or GatewayChallengeHandler.
        Important: you must call this method at the beginning of your application after you initialize WLClient. Each challenge handler should only be registered once in the lifetime of the application.

        Parameters:
        challengeHandler - An instance of a challenge handler that extends either SecurityCheckChallengeHandler or GatewayChallengeHandler.
      • getWLServerURL

        protected java.lang.String getWLServerURL()
      • setServerUrl

        public void setServerUrl(java.net.URL url)
        Sets the MobileFirst Platform server URL to the specified 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:

        • 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.
        Example

        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 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.
      • setDeviceDisplayName

        public void setDeviceDisplayName(java.lang.String deviceDisplayName,
                                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 whose onSuccess or onFailure method is called upon request completion.


© Copyright IBM Corp. 2006, 2015. All Rights Reserved.