Package org.openspaces.rest.space
Class SpaceAPIController
java.lang.Object
org.openspaces.rest.space.SpaceAPIController
@Controller
@Api(name="Space API",
description="Methods for interacting with space")
public class SpaceAPIController
extends Object
Spring MVC controller for the RESTful Space API usage examples: GET:
http://localhost:8080/rest/data/Item/_introduce_type?spaceid=customerid
http://localhost:8080/rest/data/Item/1 http://192.168.9.47:8080/rest/data/Item/_criteria?q=data2='common'
Limit result size: http://192.168.9.47:8080/rest/data/Item/_criteria?q=data2='common'&s=10
DELETE: curl -XDELETE http://localhost:8080/rest/data/Item/1 curl -XDELETE
http://localhost:8080/rest/data/Item/_criteria?q=id=1 Limit result size: curl -XDELETE
http://localhost:8080/rest/data/Item/_criteria?q=data2='common'&s=5 POST: curl -XPOST -d
'[{"id":"1", "data":"testdata", "data2":"common", "nestedData" : {"nestedKey1":"nestedValue1"}},
{"id":"2", "data":"testdata2", "data2":"common", "nestedData" : {"nestedKey2":"nestedValue2"}},
{"id":"3", "data":"testdata3", "data2":"common", "nestedData" : {"nestedKey3":"nestedValue3"}}]'
http://localhost:8080/rest/data/Item The response is a json object: On Sucess: {
"status" : "success" } If there is a data: { "status" : "success", "data" : {...} or [{...},
{...}] } On Failure: If Inner error (TypeNotFound/ObjectNotFound) then { "status" : "error",
"error": { "message": "some error message" } } If it is a XAP exception: { "status" : "error",
"error": { "java.class" : "the exception's class name", "message": "exception.getMessage()" } }
- Since:
- 8.0
- Author:
- rafi
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionREST COUNT request handlerdeleteById(String type, String id) REST DELETE by id request handlerdeleteByQuery(String type, String query, Integer max) REST DELETE by query request handlergetBoolean(com.fasterxml.jackson.databind.JsonNode node) REST GET by ID request handlergetByQuery(String type, String query, Integer size) REST GET by query request handlergetString(com.fasterxml.jackson.databind.JsonNode node) introduceType(String type, String spaceID) Deprecated.introduceTypeAdvanced(String type, String requestBody) REST POST request handlerresolveDataAccessException(org.springframework.dao.DataAccessException e) DataAcessException Handler, returns an error response to the clientObjectNotFoundException Handler, returns an error response to the clientTypeNotFoundException Handler, returns an error response to the clientvoidsetDatetimeFormat(String datetimeFormat) voidsetLookupGroups(String lookupGroups) voidsetLookupLocators(String lookupLocators) voidsetSpaceName(String spaceName)
-
Constructor Details
-
SpaceAPIController
public SpaceAPIController()
-
-
Method Details
-
setSpaceName
-
setLookupGroups
-
setLookupLocators
-
setDatetimeFormat
-
introduceType
@Deprecated @RequestMapping(value="/{type}/_introduce_type", method=GET, produces="application/json") @ResponseBody public Map<String,Object> introduceType(@PathVariable String type, @RequestParam(value="spaceid",defaultValue="id") String spaceID) Deprecated.UseintroduceTypeAdvanced(String, String)insteadREST GET for introducing type to space- Parameters:
type- type name- Returns:
- Map<String, Object>
-
getString
-
getBoolean
-
introduceTypeAdvanced
@ApiMethod(path="{type}/_introduce_type", verb=PUT, description="Introduces the specified type to the space with the provided description in the body", consumes="application/json", produces="application/json") @RequestMapping(value="/{type}/_introduce_type", method=PUT, consumes="application/json", produces="application/json") @ResponseBody public Map<String,Object> introduceTypeAdvanced(@PathVariable @ApiPathParam(name="type",description="The type name") String type, @RequestBody(required=false) @ApiBodyObject String requestBody) -
getByQuery
@ApiMethod(path="{type}/", verb=GET, description="Read multiple entries from space that matches the query.", produces="application/json") @RequestMapping(value="/{type}", method=GET, produces="application/json") @ResponseBody public Map<String,Object> getByQuery(@PathVariable @ApiPathParam(name="type",description="The type name") String type, @RequestParam(value="query",required=false) @ApiQueryParam(name="query",description="a SQLQuery that is a SQL-like syntax") String query, @RequestParam(value="max",required=false) @ApiQueryParam(name="size",description="") Integer size) throws ObjectNotFoundException REST GET by query request handler- Returns:
- Map<String, Object>
- Throws:
ObjectNotFoundException
-
getById
@ApiMethod(path="{type}/{id}", verb=GET, description="Read entry from space with the provided id", produces="application/json") @RequestMapping(value="/{type}/{id}", method=GET, produces="application/json") @ResponseBody public Map<String,Object> getById(@PathVariable @ApiPathParam(name="type",description="The type name") String type, @PathVariable @ApiPathParam(name="id") String id) throws ObjectNotFoundException REST GET by ID request handler- Returns:
- Map<String, Object>
- Throws:
ObjectNotFoundException
-
count
@ApiMethod(path="{type}/count", verb=GET, description="Returns the number of entries in space of the specified type\n", produces="application/json") @RequestMapping(value="/{type}/count", method=GET, produces="application/json") @ResponseBody public Map<String,Object> count(@ApiPathParam(name="type",description="The type name") @PathVariable String type) throws ObjectNotFoundException REST COUNT request handler- Throws:
ObjectNotFoundException
-
deleteById
@ApiMethod(path="{type}/{id}", verb=DELETE, description="Gets and deletes the entry from space with the provided id.", produces="application/json") @RequestMapping(value="/{type}/{id}", method=DELETE, produces="application/json") @ResponseBody public Map<String,Object> deleteById(@ApiPathParam(name="type",description="The type name") @PathVariable String type, @ApiPathParam(name="id") @PathVariable String id) throws ObjectNotFoundException REST DELETE by id request handler- Returns:
- Map<String, Object>
- Throws:
ObjectNotFoundException
-
deleteByQuery
@ApiMethod(path="{type}/", verb=DELETE, description="Gets and deletes entries from space that matches the query.", produces="application/json") @RequestMapping(value="/{type}", method=DELETE, produces="application/json") @ResponseBody public Map<String,Object> deleteByQuery(@ApiPathParam(name="type",description="The type name") @PathVariable String type, @ApiQueryParam(name="query") @RequestParam("query") String query, @ApiQueryParam(name="max",description="The maximum number of entries to return. Default is Integer.MAX_VALUE") @RequestParam(value="max",required=false) Integer max) REST DELETE by query request handler- Returns:
- Map<String, Object>
-
post
@ApiMethod(path="{type}/", verb=POST, description="Write one or more entries to the space.", consumes="application/json", produces="application/json") @RequestMapping(value="/{type}", method=POST, consumes="application/json", produces="application/json") @ResponseBody public Map<String,Object> post(@ApiPathParam(name="type",description="The type name") @PathVariable String type, @RequestBody(required=false) @ApiBodyObject(clazz=ErrorMessage.class) String requestBody) throws TypeNotFoundException REST POST request handler- Returns:
- Map<String, Object>
- Throws:
TypeNotFoundException
-
resolveTypeDescriptorNotFoundException
@ExceptionHandler(TypeNotFoundException.class) @ResponseStatus(NOT_FOUND) @ResponseBody public ErrorResponse resolveTypeDescriptorNotFoundException(TypeNotFoundException e) throws IOException TypeNotFoundException Handler, returns an error response to the client- Throws:
IOException
-
resolveDocumentNotFoundException
@ExceptionHandler(ObjectNotFoundException.class) @ResponseStatus(NOT_FOUND) @ResponseBody public ErrorResponse resolveDocumentNotFoundException(ObjectNotFoundException e) throws IOException ObjectNotFoundException Handler, returns an error response to the client- Throws:
IOException
-
resolveDataAccessException
@ExceptionHandler(org.springframework.dao.DataAccessException.class) @ResponseStatus(INTERNAL_SERVER_ERROR) @ResponseBody public ErrorResponse resolveDataAccessException(org.springframework.dao.DataAccessException e) throws IOException DataAcessException Handler, returns an error response to the client- Throws:
IOException
-
resolveCannotFindSpaceException
@ExceptionHandler(CannotFindSpaceException.class) @ResponseStatus(INTERNAL_SERVER_ERROR) @ResponseBody public ErrorResponse resolveCannotFindSpaceException(CannotFindSpaceException e) throws IOException - Throws:
IOException
-
resoleTypeAlreadyRegisteredException
@ExceptionHandler(TypeAlreadyRegisteredException.class) @ResponseStatus(INTERNAL_SERVER_ERROR) @ResponseBody public ErrorResponse resoleTypeAlreadyRegisteredException(TypeAlreadyRegisteredException e) throws IOException - Throws:
IOException
-
resolveRestIntroduceTypeException
@ExceptionHandler(RestException.class) @ResponseStatus(INTERNAL_SERVER_ERROR) @ResponseBody public ErrorResponse resolveRestIntroduceTypeException(RestException e) throws IOException - Throws:
IOException
-
resolveRuntimeException
@ExceptionHandler(java.lang.RuntimeException.class) @ResponseStatus(INTERNAL_SERVER_ERROR) @ResponseBody public ErrorResponse resolveRuntimeException(RuntimeException e) throws IOException - Throws:
IOException
-
resolveUnsupportedTypeException
@ExceptionHandler(UnsupportedTypeException.class) @ResponseStatus(INTERNAL_SERVER_ERROR) @ResponseBody public ErrorResponse resolveUnsupportedTypeException(UnsupportedTypeException e) throws IOException - Throws:
IOException
-
introduceTypeAdvanced(String, String)instead