Package org.apache.sling.servlets.post
Class JSONResponse
java.lang.Object
org.apache.sling.servlets.post.AbstractPostResponse
org.apache.sling.servlets.post.JSONResponse
- All Implemented Interfaces:
PostResponse
The
JSONResponse
is an AbstractPostResponse
preparing
the response in JSON.-
Nested Class Summary
-
Field Summary
Fields inherited from class org.apache.sling.servlets.post.AbstractPostResponse
PN_ERROR, PN_IS_CREATED, PN_LOCATION, PN_PARENT_LOCATION, PN_PATH, PN_REFERER, PN_STATUS_CODE, PN_STATUS_MESSAGE, PN_TITLE
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
doSend
(javax.servlet.http.HttpServletResponse response) getError()
Returns any recorded error ornull
getProperty
(String name) Returns the generic response property with the given name and type ornull
if no such property exists.void
Records a generic change of the giventype
with arguments.void
Sets the recorded error causing the operation to fail.void
setProperty
(String name, Object value) This method accepts values that correspond to json primitives or otherwise assumes that the toString() of the value can be parsed as json.Methods inherited from class org.apache.sling.servlets.post.AbstractPostResponse
getLocation, getParentLocation, getPath, getProperty, getReferer, getStatusCode, getStatusMessage, isCreateRequest, isSafeReferer, isSuccessful, onCopied, onCreated, onDeleted, onModified, onMoved, send, setCreateRequest, setLocation, setParentLocation, setPath, setReferer, setStatus, setTitle
-
Field Details
-
RESPONSE_CONTENT_TYPE
- See Also:
-
-
Constructor Details
-
JSONResponse
public JSONResponse()
-
-
Method Details
-
onChange
Description copied from interface:PostResponse
Records a generic change of the giventype
with arguments.- Parameters:
type
- The type of the modificationarguments
- The arguments to the modifications
-
setError
Description copied from interface:PostResponse
Sets the recorded error causing the operation to fail.- Specified by:
setError
in interfacePostResponse
- Overrides:
setError
in classAbstractPostResponse
- Parameters:
error
- the throwable
-
getError
Description copied from class:AbstractPostResponse
Returns any recorded error ornull
- Specified by:
getError
in interfacePostResponse
- Overrides:
getError
in classAbstractPostResponse
- Returns:
- an error or
null
-
setProperty
This method accepts values that correspond to json primitives or otherwise assumes that the toString() of the value can be parsed as json. If neither is the case it will throw an Exception. Assuming the above holds, it will put the value as json directly into the json value part of the response.- Overrides:
setProperty
in classAbstractPostResponse
- Parameters:
name
- name of the propertyvalue
- value of the property - either of type {String, Boolean, Number, null} or the toString() is parseable as json- Throws:
JSONResponse.JSONResponseException
- if the value is not usable
-
getProperty
Description copied from class:AbstractPostResponse
Returns the generic response property with the given name and type ornull
if no such property exists.- Overrides:
getProperty
in classAbstractPostResponse
- Parameters:
name
- the name of the response property- Returns:
- the requested property (might be null)
-
doSend
- Specified by:
doSend
in classAbstractPostResponse
- Throws:
IOException
-