}
@Override
protected void service(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException {
final String url = request.getParameter(PARAMETER_URL);
final RequestPathInfo requestPathInfo = new DecomposedURL(url).getRequestPathInfo();
String method = request.getParameter(PARAMETER_METHOD);
if (StringUtils.isBlank(method)) {
method = "GET";
}
final String CONSOLE_PATH_WARNING =
"<em>"
+ "Note that in a real Sling request, the path might vary depending on the existence of"
+ " resources that partially match it."
+ "<br/>This utility does not take this into account and uses the first dot to split"
+ " between path and selectors/extension."
+ "<br/>As a workaround, you can replace dots with underline characters, for example, when testing such an URL."
+ "</em>";
ResourceResolver resourceResolver = null;
try {
resourceResolver = resourceResolverFactory.getAdministrativeResourceResolver(null);
final PrintWriter pw = response.getWriter();
pw.print("<form method='get'>");
pw.println("<table class='content' cellpadding='0' cellspacing='0' width='100%'>");
titleHtml(
pw,
"Servlet Resolver Test",
"To check which servlet is responsible for rendering a response, enter a request path into " +
"the field and click 'Resolve' to resolve it.");
tr(pw);
tdLabel(pw, "URL");
tdContent(pw);
pw.print("<input type='text' name='");
pw.print(PARAMETER_URL);
pw.print("' value='");
if ( url != null ) {
pw.print(ResponseUtil.escapeXml(url));
}
pw.println("' class='input' size='50'>");
closeTd(pw);
closeTr(pw);
closeTr(pw);
tr(pw);
tdLabel(pw, "Method");
tdContent(pw);
pw.print("<select name='");
pw.print(PARAMETER_METHOD);
pw.println("'>");
pw.println("<option value='GET'>GET</option>");
pw.println("<option value='POST'>POST</option>");
pw.println("</select>");
pw.println(" <input type='submit' value='Resolve' class='submit'>");
closeTd(pw);
closeTr(pw);
if (StringUtils.isNotBlank(url)) {
tr(pw);
tdLabel(pw, "Decomposed URL");
tdContent(pw);
pw.println("<dl>");
pw.println("<dt>Path</dt>");
pw.print("<dd>");
pw.print(ResponseUtil.escapeXml(requestPathInfo.getResourcePath()));
pw.print("<br/>");
pw.print(CONSOLE_PATH_WARNING);
pw.println("</dd>");
pw.println("<dt>Selectors</dt>");
pw.print("<dd>");
if (requestPathInfo.getSelectors().length == 0) {
pw.print("<none>");
} else {
pw.print("[");
pw.print(ResponseUtil.escapeXml(StringUtils.join(requestPathInfo.getSelectors(), ", ")));
pw.print("]");
}
pw.println("</dd>");
pw.println("<dt>Extension</dt>");
pw.print("<dd>");
pw.print(ResponseUtil.escapeXml(requestPathInfo.getExtension()));
pw.println("</dd>");
pw.println("</dl>");
pw.println("</dd>");
pw.println("<dt>Suffix</dt>");
pw.print("<dd>");
pw.print(ResponseUtil.escapeXml(requestPathInfo.getSuffix()));
pw.println("</dd>");
pw.println("</dl>");
closeTd(pw);
closeTr(pw);
}
if (StringUtils.isNotBlank(requestPathInfo.getResourcePath())) {
final Collection<Resource> servlets;
Resource resource = resourceResolver.resolve(requestPathInfo.getResourcePath());
if (resource.adaptTo(Servlet.class) != null) {
servlets = Collections.singleton(resource);
} else {
final ResourceCollector locationUtil = ResourceCollector.create(
resource,
requestPathInfo.getExtension(),
executionPaths,
defaultExtensions,
method,
requestPathInfo.getSelectors());
servlets = locationUtil.getServlets(resourceResolver);
}
tr(pw);
tdLabel(pw, " ");
tdContent(pw);