@Test public void shouldPostJson() throws IOException { when(requestMock.getMethod()).thenReturn("POST"); when(requestMock.getPathInfo()).thenReturn("/postMethod"); JsonObject requestObject = new JsonObject() .put("foo", "bar") .put("list", Arrays.asList("a", "b", "c")); when(requestMock.getReader()) .thenReturn(new BufferedReader(new StringReader(requestObject.toIndentedJson(" ")))); servlet.service(requestMock, responseMock); assertThat(postedBody).isEqualTo(requestObject); }
@Override protected void service(HttpServletRequest req, HttpServletResponse resp) throws IOException { try ( MDC.MDCCloseable ignored = MDC.putCloseable("clientIp", req.getRemoteAddr()); MDC.MDCCloseable ignored2 = MDC.putCloseable("requestPath", req.getContextPath() + req.getServletPath() + req.getPathInfo()) ) { controllerException.verifyNoExceptions(); invokeAction(new ServletHttpExchange(req, resp)); } }
ApiServlet extends HttpServlet implements UserContext { @Override protected void service(HttpServletRequest req, HttpServletResponse resp) throws IOException { try ( MDC.MDCCloseable ignored = MDC.putCloseable("clientIp", req.getRemoteAddr()); MDC.MDCCloseable ignored2 = MDC.putCloseable("requestPath", req.getContextPath() + req.getServletPath() + req.getPathInfo()) ) { controllerException.verifyNoExceptions(); invokeAction(new ServletHttpExchange(req, resp)); } } }
ApiServlet extends HttpServlet implements UserContext { @Override protected void service(HttpServletRequest req, HttpServletResponse resp) throws IOException { try ( MDC.MDCCloseable ignored = MDC.putCloseable("clientIp", req.getRemoteAddr()); MDC.MDCCloseable ignored2 = MDC.putCloseable("requestPath", req.getContextPath() + req.getServletPath() + req.getPathInfo()) ) { controllerException.verifyNoExceptions(); invokeAction(new ServletHttpExchange(req, resp)); } } ApiServlet();  ApiServlet(Object controller); }
ApiServlet extends HttpServlet implements UserContext { @Override protected void service(HttpServletRequest req, HttpServletResponse resp) throws IOException { try ( MDC.MDCCloseable ignored = MDC.putCloseable("clientIp", req.getRemoteAddr()); MDC.MDCCloseable ignored2 = MDC.putCloseable("requestPath", req.getContextPath() + req.getServletPath() + req.getPathInfo()) ) { controllerException.verifyNoExceptions(); invokeAction(new ServletHttpExchange(req, resp)); } } ApiServlet();  ApiServlet(Object controller); ApiControllerContext getContext(); @Override boolean isUserLoggedIn(ApiHttpExchange exchange); @Override boolean isUserInRole(ApiHttpExchange exchange, String role); void registerController(Object controller); void registerControllers(Object... controllers); void registerControllerList(List<Object> controllers); @Override void init(ServletConfig config); void registerMBeans(); void registerMBeans(MBeanServer mBeanServer); @Override TimerRegistry getTimerRegistry(); void setTimerRegistry(TimerRegistry timerRegistry); }
ApiServlet extends HttpServlet implements UserContext { @Override protected void service(HttpServletRequest req, HttpServletResponse resp) throws IOException { try ( MDC.MDCCloseable ignored = MDC.putCloseable("clientIp", req.getRemoteAddr()); MDC.MDCCloseable ignored2 = MDC.putCloseable("requestPath", req.getContextPath() + req.getServletPath() + req.getPathInfo()) ) { controllerException.verifyNoExceptions(); invokeAction(new ServletHttpExchange(req, resp)); } } ApiServlet();  ApiServlet(Object controller); ApiControllerContext getContext(); @Override boolean isUserLoggedIn(ApiHttpExchange exchange); @Override boolean isUserInRole(ApiHttpExchange exchange, String role); void registerController(Object controller); void registerControllers(Object... controllers); void registerControllerList(List<Object> controllers); @Override void init(ServletConfig config); void registerMBeans(); void registerMBeans(MBeanServer mBeanServer); @Override TimerRegistry getTimerRegistry(); void setTimerRegistry(TimerRegistry timerRegistry);  }