public class HttpClientService extends Object implements org.springframework.web.context.ServletContextAware
| Constructor and Description |
|---|
HttpClientService() |
| Modifier and Type | Method and Description |
|---|---|
String |
executeGet(String url)
Executes a request with GET method to the specified URL and reads the response content as a string.
|
String |
executeGet(String url,
Map<String,String> headers)
Executes a request with GET method to the specified URL and reads the response content as a string.
|
String |
executePost(String url,
Map<String,String> parameters,
Map<String,String> headers)
Executes a request with POST method to the specified URL and reads the response content as a string.
|
String |
executePost(String url,
Map<String,String> parameters,
Map<String,String> headers,
org.apache.commons.httpclient.HttpState state)
Executes a request with POST method to the specified URL and reads the response content as a string.
|
String |
getAbsoluteResourceAsString(String url)
Connects to the specified absolute URL and reads its content as a string.
|
String |
getContextResourceAsString(String url)
Retrieves the content of the resource, specified by the provided URL.
|
org.apache.commons.httpclient.HttpClient |
getHttpClient()
Deprecated.
since 7.1.2.3 Please, use
getHttpClient(String) instead which properly handles proxy server settings, if any |
org.apache.commons.httpclient.HttpClient |
getHttpClient(String url)
Detects the instance of the
HttpClient that is the most appropriate to handle the specified URL, considering proxy settings,
if any. |
String |
getResourceAsString(String url)
Retrieves the content of the specified resource as a string.
|
String |
getResourceAsString(String url,
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
Retrieves resource content, specified by the provided URL.
|
static boolean |
isAbsoluteUrl(String url)
Returns true if our current URL is absolute, false
otherwise.
|
void |
setHttpClient(org.apache.commons.httpclient.HttpClient httpClient)
Injects an instance of the
HttpClient. |
void |
setServletContext(javax.servlet.ServletContext servletContext) |
void |
shutdown() |
public static boolean isAbsoluteUrl(String url)
ImportSupport.isAbsoluteUrl(String)public String executeGet(String url) throws IllegalArgumentException
url - a URL to connect to{@link - IllegalArgumentException} in case of a malformed URLIllegalArgumentExceptionpublic String executeGet(String url, Map<String,String> headers) throws IllegalArgumentException
url - a URL to connect toheaders - request headers to be set for connection; null if no additional headers needs to be set{@link - IllegalArgumentException} in case of a malformed URLIllegalArgumentExceptionpublic String executePost(String url, Map<String,String> parameters, Map<String,String> headers) throws IllegalArgumentException
url - a URL to connect toparameters - the request parameter to submit; null if no parameters are passedheaders - request headers to be set for connection; null if no additional headers needs to be set{@link - IllegalArgumentException} in case of a malformed URLIllegalArgumentExceptionpublic String executePost(String url, Map<String,String> parameters, Map<String,String> headers, org.apache.commons.httpclient.HttpState state) throws IllegalArgumentException
url - a URL to connect toparameters - the request parameter to submit; null if no parameters are passedheaders - request headers to be set for connection; null if no additional headers needs to be setstate - the HTTP state object if additional state options, e.g. credentials, needs to be specified; otherwise can be null{@link - IllegalArgumentException} in case of a malformed URLIllegalArgumentExceptionpublic String getAbsoluteResourceAsString(String url) throws IllegalArgumentException
url - the absolute URL to connect to{@link - IllegalArgumentException} in case of a malformed URLIllegalArgumentExceptionpublic String getContextResourceAsString(String url) throws IllegalArgumentException
url - the URL of the resource to be retrieved{@link - IllegalArgumentException} in case of a malformed URLIllegalArgumentExceptionServletContext.getResourceAsStream(String)@Deprecated public org.apache.commons.httpclient.HttpClient getHttpClient()
getHttpClient(String) instead which properly handles proxy server settings, if anypublic org.apache.commons.httpclient.HttpClient getHttpClient(String url)
HttpClient that is the most appropriate to handle the specified URL, considering proxy settings,
if any.url - the target URL to be used for the HTTP client requestHttpClient that is the most appropriate to handle the specified URL, considering proxy settings,
if anypublic String getResourceAsString(String url) throws IllegalArgumentException
ServletContext.getResource(String) method.url - the resource URL{@link - IllegalArgumentException} in case of a malformed URLIllegalArgumentExceptionpublic String getResourceAsString(String url, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws IllegalArgumentException
url - the URL of the resource to be retrieved{@link - IllegalArgumentException} in case of a malformed URLIllegalArgumentExceptionpublic void setHttpClient(org.apache.commons.httpclient.HttpClient httpClient)
HttpClient.httpClient - an instance of the HttpClientpublic void setServletContext(javax.servlet.ServletContext servletContext)
setServletContext in interface org.springframework.web.context.ServletContextAwarepublic void shutdown()
Copyright © 2004–2020 Jahia Solutions Group SA. All rights reserved.