mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-11 07:55:47 +01:00
javadoc for httpclient api
This commit is contained in:
@@ -41,31 +41,37 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Simple client for http operations.
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*
|
||||
* @apiviz.landmark
|
||||
* @apiviz.uses sonia.scm.net.HttpRequest
|
||||
* @apiviz.uses sonia.scm.net.HttpResponse
|
||||
*/
|
||||
public interface HttpClient
|
||||
{
|
||||
|
||||
/**
|
||||
* Method description
|
||||
* Send a post request to the given url.
|
||||
*
|
||||
*
|
||||
* @param url
|
||||
* @param url url for post request
|
||||
*
|
||||
* @return
|
||||
* @return the response of the http request
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
public HttpResponse post(String url) throws IOException;
|
||||
|
||||
/**
|
||||
* Method description
|
||||
* Sends a post request with the parameter specified in the
|
||||
* {@link HttpRequest} object.
|
||||
*
|
||||
*
|
||||
* @param request
|
||||
* @param request request object
|
||||
*
|
||||
* @return
|
||||
* @return the response of the http request
|
||||
* @since 1.9
|
||||
*
|
||||
* @throws IOException
|
||||
@@ -73,13 +79,13 @@ public interface HttpClient
|
||||
public HttpResponse post(HttpRequest request) throws IOException;
|
||||
|
||||
/**
|
||||
* Method description
|
||||
* Send a post request to the given url with the specified post parameters.
|
||||
*
|
||||
*
|
||||
* @param url
|
||||
* @param parameters
|
||||
* @param url url for post request
|
||||
* @param parameters parameters for the post request
|
||||
*
|
||||
* @return
|
||||
* @return the response of the http request
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
@@ -89,24 +95,25 @@ public interface HttpClient
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
* Send a get request to the given url.
|
||||
*
|
||||
*
|
||||
* @param url
|
||||
* @param url url for get request
|
||||
*
|
||||
* @return
|
||||
* @return the response of the http request
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
public HttpResponse get(String url) throws IOException;
|
||||
|
||||
/**
|
||||
* Method description
|
||||
* Sends a get request with the parameter specified in the
|
||||
* {@link HttpRequest} object.
|
||||
*
|
||||
*
|
||||
* @param request
|
||||
* @param request request object
|
||||
*
|
||||
* @return
|
||||
* @return the response of the http request
|
||||
* @since 1.9
|
||||
*
|
||||
* @throws IOException
|
||||
@@ -114,13 +121,13 @@ public interface HttpClient
|
||||
public HttpResponse get(HttpRequest request) throws IOException;
|
||||
|
||||
/**
|
||||
* Method description
|
||||
* Send a get request to the given url with the specified post parameters.
|
||||
*
|
||||
*
|
||||
* @param url
|
||||
* @param parameters
|
||||
* @param url url for get request
|
||||
* @param parameters parameters for the get request
|
||||
*
|
||||
* @return
|
||||
* @return the response of the http request
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
|
||||
@@ -35,17 +35,19 @@ package sonia.scm.net;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import sonia.scm.util.AssertUtil;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Http request which can be executed by the {@link HttpClient}.
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
* @since 1.9
|
||||
@@ -54,10 +56,10 @@ public class HttpRequest
|
||||
{
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
* Constructs a new HttpRequest.
|
||||
*
|
||||
*
|
||||
* @param url
|
||||
* @param url url for the request
|
||||
*/
|
||||
public HttpRequest(String url)
|
||||
{
|
||||
@@ -67,13 +69,13 @@ public class HttpRequest
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
* Add a http header for the request.
|
||||
*
|
||||
*
|
||||
* @param name
|
||||
* @param values
|
||||
* @param name name of the request header
|
||||
* @param values values of the request header
|
||||
*
|
||||
* @return
|
||||
* @return {@code this}
|
||||
*/
|
||||
public HttpRequest addHeader(String name, String... values)
|
||||
{
|
||||
@@ -90,13 +92,13 @@ public class HttpRequest
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
* Add a parameter to the request.
|
||||
*
|
||||
*
|
||||
* @param name
|
||||
* @param values
|
||||
* @param name name of the parameter
|
||||
* @param values values of the parameter
|
||||
*
|
||||
* @return
|
||||
* @return {@code this}
|
||||
*/
|
||||
public HttpRequest addParameters(String name, String... values)
|
||||
{
|
||||
@@ -115,10 +117,10 @@ public class HttpRequest
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
* Return a map with http headers used for the request.
|
||||
*
|
||||
*
|
||||
* @return
|
||||
* @return map with http headers
|
||||
*/
|
||||
public Map<String, List<String>> getHeaders()
|
||||
{
|
||||
@@ -126,10 +128,10 @@ public class HttpRequest
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
* Return a map with http parameters for the request.
|
||||
*
|
||||
*
|
||||
* @return
|
||||
* @return map with http parameters
|
||||
*/
|
||||
public Map<String, List<String>> getParameters()
|
||||
{
|
||||
@@ -137,10 +139,10 @@ public class HttpRequest
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
* Returns the password for http basic authentication.
|
||||
*
|
||||
*
|
||||
* @return
|
||||
* @return password for http basic authentication
|
||||
*/
|
||||
public String getPassword()
|
||||
{
|
||||
@@ -148,10 +150,10 @@ public class HttpRequest
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
* Returns the url for the request.
|
||||
*
|
||||
*
|
||||
* @return
|
||||
* @return url of the request
|
||||
*/
|
||||
public String getUrl()
|
||||
{
|
||||
@@ -159,10 +161,10 @@ public class HttpRequest
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
* Returns the username for http basic authentication.
|
||||
*
|
||||
*
|
||||
* @return
|
||||
* @return username for http basic authentication
|
||||
*/
|
||||
public String getUsername()
|
||||
{
|
||||
@@ -170,10 +172,10 @@ public class HttpRequest
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
* Returns true if the request decodes gzip compression.
|
||||
*
|
||||
*
|
||||
* @return
|
||||
* @return true if the request decodes gzip compression
|
||||
*
|
||||
* @since 1.14
|
||||
*/
|
||||
@@ -183,10 +185,10 @@ public class HttpRequest
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
* Returns true if the verification of ssl certificates is disabled.
|
||||
*
|
||||
*
|
||||
* @return
|
||||
* @return true if certificate verification is disabled
|
||||
* @since 1.17
|
||||
*/
|
||||
public boolean isDisableCertificateValidation()
|
||||
@@ -195,10 +197,10 @@ public class HttpRequest
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
* Returns true if the ssl hostname validation is disabled.
|
||||
*
|
||||
*
|
||||
* @return
|
||||
* @return true if the ssl hostname validation is disabled
|
||||
* @since 1.17
|
||||
*/
|
||||
public boolean isDisableHostnameValidation()
|
||||
@@ -207,10 +209,10 @@ public class HttpRequest
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
* Returns true if the proxy settings are ignored.
|
||||
*
|
||||
*
|
||||
* @return
|
||||
* @return true if the proxy settings are ignored
|
||||
* @since 1.17
|
||||
*/
|
||||
public boolean isIgnoreProxySettings()
|
||||
@@ -221,13 +223,13 @@ public class HttpRequest
|
||||
//~--- set methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
* Enabled http basic authentication.
|
||||
*
|
||||
*
|
||||
* @param username
|
||||
* @param password
|
||||
* @param username username for http basic authentication
|
||||
* @param password password for http basic authentication
|
||||
*
|
||||
* @return
|
||||
* @return {@code this}
|
||||
*/
|
||||
public HttpRequest setBasicAuthentication(String username, String password)
|
||||
{
|
||||
@@ -238,12 +240,12 @@ public class HttpRequest
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
* Enable or disabled gzip decoding. The default value is false.
|
||||
*
|
||||
*
|
||||
* @param decodeGZip
|
||||
* @param decodeGZip true to enable gzip decoding
|
||||
*
|
||||
* @return
|
||||
* @return {@code this}
|
||||
*
|
||||
* @since 1.14
|
||||
*/
|
||||
@@ -255,10 +257,11 @@ public class HttpRequest
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
* Enable or disable certificate validation of ssl certificates. The default
|
||||
* value is false.
|
||||
*
|
||||
*
|
||||
* @param disableCertificateValidation
|
||||
* @param disableCertificateValidation true to disable certificate validation
|
||||
* @since 1.17
|
||||
*/
|
||||
public void setDisableCertificateValidation(
|
||||
@@ -268,10 +271,11 @@ public class HttpRequest
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
* Enable or disable the validation of ssl hostnames. The default value is
|
||||
* false.
|
||||
*
|
||||
*
|
||||
* @param disableHostnameValidation
|
||||
* @param disableHostnameValidation true to disable ssl hostname validation
|
||||
* @since 1.17
|
||||
*/
|
||||
public void setDisableHostnameValidation(boolean disableHostnameValidation)
|
||||
@@ -280,12 +284,12 @@ public class HttpRequest
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
* Set http headers for the request.
|
||||
*
|
||||
*
|
||||
* @param headers
|
||||
* @param headers headers for the request
|
||||
*
|
||||
* @return
|
||||
* @return {@code this}
|
||||
*/
|
||||
public HttpRequest setHeaders(Map<String, List<String>> headers)
|
||||
{
|
||||
@@ -295,10 +299,10 @@ public class HttpRequest
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
* Ignore proxy settings. The default value is false.
|
||||
*
|
||||
*
|
||||
* @param ignoreProxySettings
|
||||
* @param ignoreProxySettings true to ignore proxy settings.
|
||||
* @since 1.17
|
||||
*/
|
||||
public void setIgnoreProxySettings(boolean ignoreProxySettings)
|
||||
@@ -307,12 +311,12 @@ public class HttpRequest
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
* Set http parameters for the request.
|
||||
*
|
||||
*
|
||||
* @param parameters
|
||||
* @param parameters parameters for the request
|
||||
*
|
||||
* @return
|
||||
* @return {@code this}
|
||||
*/
|
||||
public HttpRequest setParameters(Map<String, List<String>> parameters)
|
||||
{
|
||||
@@ -324,12 +328,12 @@ public class HttpRequest
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
* Append values to map.
|
||||
*
|
||||
*
|
||||
* @param map
|
||||
* @param name
|
||||
* @param values
|
||||
* @param map map to append values
|
||||
* @param name name of the key
|
||||
* @param values values to append
|
||||
*/
|
||||
private void appendValues(Map<String, List<String>> map, String name,
|
||||
String[] values)
|
||||
@@ -338,7 +342,7 @@ public class HttpRequest
|
||||
|
||||
if (valueList == null)
|
||||
{
|
||||
valueList = new ArrayList<String>();
|
||||
valueList = Lists.newArrayList(values);
|
||||
map.put(name, valueList);
|
||||
}
|
||||
|
||||
@@ -350,30 +354,30 @@ public class HttpRequest
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
/** map of request headers */
|
||||
private Map<String, List<String>> headers;
|
||||
|
||||
/** Field description */
|
||||
/** ignore proxy settings */
|
||||
private boolean ignoreProxySettings = false;
|
||||
|
||||
/** Field description */
|
||||
/** disable ssl hostname validation */
|
||||
private boolean disableHostnameValidation = false;
|
||||
|
||||
/** Field description */
|
||||
/** disable ssl certificate validation */
|
||||
private boolean disableCertificateValidation = false;
|
||||
|
||||
/** Field description */
|
||||
/** decode gzip */
|
||||
private boolean decodeGZip = false;
|
||||
|
||||
/** Field description */
|
||||
/** map of parameters */
|
||||
private Map<String, List<String>> parameters;
|
||||
|
||||
/** Field description */
|
||||
/** password for http basic authentication */
|
||||
private String password;
|
||||
|
||||
/** Field description */
|
||||
/** url for the request */
|
||||
private String url;
|
||||
|
||||
/** Field description */
|
||||
/** username for http basic authentication */
|
||||
private String username;
|
||||
}
|
||||
|
||||
@@ -43,6 +43,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Response of a {@link HttpRequest} execute by the {@link HttpClient}.
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
@@ -50,48 +51,48 @@ public interface HttpResponse extends Closeable
|
||||
{
|
||||
|
||||
/**
|
||||
* Method description
|
||||
* Returns the response body as stream.
|
||||
*
|
||||
*
|
||||
* @return
|
||||
* @return response body as stream
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
public InputStream getContent() throws IOException;
|
||||
|
||||
/**
|
||||
* Method description
|
||||
* Returns the response body as string.
|
||||
*
|
||||
*
|
||||
* @return
|
||||
* @return response body as string
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
public String getContentAsString() throws IOException;
|
||||
|
||||
/**
|
||||
* Method description
|
||||
* Returns the value of the first response header with the given name.
|
||||
*
|
||||
*
|
||||
* @param name
|
||||
* @param name name of the response header
|
||||
*
|
||||
* @return
|
||||
* @return value of the first response header with the given name
|
||||
*/
|
||||
public String getHeader(String name);
|
||||
|
||||
/**
|
||||
* Method description
|
||||
* Returns a map with all response headers.
|
||||
*
|
||||
*
|
||||
* @return
|
||||
* @return map with all response headers
|
||||
*/
|
||||
public Map<String, List<String>> getHeaderMap();
|
||||
|
||||
/**
|
||||
* Method description
|
||||
* Returns the status code of the response.
|
||||
*
|
||||
*
|
||||
* @return
|
||||
* @return status code
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user