public final class CommonsHttpTransport extends Object implements HttpTransport
HttpTransport based on Apache HttpComponents.| Modifier and Type | Class and Description |
|---|---|
static class |
CommonsHttpTransport.CachingBehavior
Use with
createHttpClient(com.atlassian.marketplace.client.http.HttpConfiguration, com.atlassian.fugue.Option<java.net.URI>) to indicate whether or not to
enable HTTP caching. |
| Constructor and Description |
|---|
CommonsHttpTransport(HttpConfiguration configuration,
URI baseUri) |
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Should be called to shutdown the Client HttpConnectionManager, this will prevent finaliser errors
from appearing in the log, and helps to prevent a resource leak.
|
static org.apache.http.client.HttpClient |
createHttpClient(HttpConfiguration config,
com.atlassian.fugue.Option<URI> baseUri)
Helper method that configures an HttpClient with the specified proxy/timeout properties.
|
SimpleHttpResponse |
delete(URI uri)
Performs an HTTP DELETE.
|
SimpleHttpResponse |
get(URI uri)
Performs an HTTP GET.
|
static org.apache.http.impl.client.HttpClientBuilder |
httpClientBuilder(HttpConfiguration config,
com.atlassian.fugue.Option<URI> baseUri,
CommonsHttpTransport.CachingBehavior cachingBehavior)
Helper method that configures an HttpClientBuilder with the specified proxy/timeout properties.
|
SimpleHttpResponse |
patch(URI uri,
byte[] content)
Performs an HTTP PATCH.
|
SimpleHttpResponse |
post(URI uri,
InputStream content,
long length,
String contentType,
String acceptContentType)
Performs an HTTP POST of an API entity.
|
SimpleHttpResponse |
postParams(URI uri,
com.google.common.collect.Multimap<String,String> params)
Performs an HTTP POST with form parameters.
|
SimpleHttpResponse |
put(URI uri,
byte[] content)
Performs an HTTP PUT of an API entity.
|
HttpTransport |
withRequestDecorator(RequestDecorator decorator)
Returns another
HttpTransport instance that behaves the same as this one except that
it adds headers from the specified RequestDecorator to every request (in
addition to any headers previously specified in the defaults). |
public CommonsHttpTransport(HttpConfiguration configuration, URI baseUri)
public SimpleHttpResponse get(URI uri) throws MpacException
HttpTransportget in interface HttpTransporturi - URI of resource to getSimpleHttpResponse wrapping the HTTP responseMpacException - if the server was unavailable or returned no responsepublic SimpleHttpResponse postParams(URI uri, com.google.common.collect.Multimap<String,String> params) throws MpacException
HttpTransportpostParams in interface HttpTransporturi - URI of resource to post toparams - the unencoded parametersSimpleHttpResponse wrapping the HTTP responseMpacException - if the server was unavailable or returned no responsepublic SimpleHttpResponse post(URI uri, InputStream content, long length, String contentType, String acceptContentType) throws MpacException
HttpTransportpost in interface HttpTransporturi - URI of resource to post tocontent - input stream containing the request bodylength - length of the input streamcontentType - content type of the entityacceptContentType - expected content type of responseSimpleHttpResponse wrapping the HTTP responseMpacException - if the server was unavailable or returned no responsepublic SimpleHttpResponse put(URI uri, byte[] content) throws MpacException
HttpTransportput in interface HttpTransporturi - URI of resource to putcontent - request bodySimpleHttpResponse wrapping the HTTP responseMpacException - if the server was unavailable or returned no responsepublic SimpleHttpResponse patch(URI uri, byte[] content) throws MpacException
HttpTransportpatch in interface HttpTransporturi - URI of resource to putcontent - request bodySimpleHttpResponse wrapping the HTTP responseMpacException - if the server was unavailable or returned no responsepublic SimpleHttpResponse delete(URI uri) throws MpacException
HttpTransportdelete in interface HttpTransporturi - URI of resource to deleteSimpleHttpResponse wrapping the HTTP responseMpacException - if the server was unavailable or returned no responsepublic HttpTransport withRequestDecorator(RequestDecorator decorator)
HttpTransportHttpTransport instance that behaves the same as this one except that
it adds headers from the specified RequestDecorator to every request (in
addition to any headers previously specified in the defaults). The new instance still
uses the same underlying HTTP transport; closing one will close the other.withRequestDecorator in interface HttpTransportdecorator - will generate additional headers for requests made via the new instanceHttpTransport instancepublic void close()
close in interface Closeableclose in interface AutoCloseablepublic static org.apache.http.client.HttpClient createHttpClient(HttpConfiguration config, com.atlassian.fugue.Option<URI> baseUri)
RequestDecorators, etc.config - an HttpConfigurationbaseUri - base URI of the Marketplace server; this is only relevant if you're providing
basicauth credentials for the server itself (rather than for the proxy)public static org.apache.http.impl.client.HttpClientBuilder httpClientBuilder(HttpConfiguration config, com.atlassian.fugue.Option<URI> baseUri, CommonsHttpTransport.CachingBehavior cachingBehavior)
RequestDecorators, etc.config - an HttpConfigurationbaseUri - base URI of the Marketplace server; this is only relevant if you're providing
basicauth credentials for the server itself (rather than for the proxy)cachingBehavior - determines whether to use a caching clientCopyright © 2016 Atlassian. All rights reserved.