Class OkHttpResourceAccessor
java.lang.Object
com.janeirodigital.shapetrees.client.okhttp.OkHttpResourceAccessor
- All Implemented Interfaces:
ResourceAccessor
Allows the
shapetrees-core
to access
ManageableInstance
s and InstanceResource
s over the network via HTTP. This is
particularly effective when employing client-side shape-tree validation in a
proxy scenario.
Given the fact that resources are accessed via HTTP, some inferences must be made on resource state based on responses to HTTP requests.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncreateResource
(ShapeTreeContext context, URL url, ResourceAttributes attributes, String body, String contentType) deleteResource
(ShapeTreeContext context, InstanceResource deleteResource) Deletes the providedInstanceResource
deleteResource
getResource
(ShapeTreeContext context, URL url) Get aInstanceResource
at the providedurl
, which may or may not exist.updateResource
(ShapeTreeContext context, InstanceResource updateResource, String body)
-
Constructor Details
-
OkHttpResourceAccessor
public OkHttpResourceAccessor()
-
-
Method Details
-
getResource
Get aInstanceResource
at the providedurl
, which may or may not exist. Most of the work happens ingenerateResource(URL, DocumentResponse)
, which processes the response and returns the corresponding typed resource.- Specified by:
getResource
in interfaceResourceAccessor
- Parameters:
context
-ShapeTreeContext
url
- Url of the resource to get- Returns:
InstanceResource
- Throws:
ShapeTreeException
-
createResource
public InstanceResource createResource(ShapeTreeContext context, URL url, ResourceAttributes attributes, String body, String contentType) throws ShapeTreeException Create aInstanceResource
at the providedurl
via the provided HTTPmethod
. Most of the work happens ingenerateResource(URL, DocumentResponse)
, which processes the response and returns the corresponding typed resource.- Specified by:
createResource
in interfaceResourceAccessor
- Parameters:
context
-ShapeTreeContext
url
- Url of the resource to createattributes
- HTTP attributes to use for resource creationbody
- Body of resource to createcontentType
- HTTP content-type- Returns:
InstanceResource
- Throws:
ShapeTreeException
-
updateResource
public DocumentResponse updateResource(ShapeTreeContext context, InstanceResource updateResource, String body) throws ShapeTreeException - Specified by:
updateResource
in interfaceResourceAccessor
- Parameters:
context
- Shape tree contextupdateResource
-InstanceResource
to updatebody
- Body to use for update- Returns:
DocumentResponse
of the result- Throws:
ShapeTreeException
-
deleteResource
public DocumentResponse deleteResource(ShapeTreeContext context, InstanceResource deleteResource) throws ShapeTreeException Deletes the providedInstanceResource
deleteResource
- Specified by:
deleteResource
in interfaceResourceAccessor
- Parameters:
context
-ShapeTreeContext
deleteResource
-InstanceResource
to delete- Returns:
DocumentResponse
of the result- Throws:
ShapeTreeException
-