Package org.actioncontroller.servlet
Class ApiServlet
- java.lang.Object
-
- javax.servlet.GenericServlet
-
- javax.servlet.http.HttpServlet
-
- org.actioncontroller.servlet.ApiServlet
-
- All Implemented Interfaces:
Serializable,javax.servlet.Servlet,javax.servlet.ServletConfig,UserContext
public class ApiServlet extends javax.servlet.http.HttpServlet implements UserContext
Subclass ApiServlet and implementinitby callingregisterControllerwith all your controller classes. Example controller class:public class MyApiController { @Get("/v1/api/objects") @JsonBody public List<SomePojo> listObjects( @RequestParam("query") Optional<String> query, @RequestParam("maxHits") Optional<Integer> maxHits ) { // ... this is up to you } @Get("/v1/api/objects/:id") @JsonBody public SomePojo getObject(@PathParam("id") UUID id) { // ... this is up to you } @Post("/v1/api/objects/") @SendRedirect public String postData( @JsonBody SomePojo myPojo, @SessionParameter("user") Optional<User> user ) { // ... do your thing return "/home/"; } }- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description ApiServlet()ApiServlet(Object controller)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ApiControllerContextgetContext()TimerRegistrygetTimerRegistry()voidinit(javax.servlet.ServletConfig config)voidregisterController(Object controller)voidregisterControllerList(List<Object> controllers)voidregisterControllers(Object... controllers)voidregisterMBeans()voidregisterMBeans(MBeanServer mBeanServer)protected voidservice(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp)voidsetTimerRegistry(TimerRegistry timerRegistry)This method lets you plug in metrics for measuring which actions are executed and how long they take.protected voidsetupActions()-
Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doGet, doHead, doOptions, doPost, doPut, doTrace, getLastModified, service
-
-
-
-
Constructor Detail
-
ApiServlet
public ApiServlet()
-
ApiServlet
public ApiServlet(Object controller)
-
-
Method Detail
-
getContext
public ApiControllerContext getContext()
-
service
protected void service(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) throws IOException- Overrides:
servicein classjavax.servlet.http.HttpServlet- Throws:
IOException
-
registerController
public void registerController(Object controller)
-
registerControllers
public void registerControllers(Object... controllers)
-
init
public void init(javax.servlet.ServletConfig config) throws javax.servlet.ServletException- Specified by:
initin interfacejavax.servlet.Servlet- Overrides:
initin classjavax.servlet.GenericServlet- Throws:
javax.servlet.ServletException
-
setupActions
protected void setupActions()
-
registerMBeans
public void registerMBeans()
-
registerMBeans
public void registerMBeans(MBeanServer mBeanServer)
-
getTimerRegistry
public TimerRegistry getTimerRegistry()
- Specified by:
getTimerRegistryin interfaceUserContext
-
setTimerRegistry
public void setTimerRegistry(TimerRegistry timerRegistry)
This method lets you plug in metrics for measuring which actions are executed and how long they take. SeeTimerRegistry
-
-