private boolean canDebugRequest(final SlingHttpServletRequest request) { boolean canDebugRequest = false; final String path = request.getPathInfo(); if (isEnabled && path.contains(".html")) { canDebugRequest = true; } return canDebugRequest; }
public String getPagePath() { SlingHttpServletRequest request = (SlingHttpServletRequest) context.getBindings(ScriptContext.ENGINE_SCOPE).get(SlingBindings.REQUEST); String pathInfo = request.getPathInfo(); return pathInfo; }
protected void dumpRequestAsProperties(SlingHttpServletRequest request, SlingHttpServletResponse response) throws IOException { final Properties props = new Properties(); response.setContentType("text/plain"); props.put("servlet.class.name", getClass().getName()); final Resource r = request.getResource(); props.put("sling.resource.path", r == null ? "" : r.getPath()); props.put("sling.resource.type", r == null ? "" : r.getResourceType()); props.put("http.request.method", request.getMethod()); props.put("http.request.pathInfo", request.getPathInfo()); props.put("http.request.requestURI", request.getRequestURI()); props.put("http.request.requestURL", request.getRequestURL().toString()); setCustomProperties(props); props.store(response.getOutputStream(), "Data created by " + getClass().getName() + " at " + new Date()); response.getOutputStream().flush(); }
/** * Redirects the HttpServletResponse, if redirectURL is not empty * @param htmlResponse * @param request * @param response The HttpServletResponse to use for redirection * @return Whether a redirect was requested * @throws IOException */ boolean redirectIfNeeded(final SlingHttpServletRequest request, final PostResponse htmlResponse, final SlingHttpServletResponse response) throws IOException { final String redirectURL = getRedirectUrl(request, htmlResponse); if (redirectURL != null) { final Matcher m = REDIRECT_WITH_SCHEME_PATTERN.matcher(redirectURL); final boolean hasScheme = m.matches(); final String encodedURL; if (hasScheme && m.group(2).length() > 0) { encodedURL = m.group(1) + response.encodeRedirectURL(m.group(2)); } else if (hasScheme) { encodedURL = redirectURL; } else { log.debug("Request path is [{}]", request.getPathInfo()); encodedURL = response.encodeRedirectURL(redirectURL); } log.debug("redirecting to URL [{}] - encoded as [{}]", redirectURL, encodedURL); response.sendRedirect(encodedURL); return true; } return false; } private static final Pattern REDIRECT_WITH_SCHEME_PATTERN = Pattern.compile("^(https?://[^/]+)(.*)$");
final String requestPath = request.getPathInfo(); if (requestPath.endsWith(SlingPostConstants.DEFAULT_CREATE_SUFFIX) && buf.charAt(0) != '/' && !REDIRECT_WITH_SCHEME_PATTERN.matcher(buf).matches()) {
@Nullable private String getRedirectLocation(SlingHttpServletRequest request, long lastModifiedEpoch) { RequestPathInfo requestPathInfo = request.getRequestPathInfo(); if (request.getResource().isResourceType(IMAGE_RESOURCE_TYPE)) { return Joiner.on('.').join(Text.escapePath(request.getContextPath() + requestPathInfo.getResourcePath()), requestPathInfo.getSelectorString(), requestPathInfo.getExtension() + "/" + lastModifiedEpoch, requestPathInfo.getExtension()); } long lastModifiedSuffix = getRequestLastModifiedSuffix(request.getPathInfo()); String resourcePath = lastModifiedSuffix > 0 ? ResourceUtil.getParent(request.getPathInfo()) : request.getPathInfo(); String extension = FilenameUtils.getExtension(resourcePath); if (StringUtils.isNotEmpty(resourcePath)) { if (StringUtils.isNotEmpty(extension)) { resourcePath = resourcePath.substring(0, resourcePath.length() - extension.length() - 1); } return request.getContextPath() + Text.escapePath(resourcePath) + "/" + lastModifiedEpoch + "." + requestPathInfo.getExtension(); } return null; }
final String path = slingRequest.getPathInfo().toLowerCase(); final String host = slingRequest.getServerName(); final String method = slingRequest.getMethod();
/** * Returns the resource of the given request to be used as the basis for * error handling. If the resource has not yet been set in the request * because the error occurred before the resource could be set (e.g. during * resource resolution) a synthetic resource is returned whose type is * {@link ServletResolverConstants#ERROR_HANDLER_PATH}. * * @param request The request whose resource is to be returned. */ private Resource getErrorResource(final SlingHttpServletRequest request) { Resource res = request.getResource(); if (res == null) { res = new SyntheticResource(request.getResourceResolver(), request.getPathInfo(), DEFAULT_ERROR_HANDLER_RESOURCE_TYPE); } return res; }
/** * Add overrides for other SlingSafeMethodsServlet here (doGeneric, doHead, doOptions, doTrace) * */ @Override protected final void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException { // Implement custom handling of GET requests boolean responseIsText = true; if (responseIsText) { // Write a standard text/html response response.setContentType("text/html;charset=UTF-8"); response.setCharacterEncoding("UTF-8"); response.getWriter().write("<html><body>Text to write to response</body></html>"); } else { // Write some binary data to the response; Such as sending back an Image or PDF InputStream input = new InputStream() { @Override public int read() throws IOException { return 0; } }; response.setContentType(getServletContext().getMimeType(request.getPathInfo())); OutputStream output = response.getOutputStream(); byte[] buffer = new byte[FOUR_KB]; for (int length = 0; (length = input.read(buffer)) > 0;) { output.write(buffer, 0, length); output.flush(); } } }
final String path = slingRequest.getPathInfo().toLowerCase(); final String method = slingRequest.getMethod();
path = request.getPathInfo();
path = request.getPathInfo();