@Test public void testStopNullService() throws Exception { request.addParameter("service", "stop"); request.addParameter("preferences", mapper.writeValueAsString(new Preferences())); doReturn(null).when(registry).getLogger(Matchers.<User>any()); servlet.handleRequest(request, response); assertEquals(HttpServletResponse.SC_NOT_FOUND, response.getStatus()); }
public void handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { if(request.getParameter(SERVICE_PARAMETER) == null) { response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Request Parameter 'service' is required."); return; } User user = getRegistry().createOrGetUser(new PirasoHttpServletRequest(request)); if(SERVICE_GET_REGISTRY_PARAMETER_VALUE.equals(request.getParameter(SERVICE_PARAMETER))) { retrieveRegistry(response); } else if(SERVICE_LOG_PARAMETER_VALUE.equals(request.getParameter(SERVICE_PARAMETER))) { log(request); writeResponse(response, PLAIN_CONTENT_TYPE, "OK"); } else if(SERVICE_REQUEST_ID_PARAMETER_VALUE.equals(request.getParameter(SERVICE_PARAMETER))) { writeResponse(response, PLAIN_CONTENT_TYPE, String.valueOf(PirasoContextIDGenerator.INSTANCE.next())); } else if(SERVICE_START_PARAMETER_VALUE.equals(request.getParameter(SERVICE_PARAMETER))) { startLoggerService(request, response, user); } else if(SERVICE_STOP_PARAMETER_VALUE.equals(request.getParameter(SERVICE_PARAMETER))) { stopService(response, user); writeResponse(response, PLAIN_CONTENT_TYPE, "OK"); } else if(SERVICE_TEST_PARAMETER_VALUE.equals(request.getParameter(SERVICE_PARAMETER))) { writeResponse(response, JSON_CONTENT_TYPE, String.format("{\"status\":\"%s\", \"version\":\"%s\", \"bridgeSupported\": true}", STATUS_OK, version)); } else { response.sendError(HttpServletResponse.SC_BAD_REQUEST, String.format("Request Parameter 'service' with value '%s' is invalid.", request.getParameter(SERVICE_PARAMETER))); } }
PirasoServlet implements HttpRequestHandler { public void handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { if(request.getParameter(SERVICE_PARAMETER) == null) { response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Request Parameter 'service' is required."); return; } User user = getRegistry().createOrGetUser(new PirasoHttpServletRequest(request)); if(SERVICE_GET_REGISTRY_PARAMETER_VALUE.equals(request.getParameter(SERVICE_PARAMETER))) { retrieveRegistry(response); } else if(SERVICE_LOG_PARAMETER_VALUE.equals(request.getParameter(SERVICE_PARAMETER))) { log(request); writeResponse(response, PLAIN_CONTENT_TYPE, "OK"); } else if(SERVICE_REQUEST_ID_PARAMETER_VALUE.equals(request.getParameter(SERVICE_PARAMETER))) { writeResponse(response, PLAIN_CONTENT_TYPE, String.valueOf(PirasoContextIDGenerator.INSTANCE.next())); } else if(SERVICE_START_PARAMETER_VALUE.equals(request.getParameter(SERVICE_PARAMETER))) { startLoggerService(request, response, user); } else if(SERVICE_STOP_PARAMETER_VALUE.equals(request.getParameter(SERVICE_PARAMETER))) { stopService(response, user); writeResponse(response, PLAIN_CONTENT_TYPE, "OK"); } else if(SERVICE_TEST_PARAMETER_VALUE.equals(request.getParameter(SERVICE_PARAMETER))) { writeResponse(response, JSON_CONTENT_TYPE, String.format("{\"status\":\"%s\", \"version\":\"%s\", \"bridgeSupported\": true}", STATUS_OK, version)); } else { response.sendError(HttpServletResponse.SC_BAD_REQUEST, String.format("Request Parameter 'service' with value '%s' is invalid.", request.getParameter(SERVICE_PARAMETER))); } } }
PirasoServlet implements HttpRequestHandler { public void handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { if(request.getParameter(SERVICE_PARAMETER) == null) { response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Request Parameter 'service' is required."); return; } User user = getRegistry().createOrGetUser(new PirasoHttpServletRequest(request)); if(SERVICE_GET_REGISTRY_PARAMETER_VALUE.equals(request.getParameter(SERVICE_PARAMETER))) { retrieveRegistry(response); } else if(SERVICE_LOG_PARAMETER_VALUE.equals(request.getParameter(SERVICE_PARAMETER))) { log(request); writeResponse(response, PLAIN_CONTENT_TYPE, "OK"); } else if(SERVICE_REQUEST_ID_PARAMETER_VALUE.equals(request.getParameter(SERVICE_PARAMETER))) { writeResponse(response, PLAIN_CONTENT_TYPE, String.valueOf(PirasoContextIDGenerator.INSTANCE.next())); } else if(SERVICE_START_PARAMETER_VALUE.equals(request.getParameter(SERVICE_PARAMETER))) { startLoggerService(request, response, user); } else if(SERVICE_STOP_PARAMETER_VALUE.equals(request.getParameter(SERVICE_PARAMETER))) { stopService(response, user); writeResponse(response, PLAIN_CONTENT_TYPE, "OK"); } else if(SERVICE_TEST_PARAMETER_VALUE.equals(request.getParameter(SERVICE_PARAMETER))) { writeResponse(response, JSON_CONTENT_TYPE, String.format("{\"status\":\"%s\", \"version\":\"%s\", \"bridgeSupported\": true}", STATUS_OK, version)); } else { response.sendError(HttpServletResponse.SC_BAD_REQUEST, String.format("Request Parameter 'service' with value '%s' is invalid.", request.getParameter(SERVICE_PARAMETER))); } }  }
PirasoServlet implements HttpRequestHandler { public void handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { if(request.getParameter(SERVICE_PARAMETER) == null) { response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Request Parameter 'service' is required."); return; } User user = getRegistry().createOrGetUser(new PirasoHttpServletRequest(request)); if(SERVICE_GET_REGISTRY_PARAMETER_VALUE.equals(request.getParameter(SERVICE_PARAMETER))) { retrieveRegistry(response); } else if(SERVICE_LOG_PARAMETER_VALUE.equals(request.getParameter(SERVICE_PARAMETER))) { log(request); writeResponse(response, PLAIN_CONTENT_TYPE, "OK"); } else if(SERVICE_REQUEST_ID_PARAMETER_VALUE.equals(request.getParameter(SERVICE_PARAMETER))) { writeResponse(response, PLAIN_CONTENT_TYPE, String.valueOf(PirasoContextIDGenerator.INSTANCE.next())); } else if(SERVICE_START_PARAMETER_VALUE.equals(request.getParameter(SERVICE_PARAMETER))) { startLoggerService(request, response, user); } else if(SERVICE_STOP_PARAMETER_VALUE.equals(request.getParameter(SERVICE_PARAMETER))) { stopService(response, user); writeResponse(response, PLAIN_CONTENT_TYPE, "OK"); } else if(SERVICE_TEST_PARAMETER_VALUE.equals(request.getParameter(SERVICE_PARAMETER))) { writeResponse(response, JSON_CONTENT_TYPE, String.format("{\"status\":\"%s\", \"version\":\"%s\", \"bridgeSupported\": true}", STATUS_OK, version)); } else { response.sendError(HttpServletResponse.SC_BAD_REQUEST, String.format("Request Parameter 'service' with value '%s' is invalid.", request.getParameter(SERVICE_PARAMETER))); } }  void setVersion(String version); void setMaxIdleTimeout(Long maxIdleTimeout); void setMaxQueueForceKillSize(Integer maxQueueForceKillSize); void setStopTimeout(Long stopTimeout); UserRegistry getRegistry(); void handleRequest(HttpServletRequest request, HttpServletResponse response); }
PirasoServlet implements HttpRequestHandler { public void handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { if(request.getParameter(SERVICE_PARAMETER) == null) { response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Request Parameter 'service' is required."); return; } User user = getRegistry().createOrGetUser(new PirasoHttpServletRequest(request)); if(SERVICE_GET_REGISTRY_PARAMETER_VALUE.equals(request.getParameter(SERVICE_PARAMETER))) { retrieveRegistry(response); } else if(SERVICE_LOG_PARAMETER_VALUE.equals(request.getParameter(SERVICE_PARAMETER))) { log(request); writeResponse(response, PLAIN_CONTENT_TYPE, "OK"); } else if(SERVICE_REQUEST_ID_PARAMETER_VALUE.equals(request.getParameter(SERVICE_PARAMETER))) { writeResponse(response, PLAIN_CONTENT_TYPE, String.valueOf(PirasoContextIDGenerator.INSTANCE.next())); } else if(SERVICE_START_PARAMETER_VALUE.equals(request.getParameter(SERVICE_PARAMETER))) { startLoggerService(request, response, user); } else if(SERVICE_STOP_PARAMETER_VALUE.equals(request.getParameter(SERVICE_PARAMETER))) { stopService(response, user); writeResponse(response, PLAIN_CONTENT_TYPE, "OK"); } else if(SERVICE_TEST_PARAMETER_VALUE.equals(request.getParameter(SERVICE_PARAMETER))) { writeResponse(response, JSON_CONTENT_TYPE, String.format("{\"status\":\"%s\", \"version\":\"%s\", \"bridgeSupported\": true}", STATUS_OK, version)); } else { response.sendError(HttpServletResponse.SC_BAD_REQUEST, String.format("Request Parameter 'service' with value '%s' is invalid.", request.getParameter(SERVICE_PARAMETER))); } }  void setVersion(String version); void setMaxIdleTimeout(Long maxIdleTimeout); void setMaxQueueForceKillSize(Integer maxQueueForceKillSize); void setStopTimeout(Long stopTimeout); UserRegistry getRegistry(); void handleRequest(HttpServletRequest request, HttpServletResponse response); static final long DEFAULT_STOP_TIMEOUT; }