|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.wicketstuff.rest.resource.AbstractRestResource<T>
public abstract class AbstractRestResource<T extends IWebSerialDeserial>
Base class to build a resource that serves REST requests.
Nested Class Summary |
---|
Nested classes/interfaces inherited from interface org.apache.wicket.request.resource.IResource |
---|
IResource.Attributes |
Constructor Summary | |
---|---|
AbstractRestResource(T serialDeserial)
Constructor with no role-checker (i.e we don't use annotation AuthorizeInvocation ). |
|
AbstractRestResource(T serialDeserial,
IRoleCheckingStrategy roleCheckingStrategy)
Main constructor that takes in input the object serializer/deserializer and the role-checking strategy to use. |
Method Summary | ||
---|---|---|
protected void |
configureObjSerialDeserial(T objSerialDeserial)
Deprecated. use onConfigure(T objSerialDeserial) instead. |
|
static Url |
extractUrlFromRequest()
Utility method to extract the client URL from the current request. |
|
static WebRequest |
getCurrentWebRequest()
Utility method to retrieve the current web request. |
|
static WebResponse |
getCurrentWebResponse()
Utility method to retrieve the current web response. |
|
protected Map<String,List<MethodMappingInfo>> |
getMappedMethods()
Return mapped methods grouped by number of segments and HTTP method. |
|
protected IValidator |
getValidator(String key)
Retrieve a registered validato. |
|
boolean |
isMimeTypeSupported(String mimeType)
Check if a given MIME type is handled. |
|
static void |
noSuitableMethodFound(WebResponse response,
HttpMethod httpMethod)
This method can be used to write a standard error message to the current response object when no mapped method has been found for the current request. |
|
void |
objectToResponse(Object result,
WebResponse response,
String mimeType)
Method invoked to serialize the result of the invoked method and write this value to the response. |
|
protected void |
onAfterMethodInvoked(MethodMappingInfo mappedMethod,
IResource.Attributes attributes,
Object result)
Invoked just after a mapped method has been invoked to serve the current request. |
|
protected void |
onBeforeMethodInvoked(MethodMappingInfo mappedMethod,
IResource.Attributes attributes)
Invoked just before a mapped method is invoked to serve the current request. |
|
protected void |
onInitialize(T objSerialDeserial)
Method called to initialize and configure the resource. |
|
protected void |
registerValidator(String key,
IValidator validator)
Register a Wicket validator for the current resource. |
|
|
requestToObject(WebRequest request,
Class<T> argClass,
String mimeType)
Internal method that tries to extract an instance of the given class from the request body. |
|
void |
respond(IResource.Attributes attributes)
Handles a REST request invoking one of the methods annotated with MethodMapping . |
|
protected void |
setResponseStatusCode(int statusCode)
Set the status code for the current response. |
|
static Object |
toObject(Class clazz,
String value)
Utility method to convert string values to the corresponding objects. |
|
protected void |
unregisterValidator(String key)
Unregister a Wicket validator. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public AbstractRestResource(T serialDeserial)
AuthorizeInvocation
).
serialDeserial
- General class that is used to serialize/desiarilze objects to string.public AbstractRestResource(T serialDeserial, IRoleCheckingStrategy roleCheckingStrategy)
serialDeserial
- General class that is used to serialize/desiarilze objects to stringroleCheckingStrategy
- the role-checking strategy.Method Detail |
---|
public final void respond(IResource.Attributes attributes)
MethodMapping
. If
the annotated method returns a value, this latter is automatically serialized to a given
string format (like JSON, XML, etc...) and written to the web response.AuthorizeInvocation
).
respond
in interface IResource
attributes
- the Attribute object of the current requestpublic static void noSuitableMethodFound(WebResponse response, HttpMethod httpMethod)
response
- the current response objecthttpMethod
- the HTTP method of the current requestprotected void onBeforeMethodInvoked(MethodMappingInfo mappedMethod, IResource.Attributes attributes)
mappedMethod
- the mapped method.attributes
- the current Attributes object.protected void onAfterMethodInvoked(MethodMappingInfo mappedMethod, IResource.Attributes attributes, Object result)
mappedMethod
- the mapped method.attributes
- the current Attributes object.result
- the value returned by the invoked method.public void objectToResponse(Object result, WebResponse response, String mimeType)
objectToResponse
in interface IWebSerialDeserial
response
- The current response object.result
- The object to write to response.restMimeFormats
- The MIME type to use to serialize data@Deprecated protected void configureObjSerialDeserial(T objSerialDeserial)
onConfigure(T objSerialDeserial)
instead.
objSerialDeserial
- the object serializer/deserializerprotected void onInitialize(T objSerialDeserial)
objSerialDeserial
- the object serializer/deserializerpublic static Url extractUrlFromRequest()
public <T> T requestToObject(WebRequest request, Class<T> argClass, String mimeType)
requestToObject
in interface IWebSerialDeserial
argClass
- the type we want to extract from request body.request
- the request object.mimeType
- the MIME type of the request.
public static final WebRequest getCurrentWebRequest()
public static Object toObject(Class clazz, String value) throws IllegalArgumentException
clazz
- the type of the object we want to obtain.value
- the string value we want to convert.
IllegalArgumentException
public static final WebResponse getCurrentWebResponse()
public boolean isMimeTypeSupported(String mimeType)
IWebSerialDeserial
isMimeTypeSupported
in interface IWebSerialDeserial
mimeType
- the MIME type we want to check.
protected final void setResponseStatusCode(int statusCode)
statusCode
- the status code we want to set on the current response.protected Map<String,List<MethodMappingInfo>> getMappedMethods()
protected void registerValidator(String key, IValidator validator)
key
- the key to use to store the validator.validator
- the validator to registerprotected void unregisterValidator(String key)
key
- the key to use to remove the validator.protected IValidator getValidator(String key)
key
- the key to use to retrieve the validator.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |