@Test public void testExceptionHandling() throws IOException { SlingHttpServletResponse mockResponse = Mockito.mock(SlingHttpServletResponse.class); Mockito.when(request.getResource().getPath()).thenThrow(JSONException.class); servlet.doGet(request, mockResponse); verify(mockResponse).sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Unable to create JSON response"); }
protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws IOException { try { Resource resource = request.getResource(); String resourcePath = resource.getPath(); String configContainerPath = resourcePath.endsWith(Constants.COMMERCE_BUCKET_PATH) ? resourcePath.replace( "/" + Constants.COMMERCE_BUCKET_PATH, "") : resourcePath; Resource configContainerResource = request.getResourceResolver().getResource(configContainerPath); if (configContainerResource == null) { response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Unable to load configuration container resource"); return; } JSONObject config = ConfigInheritance.getInheritanceMap(configContainerResource, CONFIG_KEYS); response.setContentType("application/json"); response.getWriter().println(config.toString()); } catch (JSONException e) { LOGGER.error("Unable to retrieve config: {}", e.getMessage()); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Unable to create JSON response"); } }
ConfigurationInheritanceServlet extends SlingSafeMethodsServlet { protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws IOException { try { Resource resource = request.getResource(); String resourcePath = resource.getPath(); String configContainerPath = resourcePath.endsWith(Constants.COMMERCE_BUCKET_PATH) ? resourcePath.replace( "/" + Constants.COMMERCE_BUCKET_PATH, "") : resourcePath; Resource configContainerResource = request.getResourceResolver().getResource(configContainerPath); if (configContainerResource == null) { response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Unable to load configuration container resource"); return; } JSONObject config = ConfigInheritance.getInheritanceMap(configContainerResource, CONFIG_KEYS); response.setContentType("application/json"); response.getWriter().println(config.toString()); } catch (JSONException e) { LOGGER.error("Unable to retrieve config: {}", e.getMessage()); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Unable to create JSON response"); } } }
ConfigurationInheritanceServlet extends SlingSafeMethodsServlet { protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws IOException { try { Resource resource = request.getResource(); String resourcePath = resource.getPath(); String configContainerPath = resourcePath.endsWith(Constants.COMMERCE_BUCKET_PATH) ? resourcePath.replace( "/" + Constants.COMMERCE_BUCKET_PATH, "") : resourcePath; Resource configContainerResource = request.getResourceResolver().getResource(configContainerPath); if (configContainerResource == null) { response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Unable to load configuration container resource"); return; } JSONObject config = ConfigInheritance.getInheritanceMap(configContainerResource, CONFIG_KEYS); response.setContentType("application/json"); response.getWriter().println(config.toString()); } catch (JSONException e) { LOGGER.error("Unable to retrieve config: {}", e.getMessage()); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Unable to create JSON response"); } }  }
ConfigurationInheritanceServlet extends SlingSafeMethodsServlet { protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws IOException { try { Resource resource = request.getResource(); String resourcePath = resource.getPath(); String configContainerPath = resourcePath.endsWith(Constants.COMMERCE_BUCKET_PATH) ? resourcePath.replace( "/" + Constants.COMMERCE_BUCKET_PATH, "") : resourcePath; Resource configContainerResource = request.getResourceResolver().getResource(configContainerPath); if (configContainerResource == null) { response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Unable to load configuration container resource"); return; } JSONObject config = ConfigInheritance.getInheritanceMap(configContainerResource, CONFIG_KEYS); response.setContentType("application/json"); response.getWriter().println(config.toString()); } catch (JSONException e) { LOGGER.error("Unable to retrieve config: {}", e.getMessage()); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Unable to create JSON response"); } }   }
ConfigurationInheritanceServlet extends SlingSafeMethodsServlet { protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws IOException { try { Resource resource = request.getResource(); String resourcePath = resource.getPath(); String configContainerPath = resourcePath.endsWith(Constants.COMMERCE_BUCKET_PATH) ? resourcePath.replace( "/" + Constants.COMMERCE_BUCKET_PATH, "") : resourcePath; Resource configContainerResource = request.getResourceResolver().getResource(configContainerPath); if (configContainerResource == null) { response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Unable to load configuration container resource"); return; } JSONObject config = ConfigInheritance.getInheritanceMap(configContainerResource, CONFIG_KEYS); response.setContentType("application/json"); response.getWriter().println(config.toString()); } catch (JSONException e) { LOGGER.error("Unable to retrieve config: {}", e.getMessage()); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Unable to create JSON response"); } }    }