com.worklight.wlclient.api

Class WLResourceRequest

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


  • public class WLResourceRequest
    extends java.lang.Object
    This class encapsulates a resource request.

    The resource can be an adapter that is deployed to an instance of MobileFirst Server, or a resource on an external resource server.
    The class provides several send methods with different inputs for the body of a request.
    In addition, the send methods support the WLResponseListener response listener. The onSuccess method of this listener is called with an instance of the WLResponse class. The content of the response is read by the security framework into the WLResponse instance, and is then accessible through WLResponse methods. In case of failure, the onFailure method of the listener is called with an instance of the WLFailResponse class, which contains all the information about the failure.
    A successful response is any response with a status in the 2xx range. These responses are delivered to the onSuccess method.
    A response with a 4xx or 5xx status is considered a failure, and is delivered to the onFailure method.

    • Field Summary

      Fields 
      Modifier and Type Field and Description
      static java.lang.String BEARER_ERROR_INVALID_TOKEN 
      static java.lang.String DELETE
      String constant for the HTTP DELETE method.
      static java.lang.String GET
      String constant for the HTTP GET method.
      static java.lang.String HEAD
      String constant for the HTTP {@code HEAD method.
      static java.lang.String OPTIONS
      String constant for the HTTP OPTIONS method.
      static java.lang.String POST
      String constant for the HTTP POST method.
      static java.lang.String PUT
      String constant for the HTTP PUT method.
      static java.lang.String TRACE
      String constant for the HTTP TRACE method.
    • Constructor Summary

      Constructors 
      Constructor and Description
      WLResourceRequest(java.net.URI url, java.lang.String method)
      Constructs a new resource request with the specified URL, using the specified HTTP method.
      WLResourceRequest(java.net.URI url, java.lang.String method, int timeout)
      Constructs a new resource request with the specified URL, using the specified HTTP method.
      Additionally this constructor sets a custom expiration period (timeout) for the request.
      WLResourceRequest(java.net.URI url, java.lang.String method, int timeout, java.lang.String scope)
      Constructs a new resource request with the specified URL and protecting scope, using the specified HTTP method.
      WLResourceRequest(java.net.URI url, java.lang.String method, java.lang.String scope)
      Constructs a new resource request with the specified URL and protecting scope, using the specified HTTP method.
    • Method Summary

      Methods 
      Modifier and Type Method and Description
      void addHeader(java.lang.String name, java.lang.String value)
      Adds a header to this resource request.
      This method allows response headers to have multiple values.
      java.util.Map getAllHeaders()
      Returns all headers for this resource request.
      java.util.List getHeaders(java.lang.String headerName)
      Returns all headers of the specified name for this resource request.
      java.lang.String getMethod()
      Returns the HTTP method of this resource request.
      java.util.Map getQueryParameters()
      Returns the query parameters set for this resource request as a Map.
      java.lang.String getQueryString()
      Returns the query parameters of this resource request as a string.
      int getTimeout()
      Returns the expiration period (timeout) for this resource request.
      java.net.URL getUrl()
      Returns the URL for this resource request.
      void removeHeaders(java.lang.String headerName)
      Removes headers with the specified name for this resource request.
      void send(JSONObject json, WLResponseListener listener)
      Sends this resource request asynchronously, with the given JSON object as the request body.
      void send(java.util.Map formParameters, WLResponseListener listener)
      Sends this resource request asynchronously, with the provided form parameters as the request body.
      void send(java.lang.String requestBody, WLResponseListener listener)
      Sends this resource request asynchronously, with the provided string as the request body.
      void send(WLResponseListener listener)
      Send this resource request asynchronously, without a request body.
      void setHeaders(java.util.Map headerMap)
      Sets the specified headers for this resource request.
      For a header that is already set, the new value overwrites the previous value.
      void setQueryParameter(java.lang.String name, java.lang.String value)
      Sets the value of the specified query parameter to the provided value.
      If no matching parameter is found, the parameter is added.
      void setQueryParameters(java.util.HashMap parameters)
      Sets the query parameters of this resource.
      void setTimeout(int timeout)
      Sets the expiration period (timeout) for this resource request.
      • Methods inherited from class java.lang.Object

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

      • BEARER_ERROR_INVALID_TOKEN

        public static final java.lang.String BEARER_ERROR_INVALID_TOKEN
        See Also:
        Constant Field Values
      • GET

        public static final java.lang.String GET
        String constant for the HTTP GET method.
        See Also:
        Constant Field Values
      • POST

        public static final java.lang.String POST
        String constant for the HTTP POST method.
        See Also:
        Constant Field Values
      • PUT

        public static final java.lang.String PUT
        String constant for the HTTP PUT method.
        See Also:
        Constant Field Values
      • DELETE

        public static final java.lang.String DELETE
        String constant for the HTTP DELETE method.
        See Also:
        Constant Field Values
      • TRACE

        public static final java.lang.String TRACE
        String constant for the HTTP TRACE method.
        See Also:
        Constant Field Values
      • HEAD

        public static final java.lang.String HEAD
        String constant for the HTTP {@code HEAD method.
        See Also:
        Constant Field Values
      • OPTIONS

        public static final java.lang.String OPTIONS
        String constant for the HTTP OPTIONS method.
        See Also:
        Constant Field Values
    • Constructor Detail

      • WLResourceRequest

        public WLResourceRequest(java.net.URI url,
                         java.lang.String method)
        Constructs a new resource request with the specified URL, using the specified HTTP method.
        Parameters:
        url - Resource URL, either as a relative or as an absolute path.
        method - HTTP method to use.
      • WLResourceRequest

        public WLResourceRequest(java.net.URI url,
                         java.lang.String method,
                         java.lang.String scope)
        Constructs a new resource request with the specified URL and protecting scope, using the specified HTTP method.
        Parameters:
        url - Resource URL, either as a relative or as an absolute path.
        method - HTTP method to use.
        scope - Protecting scope of the requested resource.
      • WLResourceRequest

        public WLResourceRequest(java.net.URI url,
                         java.lang.String method,
                         int timeout)
        Constructs a new resource request with the specified URL, using the specified HTTP method.
        Additionally this constructor sets a custom expiration period (timeout) for the request.
        Parameters:
        url - Resource URL, either as a relative or as an absolute path.
        method - The HTTP method to use.
        timeout - The timeout in milliseconds for this request.
      • WLResourceRequest

        public WLResourceRequest(java.net.URI url,
                         java.lang.String method,
                         int timeout,
                         java.lang.String scope)
        Constructs a new resource request with the specified URL and protecting scope, using the specified HTTP method. Additionally this constructor sets a custom expiration period (timeout) for the request.
        Parameters:
        url - Resource URL, either as a relative or as an absolute path.
        method - HTTP method to use.
        timeout - The timeout in milliseconds for this request.
        scope - Protecting scope of the requested resource.
    • Method Detail

      • getUrl

        public java.net.URL getUrl()
        Returns the URL for this resource request.
        Returns:
        A URL object that represents the absolute path for the resource request.
      • getMethod

        public java.lang.String getMethod()
        Returns the HTTP method of this resource request.
        Returns:
        A string containing the name of the HTTP method of the resource request.
      • getQueryParameters

        public java.util.Map getQueryParameters()
        Returns the query parameters set for this resource request as a Map.
        Returns:
        A Map that contains the query parameters of the request.
      • getQueryString

        public java.lang.String getQueryString()
        Returns the query parameters of this resource request as a string.
        Returns:
        A string that contains the query parameters of the request.
      • setQueryParameters

        public void setQueryParameters(java.util.HashMap parameters)
        Sets the query parameters of this resource.
        Parameters:
        parameters - A HashMap that contains the query parameters of the request.
      • setQueryParameter

        public void setQueryParameter(java.lang.String name,
                             java.lang.String value)
        Sets the value of the specified query parameter to the provided value.
        If no matching parameter is found, the parameter is added.
        Parameters:
        name - Name of the parameter to set.
        value - Value to set for the parameter.
      • getAllHeaders

        public java.util.Map getAllHeaders()
        Returns all headers for this resource request.
        Returns:
        A map that contains all the retrieved request headers.
      • getHeaders

        public java.util.List getHeaders(java.lang.String headerName)
        Returns all headers of the specified name for this resource request.
        Parameters:
        headerName - Name of the headers to retrieve.
        Returns:
        A list that contains all the values of the retrieved request headers.
      • removeHeaders

        public void removeHeaders(java.lang.String headerName)
        Removes headers with the specified name for this resource request.
        Parameters:
        headerName - Name of the headers to remove.
      • setHeaders

        public void setHeaders(java.util.Map headerMap)
        Sets the specified headers for this resource request.
        For a header that is already set, the new value overwrites the previous value.
        Parameters:
        headerMap - Map of the headers to set.
      • addHeader

        public void addHeader(java.lang.String name,
                     java.lang.String value)
        Adds a header to this resource request.
        This method allows response headers to have multiple values.
        Parameters:
        value - Value of the header to add.
      • getTimeout

        public int getTimeout()
        Returns the expiration period (timeout) for this resource request.
        Returns:
        Expiration period for this resource request, in milliseconds.
      • setTimeout

        public void setTimeout(int timeout)
        Sets the expiration period (timeout) for this resource request.
        Parameters:
        timeout - Expiration period for this resource request, in milliseconds.
      • send

        public void send(WLResponseListener listener)
        Send this resource request asynchronously, without a request body.
        Parameters:
        listener - Listener whose onSuccess or onFailure method will be called when this request processing completes.
      • send

        public void send(java.lang.String requestBody,
                WLResponseListener listener)
        Sends this resource request asynchronously, with the provided string as the request body. When no content-type header is set, the method sets this header to "text/plain".
        Parameters:
        requestBody - The request body text
        listener - Listener whose onSuccess or onFailure method will be called when this request processing completes.
      • send

        public void send(java.util.Map formParameters,
                WLResponseListener listener)
        Sends this resource request asynchronously, with the provided form parameters as the request body. When no content-type header is set, the method sets this header to "application/x-www-form-urlencoded", this value cannot be overrode.
        Parameters:
        formParameters - The parameters to put in the request body
        listener - Listener whose onSuccess or onFailure method will be called when this request processing completes.
      • send

        public void send(JSONObject json,
                WLResponseListener listener)
        Sends this resource request asynchronously, with the given JSON object as the request body. When no content-type header is set, the method sets this header to "application/json".
        Parameters:
        json - The JSON object to put in the request body
        listener - Listener whose onSuccess or onFailure method will be called when this request processing completes.


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