org.apache.struts2.rest
Class RestActionMapper
java.lang.Object
org.apache.struts2.dispatcher.mapper.DefaultActionMapper
org.apache.struts2.rest.RestActionMapper
- All Implemented Interfaces:
- ActionMapper
public class RestActionMapper
- extends DefaultActionMapper
This Restful action mapper enforces Ruby-On-Rails Rest-style mappings. If the method
is not specified (via '!' or 'method:' prefix), the method is "guessed" at using
ReST-style conventions that examine the URL and the HTTP method. Special care has
been given to ensure this mapper works correctly with the codebehind plugin so that
XML configuration is unnecessary.
This mapper supports the following parameters:
struts.mapper.idParameterName
- If set, this value will be the name
of the parameter under which the id is stored. The id will then be removed
from the action name. Whether or not the method is specified, the mapper will
try to truncate the identifier from the url and store it as a parameter.
struts.mapper.indexMethodName
- The method name to call for a GET
request with no id parameter. Defaults to 'index'.
struts.mapper.getMethodName
- The method name to call for a GET
request with an id parameter. Defaults to 'show'.
struts.mapper.postMethodName
- The method name to call for a POST
request with no id parameter. Defaults to 'create'.
struts.mapper.putMethodName
- The method name to call for a PUT
request with an id parameter. Defaults to 'update'.
struts.mapper.deleteMethodName
- The method name to call for a DELETE
request with an id parameter. Defaults to 'destroy'.
struts.mapper.editMethodName
- The method name to call for a GET
request with an id parameter and the 'edit' view specified. Defaults to 'edit'.
struts.mapper.newMethodName
- The method name to call for a GET
request with no id parameter and the 'new' view specified. Defaults to 'editNew'.
The following URL's will invoke its methods:
GET: /movies => method="index"
GET: /movies/Thrillers => method="show", id="Thrillers"
GET: /movies/Thrillers;edit => method="edit", id="Thrillers"
GET: /movies/Thrillers/edit => method="edit", id="Thrillers"
GET: /movies/new => method="editNew"
POST: /movies => method="create"
PUT: /movies/Thrillers => method="update", id="Thrillers"
DELETE: /movies/Thrillers => method="destroy", id="Thrillers"
To simulate the HTTP methods PUT and DELETE, since they aren't supported by HTML,
the HTTP parameter "_method" will be used.
Methods inherited from class org.apache.struts2.dispatcher.mapper.DefaultActionMapper |
addParameterAction, dropExtension, dropExtension, getDefaultExtension, getMappingFromActionName, getUri, getUriFromActionMapping, handleSpecialParameters, isSlashesInActionNames, parseActionName, setAlwaysSelectFullNamespace, setContainer, setExtensions, setSlashesInActionNames |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
LOG
protected static final com.opensymphony.xwork2.util.logging.Logger LOG
HTTP_METHOD_PARAM
public static final String HTTP_METHOD_PARAM
- See Also:
- Constant Field Values
RestActionMapper
public RestActionMapper()
getIdParameterName
public String getIdParameterName()
setIdParameterName
public void setIdParameterName(String idParameterName)
setIndexMethodName
public void setIndexMethodName(String indexMethodName)
setGetMethodName
public void setGetMethodName(String getMethodName)
setPostMethodName
public void setPostMethodName(String postMethodName)
setEditMethodName
public void setEditMethodName(String editMethodName)
setNewMethodName
public void setNewMethodName(String newMethodName)
setDeleteMethodName
public void setDeleteMethodName(String deleteMethodName)
setPutMethodName
public void setPutMethodName(String putMethodName)
setOptionsMethodName
public void setOptionsMethodName(String optionsMethodName)
setPostContinueMethodName
public void setPostContinueMethodName(String postContinueMethodName)
setPutContinueMethodName
public void setPutContinueMethodName(String putContinueMethodName)
setAllowDynamicMethodCalls
public void setAllowDynamicMethodCalls(String allowDynamicMethodCalls)
- Overrides:
setAllowDynamicMethodCalls
in class DefaultActionMapper
getMapping
public ActionMapping getMapping(javax.servlet.http.HttpServletRequest request,
com.opensymphony.xwork2.config.ConfigurationManager configManager)
- Specified by:
getMapping
in interface ActionMapper
- Overrides:
getMapping
in class DefaultActionMapper
parseNameAndNamespace
protected void parseNameAndNamespace(String uri,
ActionMapping mapping,
com.opensymphony.xwork2.config.ConfigurationManager configManager)
- Parses the name and namespace from the uri. Uses the configured package
namespaces to determine the name and id parameter, to be parsed later.
- Overrides:
parseNameAndNamespace
in class DefaultActionMapper
- Parameters:
uri
- The urimapping
- The action mapping to populate
isGet
protected boolean isGet(javax.servlet.http.HttpServletRequest request)
isPost
protected boolean isPost(javax.servlet.http.HttpServletRequest request)
isPut
protected boolean isPut(javax.servlet.http.HttpServletRequest request)
isDelete
protected boolean isDelete(javax.servlet.http.HttpServletRequest request)
isOptions
protected boolean isOptions(javax.servlet.http.HttpServletRequest request)
isExpectContinue
protected boolean isExpectContinue(javax.servlet.http.HttpServletRequest request)
Copyright © 2000-2012 Apache Software Foundation. All Rights Reserved.