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 Details

    • SpaceAPIController

      public SpaceAPIController()
  • Method Details

    • setSpaceName

      @Value("${spaceName}") public void setSpaceName(String spaceName)
    • setLookupGroups

      @Value("${lookupGroups}") public void setLookupGroups(String lookupGroups)
    • setLookupLocators

      @Value("${lookupLocators}") public void setLookupLocators(String lookupLocators)
    • setDatetimeFormat

      @Value("${datetime_format}") public void setDatetimeFormat(String datetimeFormat)
    • 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.
      REST GET for introducing type to space
      Parameters:
      type - type name
      Returns:
      Map<String, Object>
    • getString

      public String getString(com.fasterxml.jackson.databind.JsonNode node)
    • getBoolean

      public Boolean getBoolean(com.fasterxml.jackson.databind.JsonNode node)
    • 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