Package org.actioncontroller
Class ApiControllerMethodAction
- java.lang.Object
-
- org.actioncontroller.ApiControllerMethodAction
-
- All Implemented Interfaces:
ApiControllerAction
public class ApiControllerMethodAction extends Object implements ApiControllerAction
Represents a single action that can be performed on a controller. An action is defined on the http-end as a http method and a path template, and on the Java-side as a method on the controller class. For example@Get("/helloWorld") public String hello(@RequestParam("greeter") String greeter)defines an action that responds toGET /helloWorld?greeter=somethingwith a string.
-
-
Field Summary
Fields Modifier and Type Field Description static PatternPATH_PARAM_PATTERN
-
Constructor Summary
Constructors Constructor Description ApiControllerMethodAction(String httpMethod, String pattern, Object controller, Method action, ApiControllerContext context)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidcalculatePathParams(ApiHttpExchange exchange)MethodgetAction()Returns the method that implements this actionObjectgetController()Returns the controller that this action belongs toStringgetHttpMethod()Returns the request HTTP Method used to match this actionStringgetMethodName()Pattern[]getParamRegexp()Returns an sparse array with the element of the path specification that are parameterizedStringgetPattern()Returns the request URL pattern used to match this actionString[]getPatternParts()Returns an array with each element of the path specificationprotected Optional<String>getRequiredUserRole()protected Objectinvoke(Object controller, Method action, Object[] arguments)Invoke the method on the controller with the given parameters and translate exceptions to http status codesvoidinvoke(UserContext userContext, ApiHttpExchange exchange)Invokes this action on the givenApiHttpExchangeby converting the exchange to method invocation arguments, invoking the method and converting the return value.booleanmatches(ApiControllerAction otherAction)Returns true if the actions respond to the same routesbooleanmatchesRequiredParameters(ApiHttpExchange exchange)Returns true if the exchange has all the required query parameters specified in this action, or if there are no required query parameters in the actionbooleanrequiresParameter()Returns true if the action requires a request parameter, such as@Get("/test?error").StringtoString()protected voidverifyUserAccess(ApiHttpExchange exchange, UserContext userContext)
-
-
-
Field Detail
-
PATH_PARAM_PATTERN
public static final Pattern PATH_PARAM_PATTERN
-
-
Constructor Detail
-
ApiControllerMethodAction
public ApiControllerMethodAction(String httpMethod, String pattern, Object controller, Method action, ApiControllerContext context)
-
-
Method Detail
-
getController
public Object getController()
Description copied from interface:ApiControllerActionReturns the controller that this action belongs to- Specified by:
getControllerin interfaceApiControllerAction
-
getAction
public Method getAction()
Description copied from interface:ApiControllerActionReturns the method that implements this action- Specified by:
getActionin interfaceApiControllerAction
-
getPattern
public String getPattern()
Description copied from interface:ApiControllerActionReturns the request URL pattern used to match this action- Specified by:
getPatternin interfaceApiControllerAction
-
getHttpMethod
public String getHttpMethod()
Description copied from interface:ApiControllerActionReturns the request HTTP Method used to match this action- Specified by:
getHttpMethodin interfaceApiControllerAction
-
requiresParameter
public boolean requiresParameter()
Description copied from interface:ApiControllerActionReturns true if the action requires a request parameter, such as@Get("/test?error"). When more than one action returns true fromApiControllerAction.matches(org.actioncontroller.ApiControllerAction)and exactly one action returns true from requiresParameter, that action is invokes. Otherwise action-controller throws an exception- Specified by:
requiresParameterin interfaceApiControllerAction
-
matchesRequiredParameters
public boolean matchesRequiredParameters(ApiHttpExchange exchange)
Description copied from interface:ApiControllerActionReturns true if the exchange has all the required query parameters specified in this action, or if there are no required query parameters in the action- Specified by:
matchesRequiredParametersin interfaceApiControllerAction
-
getPatternParts
public String[] getPatternParts()
Description copied from interface:ApiControllerActionReturns an array with each element of the path specification- Specified by:
getPatternPartsin interfaceApiControllerAction
-
getParamRegexp
public Pattern[] getParamRegexp()
Description copied from interface:ApiControllerActionReturns an sparse array with the element of the path specification that are parameterized- Specified by:
getParamRegexpin interfaceApiControllerAction
-
matches
public boolean matches(ApiControllerAction otherAction)
Description copied from interface:ApiControllerActionReturns true if the actions respond to the same routes- Specified by:
matchesin interfaceApiControllerAction
-
invoke
public void invoke(UserContext userContext, ApiHttpExchange exchange) throws IOException
Description copied from interface:ApiControllerActionInvokes this action on the givenApiHttpExchangeby converting the exchange to method invocation arguments, invoking the method and converting the return value.- Specified by:
invokein interfaceApiControllerAction- Throws:
IOException
-
calculatePathParams
protected void calculatePathParams(ApiHttpExchange exchange)
-
invoke
protected Object invoke(Object controller, Method action, Object[] arguments)
Invoke the method on the controller with the given parameters and translate exceptions to http status codes
-
verifyUserAccess
protected void verifyUserAccess(ApiHttpExchange exchange, UserContext userContext)
-
getMethodName
public String getMethodName()
- Specified by:
getMethodNamein interfaceApiControllerAction
-
-