Class OkHttpHelper
java.lang.Object
com.janeirodigital.shapetrees.client.okhttp.OkHttpHelper
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic okhttp3.Headers
addHttpHeader
(HttpHeader name, String value) Add the HTTP header identified byname
with the providedvalue
.static okhttp3.Headers
addHttpHeader
(HttpHeader name, String value, okhttp3.Headers headers) Add the HTTP header identified byname
with the providedvalue
.static okhttp3.Headers
addLinkRelationHeader
(LinkRelation type, String target) Add an HTTP Link Relation header oftype
with the providedtarget
.static okhttp3.Headers
addLinkRelationHeader
(LinkRelation type, String target, okhttp3.Headers headers) Add an HTTP Link Relation header oftype
with the providedtarget
.static okhttp3.Headers
attributesToHeaders
(ResourceAttributes attributes) Converts "multi map" representation of attributes to the OkHttp Headers class public for OkHttpValidatingShapeTreeInterceptor.createResponsestatic okhttp3.Response
check
(okhttp3.Response response) static okhttp3.Response
checkResponse
(okhttp3.Response response) Check the providedresponse
for viabilitystatic okhttp3.Response
createErrorResponse
(okhttp3.Request nativeRequest, ShapeTreeException exception) static okhttp3.Response
createInvalidResponse
(okhttp3.Request nativeRequest, ContainingValidationResult containingResult) static okhttp3.Response
createInvalidResponse
(okhttp3.Request nativeRequest, ValidationResult result) static okhttp3.Response
createResponse
(okhttp3.Request nativeRequest, int code) static okhttp3.Response
deleteHttpResource
(okhttp3.OkHttpClient okHttpClient, URL url, String credentials) CalldeleteHttpResource(OkHttpClient, URL, String, Headers)
without any additional headers suppliedstatic okhttp3.Response
deleteHttpResource
(okhttp3.OkHttpClient okHttpClient, URL url, String credentials, okhttp3.Headers headers) Perform an HTTP DELETE on the resource aturl
.static okhttp3.Response
getHttpResource
(okhttp3.OkHttpClient okHttpClient, URL url, String credentials) CallsgetHttpResource(OkHttpClient, URL, String, Headers)
without any additional headers supplied.static okhttp3.Response
getHttpResource
(okhttp3.OkHttpClient okHttpClient, URL url, String credentials, okhttp3.Headers headers) Perform an HTTP GET on the resource aturl
.static String
getLinkRelationString
(LinkRelation type, String target) Get a formatted HTTP Link Relation string in compliance with RFC 8288static okhttp3.Response
patchHttpResource
(okhttp3.OkHttpClient okHttpClient, URL url, String credentials, String body, ContentType contentType) CallpatchHttpResource(OkHttpClient, URL, String, Headers, String, ContentType)
without any additional headers suppliedstatic okhttp3.Response
patchHttpResource
(okhttp3.OkHttpClient okHttpClient, URL url, String credentials, okhttp3.Headers headers, String body, ContentType contentType) Perform an HTTP PATCH on the resource aturl
.static okhttp3.Response
postHttpResource
(okhttp3.OkHttpClient okHttpClient, URL url, String credentials, String body, ContentType contentType) CallpostHttpResource(OkHttpClient, URL, String, Headers, String, ContentType)
without any additional headers supplied.static okhttp3.Response
postHttpResource
(okhttp3.OkHttpClient okHttpClient, URL url, String credentials, okhttp3.Headers headers, String body, ContentType contentType) Perform an HTTP POST on the resource aturl
.static okhttp3.Response
putHttpResource
(okhttp3.OkHttpClient okHttpClient, URL url, String credentials, String body, ContentType contentType) CallputHttpResource(OkHttpClient, URL, String, Headers, String, ContentType)
without any additional headers suppliedstatic okhttp3.Response
putHttpResource
(okhttp3.OkHttpClient okHttpClient, URL url, String credentials, okhttp3.Headers headers, String body, ContentType contentType) Perform an HTTP PUT on the resource aturl
.static okhttp3.Headers
setHttpHeader
(HttpHeader name, String value) Set the HTTP header identified byname
with the providedvalue
.static okhttp3.Headers
setHttpHeader
(HttpHeader name, String value, okhttp3.Headers headers) Set the HTTP header identified byname
with the providedvalue
.
-
Constructor Details
-
OkHttpHelper
public OkHttpHelper()
-
-
Method Details
-
getHttpResource
public static okhttp3.Response getHttpResource(okhttp3.OkHttpClient okHttpClient, URL url, String credentials, okhttp3.Headers headers) throws ShapeTreeException Perform an HTTP GET on the resource aturl
. The response MUST be closed outside of this call. The body of the response is returned as a one-shot stream, and MUST BE CLOSED separately by the caller.- Parameters:
okHttpClient
- OkHttpClient to perform the GET withurl
- URL of the resource to GETcredentials
- Optional credential string to include in Authorization Http Headerheaders
- Optional OkHttp Headers to include- Returns:
- OkHttp Response
- Throws:
ShapeTreeException
- See Also:
-
getHttpResource
public static okhttp3.Response getHttpResource(okhttp3.OkHttpClient okHttpClient, URL url, String credentials) throws ShapeTreeException CallsgetHttpResource(OkHttpClient, URL, String, Headers)
without any additional headers supplied.- Parameters:
okHttpClient
- OkHttpClient to perform the GET withurl
- URL of the resource to GETcredentials
- Optional credential string to include in Authorization Http Header- Returns:
- OkHttp Response
- Throws:
ShapeTreeException
-
postHttpResource
public static okhttp3.Response postHttpResource(okhttp3.OkHttpClient okHttpClient, URL url, String credentials, okhttp3.Headers headers, String body, ContentType contentType) throws ShapeTreeException Perform an HTTP POST on the resource aturl
. ResponseBody is closed automatically.- Parameters:
okHttpClient
- OkHttpClient to perform the POST withurl
- URL of the resource to POST intocredentials
- Optional credential string to include in Authorization Http Headerheaders
- Optional OkHttp Headers to includebody
- Body of the POST requestcontentType
-ContentType
of the POST request- Returns:
- OkHttp Response
- Throws:
ShapeTreeException
-
postHttpResource
public static okhttp3.Response postHttpResource(okhttp3.OkHttpClient okHttpClient, URL url, String credentials, String body, ContentType contentType) throws ShapeTreeException CallpostHttpResource(OkHttpClient, URL, String, Headers, String, ContentType)
without any additional headers supplied.- Parameters:
okHttpClient
- OkHttpClient to perform the POST withurl
- URL of the resource to POST intocredentials
- Optional credential string to include in Authorization Http Headerbody
- Body of the POST requestcontentType
-ContentType
of the POST request- Returns:
- OkHttp Response * @return
- Throws:
ShapeTreeException
-
putHttpResource
public static okhttp3.Response putHttpResource(okhttp3.OkHttpClient okHttpClient, URL url, String credentials, okhttp3.Headers headers, String body, ContentType contentType) throws ShapeTreeException Perform an HTTP PUT on the resource aturl
. ResponseBody is closed automatically.- Parameters:
okHttpClient
- OkHttpClient to perform the PUT withurl
- URL of the resource to PUTcredentials
- Optional credential string to include in Authorization Http Headerheaders
- Optional OkHttp Headers to includebody
- Body of the PUT requestcontentType
-ContentType
of the PUT request- Returns:
- OkHttp Response
- Throws:
ShapeTreeException
-
putHttpResource
public static okhttp3.Response putHttpResource(okhttp3.OkHttpClient okHttpClient, URL url, String credentials, String body, ContentType contentType) throws ShapeTreeException CallputHttpResource(OkHttpClient, URL, String, Headers, String, ContentType)
without any additional headers supplied- Parameters:
okHttpClient
- OkHttpClient to perform the PUT withurl
- URL of the resource to PUTcredentials
- Optional credential string to include in Authorization Http Headerbody
- Body of the PUT requestcontentType
-ContentType
of the PUT request- Returns:
- OkHttp Response
- Throws:
ShapeTreeException
-
patchHttpResource
public static okhttp3.Response patchHttpResource(okhttp3.OkHttpClient okHttpClient, URL url, String credentials, okhttp3.Headers headers, String body, ContentType contentType) throws ShapeTreeException Perform an HTTP PATCH on the resource aturl
. ResponseBody is closed automatically.- Parameters:
okHttpClient
- OkHttpClient to perform the PATCH withurl
- URL of the resource to PATCHcredentials
- Optional credential string to include in Authorization Http Headerheaders
- Optional OkHttp Headers to includebody
- Body of the PATCH requestcontentType
-ContentType
of the PATCH request- Returns:
- OkHttp Response
- Throws:
ShapeTreeException
-
patchHttpResource
public static okhttp3.Response patchHttpResource(okhttp3.OkHttpClient okHttpClient, URL url, String credentials, String body, ContentType contentType) throws ShapeTreeException CallpatchHttpResource(OkHttpClient, URL, String, Headers, String, ContentType)
without any additional headers supplied- Parameters:
okHttpClient
- OkHttpClient to perform the PATCH withurl
- URL of the resource to PATCHcredentials
- Optional credential string to include in Authorization Http Headerbody
- Body of the PATCH requestcontentType
-ContentType
of the PATCH request- Returns:
- OkHttp Response
- Throws:
ShapeTreeException
-
deleteHttpResource
public static okhttp3.Response deleteHttpResource(okhttp3.OkHttpClient okHttpClient, URL url, String credentials, okhttp3.Headers headers) throws ShapeTreeException Perform an HTTP DELETE on the resource aturl
. ResponseBody is closed automatically.- Parameters:
okHttpClient
- OkHttpClient to perform the DELETE withurl
- URL of the resource to DELETEcredentials
- Optional credential string to include in Authorization Http Headerheaders
- Optional OkHttp Headers to include- Returns:
- OkHttp Response
- Throws:
ShapeTreeException
-
deleteHttpResource
public static okhttp3.Response deleteHttpResource(okhttp3.OkHttpClient okHttpClient, URL url, String credentials) throws ShapeTreeException CalldeleteHttpResource(OkHttpClient, URL, String, Headers)
without any additional headers supplied- Parameters:
okHttpClient
- OkHttpClient to perform the DELETE withurl
- URL of the resource to DELETEcredentials
- Optional credential string to include in Authorization Http Header- Returns:
- OkHttp Response
- Throws:
ShapeTreeException
-
checkResponse
Check the providedresponse
for viability- Parameters:
response
- Response to check- Returns:
- Checked response
- Throws:
ShapeTreeException
-
setHttpHeader
Set the HTTP header identified byname
with the providedvalue
. Ifheaders
are provided, they will be included in the Headers returned. If the Header to set already exists in that set, it will be updated.- Parameters:
name
-HttpHeader
to setvalue
- Value to use for the headerheaders
- Optional OkHttp Headers to include- Returns:
- Updated OkHttp Headers
-
setHttpHeader
Set the HTTP header identified byname
with the providedvalue
.- Parameters:
name
-HttpHeader
to setvalue
- Value to use for the header- Returns:
- Updated OkHttp Headers
-
addHttpHeader
Add the HTTP header identified byname
with the providedvalue
. Ifheaders
are provided, they will be included in the Headers returned.- Parameters:
name
-HttpHeader
to addvalue
- Value to use for the added headerheaders
- Optional OkHttp Headers to include- Returns:
- Populated OkHttp Headers
-
addHttpHeader
Add the HTTP header identified byname
with the providedvalue
.- Parameters:
name
-HttpHeader
to addvalue
- Value to use for the added header- Returns:
- Populated OkHttp Headers
-
attributesToHeaders
Converts "multi map" representation of attributes to the OkHttp Headers class public for OkHttpValidatingShapeTreeInterceptor.createResponse- Parameters:
attributes
- Multi-map representation of attributes- Returns:
- OkHttp Headers object
-
addLinkRelationHeader
public static okhttp3.Headers addLinkRelationHeader(LinkRelation type, String target, okhttp3.Headers headers) Add an HTTP Link Relation header oftype
with the providedtarget
. Ifheaders
are provided, they will be included in the Headers returned.- Parameters:
type
- Link relation typetarget
- Link relation targetheaders
- Optional OkHttp Headers to include- Returns:
- Populated OkHttp Headers
- See Also:
-
addLinkRelationHeader
Add an HTTP Link Relation header oftype
with the providedtarget
.- Parameters:
type
- Link relation typetarget
- Link relation target- Returns:
- Populated OkHttp Headers
- See Also:
-
getLinkRelationString
Get a formatted HTTP Link Relation string in compliance with RFC 8288- Parameters:
type
- Link relation typetarget
- Link relation target- Returns:
- Formatted Link Relation string
-
createInvalidResponse
public static okhttp3.Response createInvalidResponse(okhttp3.Request nativeRequest, ValidationResult result) throws ShapeTreeException - Throws:
ShapeTreeException
-
createInvalidResponse
public static okhttp3.Response createInvalidResponse(okhttp3.Request nativeRequest, ContainingValidationResult containingResult) throws ShapeTreeException - Throws:
ShapeTreeException
-
createErrorResponse
public static okhttp3.Response createErrorResponse(okhttp3.Request nativeRequest, ShapeTreeException exception) -
createResponse
public static okhttp3.Response createResponse(okhttp3.Request nativeRequest, int code) -
check
- Throws:
IOException
-