Package org.apache.struts2.rest
Class RestActionMapper
java.lang.Object
org.apache.struts2.dispatcher.mapper.DefaultActionMapper
org.apache.struts2.rest.RestActionMapper
- All Implemented Interfaces:
ActionMapper
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.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/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.
The httpMethod interceptor checks the actual request method, not _method.
A handler used by a POST form must allow POST, even when _method routes it to
update or destroy. @HttpPut and @HttpDelete alone require
actual PUT and DELETE requests; add @HttpPost to also accept tunneled POST forms.
XML http-method restrictions must likewise allow the actual request method.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringprotected static final org.apache.logging.log4j.LoggerFields inherited from class org.apache.struts2.dispatcher.mapper.DefaultActionMapper
ACTION_PREFIX, allowedActionNames, allowedMethodNames, allowedNamespaceNames, allowSlashesInActionNames, alwaysSelectFullNamespace, container, defaultActionName, defaultMethodName, defaultNamespaceName, extensions, METHOD_PREFIX, prefixTrie -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetMapping(jakarta.servlet.http.HttpServletRequest request, ConfigurationManager configManager) Expose the ActionMapping for the current requestprotected booleanisDelete(jakarta.servlet.http.HttpServletRequest request) protected booleanisExpectContinue(jakarta.servlet.http.HttpServletRequest request) protected booleanisGet(jakarta.servlet.http.HttpServletRequest request) protected booleanisOptions(jakarta.servlet.http.HttpServletRequest request) protected booleanisPost(jakarta.servlet.http.HttpServletRequest request) protected booleanisPut(jakarta.servlet.http.HttpServletRequest request) protected voidparseNameAndNamespace(String uri, ActionMapping mapping, ConfigurationManager configManager) Parses the name and namespace from the uri.voidsetAllowDynamicMethodCalls(String allowDynamicMethodCalls) voidsetDeleteMethodName(String deleteMethodName) voidsetEditMethodName(String editMethodName) Deprecated, for removal: This API element is subject to removal in a future version.voidsetGetMethodName(String getMethodName) voidsetIdParameterName(String idParameterName) voidsetIndexMethodName(String indexMethodName) voidsetNewMethodName(String newMethodName) voidsetOptionsMethodName(String optionsMethodName) voidsetPostContinueMethodName(String postContinueMethodName) voidsetPostMethodName(String postMethodName) voidsetPutContinueMethodName(String putContinueMethodName) voidsetPutMethodName(String putMethodName) booleanWhether this mapper honours the extension lists declared on packages and actionsMethods inherited from class org.apache.struts2.dispatcher.mapper.DefaultActionMapper
addParameterAction, cleanupActionName, cleanupMethodName, cleanupNamespaceName, dropExtension, extractMethodName, getDefaultExtension, getMappingFromActionName, getUriFromActionMapping, handleDynamicMethod, handleExtension, handleName, handleNamespace, handleParams, handleSpecialParameters, isSlashesInActionNames, lookupExtension, parseActionName, setAllowActionPrefix, setAllowedActionNames, setAllowedMethodNames, setAllowedNamespaceNames, setAlwaysSelectFullNamespace, setContainer, setDefaultActionName, setDefaultMethodName, setDefaultNamespaceName, setExtensions, setSlashesInActionNames, stripDeclaredExtension
-
Field Details
-
LOG
protected static final org.apache.logging.log4j.Logger LOG -
HTTP_METHOD_PARAM
- See Also:
-
-
Constructor Details
-
RestActionMapper
public RestActionMapper()
-
-
Method Details
-
getIdParameterName
-
setIdParameterName
-
setIndexMethodName
-
setGetMethodName
-
setPostMethodName
-
setEditMethodName
Deprecated, for removal: This API element is subject to removal in a future version.since 7.5.0, has no effect on the mapper: the/editform names the method itself and the;editform is no longer recognised.RestWorkflowInterceptorstill reads the setting. To be removed in 8.0.0. -
setNewMethodName
-
setDeleteMethodName
-
setPutMethodName
-
setOptionsMethodName
-
setPostContinueMethodName
-
setPutContinueMethodName
-
setAllowDynamicMethodCalls
- Overrides:
setAllowDynamicMethodCallsin classDefaultActionMapper
-
supportsDeclaredExtensions
public boolean supportsDeclaredExtensions()Description copied from interface:ActionMapperWhether this mapper honours the extension lists declared on packages and actions- Specified by:
supportsDeclaredExtensionsin interfaceActionMapper- Overrides:
supportsDeclaredExtensionsin classDefaultActionMapper- Returns:
- true if declared extensions are applied when mapping a request
-
getMapping
public ActionMapping getMapping(jakarta.servlet.http.HttpServletRequest request, ConfigurationManager configManager) Description copied from interface:ActionMapperExpose the ActionMapping for the current request- Specified by:
getMappingin interfaceActionMapper- Overrides:
getMappingin classDefaultActionMapper- Parameters:
request- The servlet requestconfigManager- The current configuration manager- Returns:
- The appropriate action mapping or null if mapping cannot be determined
-
parseNameAndNamespace
protected void parseNameAndNamespace(String uri, ActionMapping mapping, 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:
parseNameAndNamespacein classDefaultActionMapper- Parameters:
uri- The urimapping- The action mapping to populateconfigManager- configuration manager
-
isGet
protected boolean isGet(jakarta.servlet.http.HttpServletRequest request) -
isPost
protected boolean isPost(jakarta.servlet.http.HttpServletRequest request) -
isPut
protected boolean isPut(jakarta.servlet.http.HttpServletRequest request) -
isDelete
protected boolean isDelete(jakarta.servlet.http.HttpServletRequest request) -
isOptions
protected boolean isOptions(jakarta.servlet.http.HttpServletRequest request) -
isExpectContinue
protected boolean isExpectContinue(jakarta.servlet.http.HttpServletRequest request)
-
/editform names the method itself and the;editform is no longer recognised.