Class RESTTool

  • Direct Known Subclasses:
    APITool

    public class RESTTool
    extends java.lang.Object
    REST toolbox
    • Field Summary

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

      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 java.lang.Exception
        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:
        java.lang.Exception
      • get

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

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

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

        public static java.lang.String post​(java.lang.Object body,
                                            java.lang.String url,
                                            java.lang.String usernameOrBearerToken,
                                            java.lang.String password)
                                     throws java.lang.Exception
        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)
        Throws:
        java.lang.Exception
      • post

        public static java.lang.String post​(java.lang.Object body,
                                            java.lang.String mime,
                                            java.lang.String url)
                                     throws java.lang.Exception
        POST request
        Parameters:
        body - Body (String, JSONObject, JSONarray, etc.)
        mime - MIME type (defaults to JSON)
        url - URL
        Throws:
        java.lang.Exception
      • 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 java.lang.Exception
        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)
        Throws:
        java.lang.Exception
      • put

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

        public static java.lang.String put​(java.lang.Object body,
                                           java.lang.String url,
                                           java.lang.String usernameOrBearerToken,
                                           java.lang.String password)
                                    throws java.lang.Exception
        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)
        Throws:
        java.lang.Exception
      • put

        public static java.lang.String put​(java.lang.Object body,
                                           java.lang.String mime,
                                           java.lang.String url)
                                    throws java.lang.Exception
        PUT request
        Parameters:
        body - Body (String, JSONObject, JSONarray, etc.)
        mime - MIME type
        url - URL
        Throws:
        java.lang.Exception
      • 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 java.lang.Exception
        PUT request
        Parameters:
        body - Body (String, JSONObject, JSONarray, etc.)
        mime - MIME type
        url - URL
        username - Username
        password - Password
        Throws:
        java.lang.Exception
      • patch

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

        public static java.lang.String patch​(java.lang.Object body,
                                             java.lang.String url,
                                             java.lang.String usernameOrBearerToken,
                                             java.lang.String password)
                                      throws java.lang.Exception
        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)
        Throws:
        java.lang.Exception
      • patch

        public static java.lang.String patch​(java.lang.Object body,
                                             java.lang.String mime,
                                             java.lang.String url)
                                      throws java.lang.Exception
        PATCH request
        Parameters:
        body - Body (String, JSONObject, JSONarray, etc.)
        mime - MIME type
        url - URL
        Throws:
        java.lang.Exception
      • 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 java.lang.Exception
        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)
        Throws:
        java.lang.Exception
      • del

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

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

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

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