Class OkHttpResourceAccessor
java.lang.Object
com.janeirodigital.shapetrees.client.okhttp.OkHttpResourceAccessor
- All Implemented Interfaces:
ResourceAccessor
Allows the
shapetrees-core to access
ManageableInstances and InstanceResources 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 providedInstanceResourcedeleteResourcegetResource(ShapeTreeContext context, URL url) Get aInstanceResourceat the providedurl, which may or may not exist.updateResource(ShapeTreeContext context, InstanceResource updateResource, String body)
-
Constructor Details
-
OkHttpResourceAccessor
public OkHttpResourceAccessor()
-
-
Method Details
-
getResource
Get aInstanceResourceat 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:
getResourcein interfaceResourceAccessor- Parameters:
context-ShapeTreeContexturl- 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 aInstanceResourceat the providedurlvia the provided HTTPmethod. Most of the work happens ingenerateResource(URL, DocumentResponse), which processes the response and returns the corresponding typed resource.- Specified by:
createResourcein interfaceResourceAccessor- Parameters:
context-ShapeTreeContexturl- 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:
updateResourcein interfaceResourceAccessor- Parameters:
context- Shape tree contextupdateResource-InstanceResourceto updatebody- Body to use for update- Returns:
DocumentResponseof the result- Throws:
ShapeTreeException
-
deleteResource
public DocumentResponse deleteResource(ShapeTreeContext context, InstanceResource deleteResource) throws ShapeTreeException Deletes the providedInstanceResourcedeleteResource- Specified by:
deleteResourcein interfaceResourceAccessor- Parameters:
context-ShapeTreeContextdeleteResource-InstanceResourceto delete- Returns:
DocumentResponseof the result- Throws:
ShapeTreeException
-