@Test public void testDoGetShouldReturnWithServiceListForEmptyServiceGet() throws ServletException, IOException { given(resp.getWriter()).willReturn(printWriter); given(req.getRequestURI()).willReturn("/public/services/"); given(req.getMethod()).willReturn("get"); given(serviceMap.getMapAsResponse()).willReturn("blah"); underTest.doGet(req, resp); verify(resp).setContentType("application/json"); verify(resp).setStatus(HttpServletResponse.SC_NOT_FOUND); String response = "blah"; verify(printWriter).write(response); verify(printWriter).flush(); verify(printWriter).close(); }
@Override protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { String requestUri = req.getRequestURI(); logger.info("Service call to: " + requestUri + ", method: " + req.getMethod()); int positionOfLeadingText = requestUri.indexOf(LEADING_TEXT); int requestedServicePosition = positionOfLeadingText + LEADING_TEXT.length(); String requestedService = positionOfLeadingText >= 0 ? requestUri.substring(requestedServicePosition) : ""; resp.setContentType("application/json"); resp.setStatus(HttpServletResponse.SC_NOT_FOUND); String response = null; if ("UniqueIdGenerator/uniqueId".equalsIgnoreCase(requestedService) && "get".equalsIgnoreCase(req.getMethod())) { response = getUniqueId(); resp.setStatus(HttpServletResponse.SC_OK); } if (response == null) { response = serviceMap.callExternalService(req, requestedService, resp); } if (response == null) { if (requestedService.length() > 0) { response = "{ \"unknownServiceCall\": \"" + req.getMethod() + " " + requestedService + "\" }"; } else { response = serviceMap.getMapAsResponse(); resp.setStatus(HttpServletResponse.SC_OK); } } PrintWriter out = resp.getWriter(); out.write(response); out.flush(); out.close(); }
ServiceServlet extends HttpServlet { @Override protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { String requestUri = req.getRequestURI(); logger.info("Service call to: " + requestUri + ", method: " + req.getMethod()); int positionOfLeadingText = requestUri.indexOf(LEADING_TEXT); int requestedServicePosition = positionOfLeadingText + LEADING_TEXT.length(); String requestedService = positionOfLeadingText >= 0 ? requestUri.substring(requestedServicePosition) : ""; resp.setContentType("application/json"); resp.setStatus(HttpServletResponse.SC_NOT_FOUND); String response = null; if ("UniqueIdGenerator/uniqueId".equalsIgnoreCase(requestedService) && "get".equalsIgnoreCase(req.getMethod())) { response = getUniqueId(); resp.setStatus(HttpServletResponse.SC_OK); } if (response == null) { response = serviceMap.callExternalService(req, requestedService, resp); } if (response == null) { if (requestedService.length() > 0) { response = "{ \"unknownServiceCall\": \"" + req.getMethod() + " " + requestedService + "\" }"; } else { response = serviceMap.getMapAsResponse(); resp.setStatus(HttpServletResponse.SC_OK); } } PrintWriter out = resp.getWriter(); out.write(response); out.flush(); out.close(); } }
ServiceServlet extends HttpServlet { @Override protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { String requestUri = req.getRequestURI(); logger.info("Service call to: " + requestUri + ", method: " + req.getMethod()); int positionOfLeadingText = requestUri.indexOf(LEADING_TEXT); int requestedServicePosition = positionOfLeadingText + LEADING_TEXT.length(); String requestedService = positionOfLeadingText >= 0 ? requestUri.substring(requestedServicePosition) : ""; resp.setContentType("application/json"); resp.setStatus(HttpServletResponse.SC_NOT_FOUND); String response = null; if ("UniqueIdGenerator/uniqueId".equalsIgnoreCase(requestedService) && "get".equalsIgnoreCase(req.getMethod())) { response = getUniqueId(); resp.setStatus(HttpServletResponse.SC_OK); } if (response == null) { response = serviceMap.callExternalService(req, requestedService, resp); } if (response == null) { if (requestedService.length() > 0) { response = "{ \"unknownServiceCall\": \"" + req.getMethod() + " " + requestedService + "\" }"; } else { response = serviceMap.getMapAsResponse(); resp.setStatus(HttpServletResponse.SC_OK); } } PrintWriter out = resp.getWriter(); out.write(response); out.flush(); out.close(); } @Autowired  ServiceServlet(ServiceMap serviceMap); }
ServiceServlet extends HttpServlet { @Override protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { String requestUri = req.getRequestURI(); logger.info("Service call to: " + requestUri + ", method: " + req.getMethod()); int positionOfLeadingText = requestUri.indexOf(LEADING_TEXT); int requestedServicePosition = positionOfLeadingText + LEADING_TEXT.length(); String requestedService = positionOfLeadingText >= 0 ? requestUri.substring(requestedServicePosition) : ""; resp.setContentType("application/json"); resp.setStatus(HttpServletResponse.SC_NOT_FOUND); String response = null; if ("UniqueIdGenerator/uniqueId".equalsIgnoreCase(requestedService) && "get".equalsIgnoreCase(req.getMethod())) { response = getUniqueId(); resp.setStatus(HttpServletResponse.SC_OK); } if (response == null) { response = serviceMap.callExternalService(req, requestedService, resp); } if (response == null) { if (requestedService.length() > 0) { response = "{ \"unknownServiceCall\": \"" + req.getMethod() + " " + requestedService + "\" }"; } else { response = serviceMap.getMapAsResponse(); resp.setStatus(HttpServletResponse.SC_OK); } } PrintWriter out = resp.getWriter(); out.write(response); out.flush(); out.close(); } @Autowired  ServiceServlet(ServiceMap serviceMap);  }
ServiceServlet extends HttpServlet { @Override protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { String requestUri = req.getRequestURI(); logger.info("Service call to: " + requestUri + ", method: " + req.getMethod()); int positionOfLeadingText = requestUri.indexOf(LEADING_TEXT); int requestedServicePosition = positionOfLeadingText + LEADING_TEXT.length(); String requestedService = positionOfLeadingText >= 0 ? requestUri.substring(requestedServicePosition) : ""; resp.setContentType("application/json"); resp.setStatus(HttpServletResponse.SC_NOT_FOUND); String response = null; if ("UniqueIdGenerator/uniqueId".equalsIgnoreCase(requestedService) && "get".equalsIgnoreCase(req.getMethod())) { response = getUniqueId(); resp.setStatus(HttpServletResponse.SC_OK); } if (response == null) { response = serviceMap.callExternalService(req, requestedService, resp); } if (response == null) { if (requestedService.length() > 0) { response = "{ \"unknownServiceCall\": \"" + req.getMethod() + " " + requestedService + "\" }"; } else { response = serviceMap.getMapAsResponse(); resp.setStatus(HttpServletResponse.SC_OK); } } PrintWriter out = resp.getWriter(); out.write(response); out.flush(); out.close(); } @Autowired  ServiceServlet(ServiceMap serviceMap);   }