public abstract class AbstractRestResource<T extends IWebSerialDeserial> extends Object implements org.apache.wicket.request.resource.IResource
Modifier and Type | Field and Description |
---|---|
static String |
NO_SUITABLE_METHOD_FOUND |
static String |
USER_IS_NOT_ALLOWED |
Constructor and Description |
---|
AbstractRestResource(T serialDeserial)
Constructor with no role-checker (i.e we don't use annotation
AuthorizeInvocation ). |
AbstractRestResource(T serialDeserial,
org.apache.wicket.authroles.authorization.strategies.role.IRoleCheckingStrategy roleCheckingStrategy)
Main constructor that takes in input the object serializer/deserializer and the role-checking
strategy to use.
|
Modifier and Type | Method and Description |
---|---|
static org.apache.wicket.request.Url |
extractUrlFromRequest()
Utility method to extract the client URL from the current request.
|
static org.apache.wicket.request.http.WebRequest |
getCurrentWebRequest()
Utility method to retrieve the current web request.
|
static org.apache.wicket.request.http.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.
|
Map<Method,MethodMappingInfo> |
getMappedMethodsInfo() |
MethodMappingInfo |
getMethodInfo(Method method) |
protected <E> org.apache.wicket.validation.IValidator<E> |
getValidator(String key,
E validatorType)
Retrieve a registered validator.
|
protected void |
handleException(org.apache.wicket.request.http.WebResponse response,
Exception exception)
Handle Exception.
|
void |
noSuitableMethodFound(org.apache.wicket.request.http.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,
org.apache.wicket.request.http.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,
org.apache.wicket.request.resource.IResource.Attributes attributes,
Object result)
Invoked just after a mapped method has been invoked to serve the current request.
|
protected void |
onBeforeMethodInvoked(MethodMappingInfo mappedMethod,
org.apache.wicket.request.resource.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,
org.apache.wicket.validation.IValidator<?> validator)
Register a Wicket validator for the current resource.
|
<E> E |
requestToObject(org.apache.wicket.request.http.WebRequest request,
Class<E> argClass,
String mimeType)
Internal method that tries to extract an instance of the given class from the request body.
|
void |
respond(org.apache.wicket.request.resource.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.
|
public static final String NO_SUITABLE_METHOD_FOUND
public static final String USER_IS_NOT_ALLOWED
public AbstractRestResource(T serialDeserial)
AuthorizeInvocation
).serialDeserial
- General class that is used to serialize/desiarilze objects to string.public AbstractRestResource(T serialDeserial, org.apache.wicket.authroles.authorization.strategies.role.IRoleCheckingStrategy roleCheckingStrategy)
serialDeserial
- General class that is used to serialize/desiarilze objects to stringroleCheckingStrategy
- the role-checking strategy.public final void respond(org.apache.wicket.request.resource.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 org.apache.wicket.request.resource.IResource
attributes
- the Attribute object of the current requestpublic void noSuitableMethodFound(org.apache.wicket.request.http.WebResponse response, HttpMethod httpMethod)
response
- the current response objecthttpMethod
- the HTTP method of the current requestprotected void onBeforeMethodInvoked(MethodMappingInfo mappedMethod, org.apache.wicket.request.resource.IResource.Attributes attributes)
mappedMethod
- the mapped method.attributes
- the current Attributes object.protected void onAfterMethodInvoked(MethodMappingInfo mappedMethod, org.apache.wicket.request.resource.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, org.apache.wicket.request.http.WebResponse response, String mimeType)
response
- The current response object.result
- The object to write to response.restMimeFormats
- The MIME type to use to serialize dataprotected void onInitialize(T objSerialDeserial)
objSerialDeserial
- the object serializer/deserializerprotected void handleException(org.apache.wicket.request.http.WebResponse response, Exception exception)
exception
- The Exceptionresponse
- Response-Objectpublic static org.apache.wicket.request.Url extractUrlFromRequest()
public <E> E requestToObject(org.apache.wicket.request.http.WebRequest request, Class<E> argClass, String mimeType)
argClass
- the type we want to extract from request body.public static final org.apache.wicket.request.http.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 org.apache.wicket.request.http.WebResponse getCurrentWebResponse()
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 final void registerValidator(String key, org.apache.wicket.validation.IValidator<?> validator)
key
- the key to use to store the validator.validator
- the validator to registerprotected final void unregisterValidator(String key)
key
- the key to use to remove the validator.protected final <E> org.apache.wicket.validation.IValidator<E> getValidator(String key, E validatorType)
key
- the key to use to retrieve the validator.public Map<Method,MethodMappingInfo> getMappedMethodsInfo()
public MethodMappingInfo getMethodInfo(Method method)
Copyright © 2015. All rights reserved.