Class RESTTool


  • public class RESTTool
    extends java.lang.Object
    REST toolbox
    This class only provides static variables and methods
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int DEFAULT_TIMEOUT
      Deprecated.
      Use HTTPTool.HTTP_TIMEOUT
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String del​(java.lang.String url)
      DELETE request
      static java.lang.String del​(java.lang.String url, java.lang.String usernameOrBearerToken, java.lang.String password)
      DELETE request
      static java.lang.String delete​(java.lang.String url)
      DELETE request
      static java.lang.String delete​(java.lang.String url, java.lang.String usernameOrBearerToken, java.lang.String password)
      DELETE request
      static java.lang.String get​(java.lang.String url)
      GET request
      static java.lang.String get​(java.lang.String url, java.lang.String usernameOrBearerToken, java.lang.String password)
      GET request
      static java.lang.String patch​(java.lang.Object body, java.lang.String url)
      PATCH request
      static java.lang.String patch​(java.lang.Object body, java.lang.String mime, java.lang.String url)
      PATCH request
      static java.lang.String patch​(java.lang.Object body, java.lang.String url, java.lang.String usernameOrBearerToken, java.lang.String password)
      PATCH request
      static java.lang.String patch​(java.lang.Object body, java.lang.String mime, java.lang.String url, java.lang.String usernameOrBearerToken, java.lang.String password)
      PATCH request
      static java.lang.String post​(java.lang.Object body, java.lang.String url)
      POST request
      static java.lang.String post​(java.lang.Object body, java.lang.String mime, java.lang.String url)
      POST request
      static java.lang.String post​(java.lang.Object body, java.lang.String url, java.lang.String usernameOrBearerToken, java.lang.String password)
      POST request
      static java.lang.String post​(java.lang.Object body, java.lang.String mime, java.lang.String url, java.lang.String usernameOrBearerToken, java.lang.String password)
      POST request
      static java.lang.String put​(java.lang.Object body, java.lang.String url)
      PUT request
      static java.lang.String put​(java.lang.Object body, java.lang.String mime, java.lang.String url)
      PUT request
      static java.lang.String put​(java.lang.Object body, java.lang.String url, java.lang.String usernameOrBearerToken, java.lang.String password)
      PUT request
      static java.lang.String put​(java.lang.Object body, java.lang.String mime, java.lang.String url, java.lang.String username, java.lang.String password)
      PUT request
      static java.lang.String request​(java.lang.Object body, java.lang.String mime, java.lang.String url, java.lang.String method, java.lang.String usernameOrBearerToken, java.lang.String password, java.util.Map<java.lang.String,​java.lang.Object> headers, int timeout)
      Execute simple generic JSON/REST request.
      • Methods inherited from class java.lang.Object

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

      • DEFAULT_TIMEOUT

        @Deprecated
        public static final int DEFAULT_TIMEOUT
        Deprecated.
        Use HTTPTool.HTTP_TIMEOUT
        See Also:
        Constant Field Values
    • Method Detail

      • request

        public static java.lang.String request​(java.lang.Object body,
                                               java.lang.String mime,
                                               java.lang.String url,
                                               java.lang.String method,
                                               java.lang.String usernameOrBearerToken,
                                               java.lang.String password,
                                               java.util.Map<java.lang.String,​java.lang.Object> headers,
                                               int timeout)
                                        throws HTTPException
        Execute simple generic JSON/REST request.
        Parameters:
        body - Body (String, JSONObject, JSONarray, etc.)
        mime - MIME type (defaults to JSON)
        url - URL
        method - HTTP method
        usernameOrBearerToken - Username or auth bearer token
        password - Password (must be null if auth bearer)
        timeout - Timeout in seconds (0 means no timeout)
        Returns:
        Response as string
        Throws:
        HTTPException
      • get

        public static java.lang.String get​(java.lang.String url)
                                    throws HTTPException
        GET request
        Parameters:
        url - URL
        Returns:
        GET response
        Throws:
        HTTPException
      • get

        public static java.lang.String get​(java.lang.String url,
                                           java.lang.String usernameOrBearerToken,
                                           java.lang.String password)
                                    throws HTTPException
        GET request
        Parameters:
        url - URL
        usernameOrBearerToken - Username or auth bearer token
        password - Password (must be null if auth bearer)
        Returns:
        GET response
        Throws:
        HTTPException
      • post

        public static java.lang.String post​(java.lang.Object body,
                                            java.lang.String url)
                                     throws HTTPException
        POST request
        Parameters:
        body - Body (String, JSONObject, JSONarray, etc.)
        url - URL
        Returns:
        GET response
        Throws:
        HTTPException
      • post

        public static java.lang.String post​(java.lang.Object body,
                                            java.lang.String url,
                                            java.lang.String usernameOrBearerToken,
                                            java.lang.String password)
                                     throws HTTPException
        POST request
        Parameters:
        body - Body (String, JSONObject, JSONarray, etc.)
        url - URL
        usernameOrBearerToken - Username or auth bearer token
        password - Password (must be null if auth bearer)
        Returns:
        POST request response
        Throws:
        HTTPException
      • post

        public static java.lang.String post​(java.lang.Object body,
                                            java.lang.String mime,
                                            java.lang.String url)
                                     throws HTTPException
        POST request
        Parameters:
        body - Body (String, JSONObject, JSONarray, etc.)
        mime - MIME type (defaults to JSON)
        url - URL
        Returns:
        POST request response
        Throws:
        HTTPException
      • post

        public static java.lang.String post​(java.lang.Object body,
                                            java.lang.String mime,
                                            java.lang.String url,
                                            java.lang.String usernameOrBearerToken,
                                            java.lang.String password)
                                     throws HTTPException
        POST request
        Parameters:
        body - Body (String, JSONObject, JSONarray, etc.)
        mime - MIME type (defaults to JSON)
        url - URL
        usernameOrBearerToken - Username or auth bearer token
        password - Password (must be null if auth bearer)
        Returns:
        POST request response
        Throws:
        HTTPException
      • put

        public static java.lang.String put​(java.lang.Object body,
                                           java.lang.String url)
                                    throws HTTPException
        PUT request
        Parameters:
        body - Body (String, JSONObject, JSONarray, etc.)
        url - URL
        Returns:
        PUT request response
        Throws:
        HTTPException
      • put

        public static java.lang.String put​(java.lang.Object body,
                                           java.lang.String url,
                                           java.lang.String usernameOrBearerToken,
                                           java.lang.String password)
                                    throws HTTPException
        PUT request
        Parameters:
        body - Body (String, JSONObject, JSONarray, etc.)
        url - URL
        usernameOrBearerToken - Username or auth bearer token
        password - Password (must be null if auth bearer)
        Returns:
        PUT request response
        Throws:
        HTTPException
      • put

        public static java.lang.String put​(java.lang.Object body,
                                           java.lang.String mime,
                                           java.lang.String url)
                                    throws HTTPException
        PUT request
        Parameters:
        body - Body (String, JSONObject, JSONarray, etc.)
        mime - MIME type
        url - URL
        Returns:
        PUT request response
        Throws:
        HTTPException
      • put

        public static java.lang.String put​(java.lang.Object body,
                                           java.lang.String mime,
                                           java.lang.String url,
                                           java.lang.String username,
                                           java.lang.String password)
                                    throws HTTPException
        PUT request
        Parameters:
        body - Body (String, JSONObject, JSONarray, etc.)
        mime - MIME type
        url - URL
        username - Username
        password - Password
        Returns:
        PUT request response
        Throws:
        HTTPException
      • patch

        public static java.lang.String patch​(java.lang.Object body,
                                             java.lang.String url)
                                      throws HTTPException
        PATCH request
        Parameters:
        body - Body (String, JSONObject, JSONarray, etc.)
        url - URL
        Returns:
        PATCH request response
        Throws:
        HTTPException
      • patch

        public static java.lang.String patch​(java.lang.Object body,
                                             java.lang.String url,
                                             java.lang.String usernameOrBearerToken,
                                             java.lang.String password)
                                      throws HTTPException
        PATCH request
        Parameters:
        body - Body (String, JSONObject, JSONarray, etc.)
        url - URL
        usernameOrBearerToken - Username or auth bearer token
        password - Password (must be null if auth bearer)
        Returns:
        PATCH request response
        Throws:
        HTTPException
      • patch

        public static java.lang.String patch​(java.lang.Object body,
                                             java.lang.String mime,
                                             java.lang.String url)
                                      throws HTTPException
        PATCH request
        Parameters:
        body - Body (String, JSONObject, JSONarray, etc.)
        mime - MIME type
        url - URL
        Returns:
        PATCH request response
        Throws:
        HTTPException
      • patch

        public static java.lang.String patch​(java.lang.Object body,
                                             java.lang.String mime,
                                             java.lang.String url,
                                             java.lang.String usernameOrBearerToken,
                                             java.lang.String password)
                                      throws HTTPException
        PATCH request
        Parameters:
        body - Body (String, JSONObject, JSONarray, etc.)
        mime - MIME type
        url - URL
        usernameOrBearerToken - Username or auth bearer token
        password - Password (must be null if auth bearer)
        Returns:
        PATCH request response
        Throws:
        HTTPException
      • del

        public static java.lang.String del​(java.lang.String url)
                                    throws HTTPException
        DELETE request
        Parameters:
        url - URL
        Returns:
        DELETE request response
        Throws:
        HTTPException
      • delete

        public static java.lang.String delete​(java.lang.String url)
                                       throws HTTPException
        DELETE request
        Parameters:
        url - URL
        Returns:
        DELETE request response
        Throws:
        HTTPException
      • del

        public static java.lang.String del​(java.lang.String url,
                                           java.lang.String usernameOrBearerToken,
                                           java.lang.String password)
                                    throws HTTPException
        DELETE request
        Parameters:
        url - URL
        usernameOrBearerToken - Username or auth bearer token
        password - Password (must be null if auth bearer)
        Returns:
        DELETE request response
        Throws:
        HTTPException
      • delete

        public static java.lang.String delete​(java.lang.String url,
                                              java.lang.String usernameOrBearerToken,
                                              java.lang.String password)
                                       throws HTTPException
        DELETE request
        Parameters:
        url - URL
        usernameOrBearerToken - Username or auth bearer token
        password - Password (must be null if auth bearer)
        Returns:
        DELETE request response
        Throws:
        HTTPException