Package de.narimo.commons.ws.http
Class HttpURLClient
- java.lang.Object
-
- de.narimo.commons.ws.http.HttpURLClient
-
public class HttpURLClient extends Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classHttpURLClient.VerifierDO NOT use in production!!!
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static HttpURLClient.VerifiergetHostnameVerifier()static StringBuffergetResponseBody(HttpURLConnection con)Reads the response stream and converts it to a StringBuffer.static SSLSocketFactorygetSSLSocketFactoryTrusted()Do not use in production code!!static StringgetStringFromInputStream(InputStream is)Converts an InputStream to String.booleanisVerbose()static voidmain(String[] args)static de.narimo.commons.http.URLResponsemakeResponse(HttpURLConnection con, StringBuffer responseBody, boolean responseAsStream)Assemble correct response from the HTTPURLConnectionstatic de.narimo.commons.http.URLResponsesendRequest(String wsUrl, Map<String,String> queryParams, Map<String,String> connectionHeaders, String body, HttpMethod method, HTTPAuthorizationFactory authFactory, boolean https, boolean responseAsStream, boolean followRedirects)static de.narimo.commons.http.URLResponsesendRequest(String wsUrl, Map<String,String> queryParams, Map<String,String> connectionHeaders, String body, HttpMethod method, HTTPBasicAuthorizationFactory authFactory, boolean https, boolean responseAsStream)static de.narimo.commons.http.URLResponsesendRequest(String wsUrl, Map<String,String> queryParams, Map<String,String> connectionHeaders, String body, HttpMethod method, javax.ws.rs.core.Cookie[] cookies, String user, String pass, boolean https, boolean responseAsStream)static de.narimo.commons.http.URLResponsesendRequestMultivalue(String wsUrl, javax.ws.rs.core.MultivaluedMap<String,String> queryParams, Map<String,String> connectionHeaders, String body, HttpMethod method, HTTPBasicAuthorizationFactory authFactory, boolean https, boolean responseAsStream, boolean followRedirects)voidsetFollowRedirects(boolean followRedirects)voidsetHttps(boolean https)voidsetHttps(boolean https, SSLSocketFactory optSSLFactory, HostnameVerifier optHostnameVerifier)voidsetResponseAsStream(boolean responseAsStream)voidsetVerbose(boolean verbose)
-
-
-
Method Detail
-
setHttps
public void setHttps(boolean https)
-
setHttps
public void setHttps(boolean https, SSLSocketFactory optSSLFactory, HostnameVerifier optHostnameVerifier)
-
setFollowRedirects
public void setFollowRedirects(boolean followRedirects)
-
getResponseBody
public static StringBuffer getResponseBody(HttpURLConnection con) throws IOException
Reads the response stream and converts it to a StringBuffer.- Parameters:
con-- Returns:
- Throws:
IOException
-
makeResponse
public static de.narimo.commons.http.URLResponse makeResponse(HttpURLConnection con, StringBuffer responseBody, boolean responseAsStream) throws IOException
Assemble correct response from the HTTPURLConnection- Parameters:
con-responseBody-responseAsStream-- Returns:
- Throws:
IOException
-
sendRequest
public static de.narimo.commons.http.URLResponse sendRequest(String wsUrl, Map<String,String> queryParams, Map<String,String> connectionHeaders, String body, HttpMethod method, javax.ws.rs.core.Cookie[] cookies, String user, String pass, boolean https, boolean responseAsStream) throws IOException
- Throws:
IOException
-
sendRequest
public static de.narimo.commons.http.URLResponse sendRequest(String wsUrl, Map<String,String> queryParams, Map<String,String> connectionHeaders, String body, HttpMethod method, HTTPBasicAuthorizationFactory authFactory, boolean https, boolean responseAsStream) throws Exception
- Throws:
Exception
-
sendRequest
public static de.narimo.commons.http.URLResponse sendRequest(String wsUrl, Map<String,String> queryParams, Map<String,String> connectionHeaders, String body, HttpMethod method, HTTPAuthorizationFactory authFactory, boolean https, boolean responseAsStream, boolean followRedirects) throws Exception
- Throws:
Exception
-
sendRequestMultivalue
public static de.narimo.commons.http.URLResponse sendRequestMultivalue(String wsUrl, javax.ws.rs.core.MultivaluedMap<String,String> queryParams, Map<String,String> connectionHeaders, String body, HttpMethod method, HTTPBasicAuthorizationFactory authFactory, boolean https, boolean responseAsStream, boolean followRedirects) throws Exception
- Throws:
Exception
-
setResponseAsStream
public void setResponseAsStream(boolean responseAsStream)
-
getStringFromInputStream
public static String getStringFromInputStream(InputStream is)
Converts an InputStream to String.- Parameters:
is-- Returns:
-
isVerbose
public boolean isVerbose()
-
setVerbose
public void setVerbose(boolean verbose)
-
getSSLSocketFactoryTrusted
public static SSLSocketFactory getSSLSocketFactoryTrusted() throws Exception
Do not use in production code!!- Returns:
- Throws:
Exception
-
getHostnameVerifier
public static HttpURLClient.Verifier getHostnameVerifier()
-
main
public static void main(String[] args) throws URISyntaxException, MalformedURLException
-
-