public class WebServiceUtils extends Object
| Modifier and Type | Method and Description |
|---|---|
static String |
generateBasicAuthorizationHeader(String username,
String password)
Generates a basic authorization header from the given credentials.
|
static WebServiceResponse |
get(String url)
Executes HTTP GET on a given URL.
|
static WebServiceResponse |
get(String url,
Map<String,String> headers)
Executes HTTP GET on a given URL, with custom headers
|
static String |
getAsString(String url)
Executes HTTP GET on given URL.
|
static String |
getAsString(String url,
Map<String,String> headers)
Executes HTTP GET on a given URL with custom headers.
|
static String |
getResponseAsString(WebServiceResponse webServiceResponse)
Returns the HTTP response body, as string, given an HTTP client response.
|
static int |
getStatusCode(WebServiceResponse webServiceResponse)
Returns the HTTP status code, given an HTTP response.
|
static WebServiceResponse |
invoke(String method,
String url,
Object requestEntity)
Executes the requested HTTP method on a given URL.
|
static WebServiceResponse |
invoke(String method,
String url,
Object requestEntity,
Map<String,String> headers)
Executes the requested HTTP method on a given URL, with custom headers.
|
public static String getAsString(String url)
url - the URL of the resourcepublic static String getAsString(String url, Map<String,String> headers)
url - the URL of the resourceheaders - a map of custom headers to be added to the requestpublic static String getResponseAsString(WebServiceResponse webServiceResponse)
webServiceResponse - the HTTP client responsepublic static WebServiceResponse get(String url)
url - the URL of the resourceWebServiceResponse object, which may contain the HTTP status code and
the content returned from the Web Servicepublic static WebServiceResponse get(String url, Map<String,String> headers)
url - the URL of the resourceheaders - a map of custom headers to be added to the request; can be nullWebServiceResponse object, which may contain the HTTP status code and
the content returned from the Web Servicepublic static WebServiceResponse invoke(String method, String url, Object requestEntity)
method - the HTTP method to be invokedurl - the URL of the resourcerequestEntity - the request body entity/payload to be sent; can be nullWebServiceResponse object, which may contain the HTTP status code and
the content returned from the Web Servicepublic static WebServiceResponse invoke(String method, String url, Object requestEntity, Map<String,String> headers)
method - the HTTP method to be invokedurl - the URL of the resourcerequestEntity - the request body entity/payload to be sent; can be nullheaders - a map of custom headers to be added to the request; can be nullWebServiceResponse object, which may contain the HTTP status code and
the content returned from the Web ServiceIllegalArgumentException - if the HTTP method is null or emptypublic static int getStatusCode(WebServiceResponse webServiceResponse)
webServiceResponse - the HTTP client responsepublic static final String generateBasicAuthorizationHeader(String username, String password)
username - the username to be encodedpassword - the password to be encodedCopyright © 2021. All rights reserved.