/** * Get the path to the next page. * * @return The path to the next page. */ public String getNextPath() { return request.getRequestURI() + PAGE_QUERYSTRING + (currentPage + 1); }
/** * Get the path to the previous page. * * @return The path to the previous page. */ public String getPreviousPath() { return request.getRequestURI() + PAGE_QUERYSTRING + (currentPage - 1); }
public boolean accepts(SlingHttpServletRequest request) { // Use a fake selector to opt in. Not really useful, this // is just a test of the opting mechanism. return request.getRequestURI().contains(".RequestUriOptingServlet.html"); } }
@Override protected void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response) throws IOException { response.sendRedirect(request.getRequestURI()); }
/** * Get the list of pages and their paths. * * The list includes the index, whether the page is the current page * and the path of the page. * * @return The list of pages and their paths. */ public List<HashMap<String, Object>> getPages() { List<HashMap<String, Object>> pages = new ArrayList<HashMap<String, Object>>(); String path = request.getRequestURI(); for (int x = 1; x <= totalPages; x++) { HashMap<String, Object> map = new HashMap<String, Object>(); map.put("page", x); map.put("path", path + PAGE_QUERYSTRING + x); map.put("current", Boolean.valueOf(x == currentPage)); pages.add(map); } return pages; } }
private boolean executeCacheContentDeliver(SlingHttpServletRequest request, SlingHttpServletResponse response, CacheContent cacheContent) throws HttpCacheDataStreamException { // Copy the cached data into the servlet output stream. try { serveCacheContentIntoResponse(response, cacheContent); if (log.isDebugEnabled()) { log.debug("Response delivered from cache for the url [ {} ]", request.getRequestURI()); } return true; } catch (IOException e) { throw new HttpCacheDataStreamException("Unable to copy from cached data to the servlet output stream."); } }
private String getRemoteAssets(SlingHttpServletRequest request) { try { CloseableHttpClient client = HttpClients.createDefault(); HttpGet get = new HttpGet( "http://localhost:4503/" + request.getRequestURI() + "?" + request.getQueryString()); get.addHeader("Cache-Control", "no-cache"); get.addHeader("Content-Type", "application/x-www-form-urlencoded"); logger.info("URL : " + get.getURI()); HttpResponse response = client.execute(get); if (response.getStatusLine().getStatusCode() != 200) { logger.info("response code {} ", response.getStatusLine().getStatusCode()); } String result = IOUtils.toString(response.getEntity().getContent()); result = StringUtils.replace(result, "/content/dam/", "http://localhost:4503/content/dam/"); logger.info("JSON Response : {}", result); return result; } catch (Exception e) { logger.error("Error in getRemoteAssets ", e); } return ""; }
protected boolean accepts(SlingHttpServletRequest request) { if (request.getAttribute(REQ_ATTR) != null) { // Cyclic loop log.warn("Identified a cyclic loop in the ACS Commons CQ Include Namespace prefix Servlet for [ {} ]", request.getRequestURI()); return false; } for (int i = 0; i <= NAME_PROPERTY_SELECTOR_INDEX; i++) { if (StringUtils.isBlank(PathInfoUtil.getSelector(request, i))) { // Missing necessary selectors; the first N - 1 should be redundant since the selectors are specified // in the Servlet registration return false; } } return true; }
protected boolean accepts(SlingHttpServletRequest request) { if (request.getAttribute(REQ_ATTR) != null) { // Cyclic loop log.warn("Identified a cyclic loop in the ACS Commons CQ Include Namespace prefix Servlet for [ {} ]", request.getRequestURI()); return false; } for (int i = 0; i <= NAME_PROPERTY_SELECTOR_INDEX; i++) { if (StringUtils.isBlank(PathInfoUtil.getSelector(request, i))) { // Missing necessary selectors; the first N - 1 should be redundant since the selectors are specified // in the Servlet registration return false; } } return true; }
public String getUrl() { SlingHttpServletRequest request = (SlingHttpServletRequest) context.getBindings(ScriptContext.ENGINE_SCOPE).get(SlingBindings.REQUEST); return request.getRequestURI(); }
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(); }
responseString.append("TRACE ").append(request.getRequestURI()); responseString.append(' ').append(request.getProtocol());
public AbstractCacheKey(SlingHttpServletRequest request, HttpCacheConfig cacheConfig) { this.authenticationRequirement = cacheConfig.getAuthenticationRequirement(); this.uri = request.getRequestURI(); this.resourcePath = request.getResource().getPath(); }
log.debug("Dispatch request {} to {}", request.getRequestURI(), url); log.error("Unable to dispatch proxy request for {} referrer={}", request.getRequestURI(), request.getHeader("Referrer")); throw new ServletException("No Content");
public boolean dispatch(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException, RepositoryException { if (request.getAttribute(VANITY_DISPATCH_CHECK_ATTR) != null) { log.trace("Processing a previously vanity dispatched request. Skipping..."); return false; } request.setAttribute(VANITY_DISPATCH_CHECK_ATTR, true); final String requestURI = request.getRequestURI(); final RequestPathInfo mappedPathInfo = new PathInfo(request.getResourceResolver(), requestURI); final String candidateVanity = mappedPathInfo.getResourcePath(); final String pathScope = StringUtils.removeEnd(requestURI, candidateVanity); log.debug("Candidate vanity URL to check and dispatch: [ {} ]", candidateVanity); // Check if... // 1) the candidateVanity and the requestURI are the same; If they are it means the request has already // gone through resource resolution and failed so there is no sense in sending it through again. // 2) the candidate is in at least 1 sling:vanityPath under /content if (!StringUtils.equals(candidateVanity, requestURI) && isVanityPath(pathScope, candidateVanity, request)) { log.debug("Forwarding request to vanity resource [ {} ]", candidateVanity); final RequestDispatcher requestDispatcher = request.getRequestDispatcher(candidateVanity); requestDispatcher.forward(new ExtensionlessRequestWrapper(request), response); return true; } return false; }
@Override public void cacheResponse(SlingHttpServletRequest request, SlingHttpServletResponse response, HttpCacheConfig cacheConfig) throws HttpCacheKeyCreationException, HttpCacheDataStreamException, HttpCachePersistenceException { // TODO - This can be made asynchronous to avoid performance penalty on response cache. CacheContent cacheContent = null; try { // Construct the cache content. HttpCacheServletResponseWrapper responseWrapper = null; if (response instanceof HttpCacheServletResponseWrapper) { responseWrapper = (HttpCacheServletResponseWrapper) response; } else { throw new AssertionError("Programming error."); } CacheKey cacheKey = cacheConfig.buildCacheKey(request); cacheContent = new CacheContent().build(responseWrapper); // Persist in cache. if (isRequestCachableAccordingToHandlingRules(request, response, cacheConfig, cacheContent)) { getCacheStore(cacheConfig).put(cacheKey, cacheContent); log.debug("Response for the URI cached - {}", request.getRequestURI()); } } finally { // Close the temp sink input stream. if (null != cacheContent) { IOUtils.closeQuietly(cacheContent.getInputDataStream()); } } }
protected final boolean accepts(final SlingHttpServletRequest request, final SlingHttpServletResponse response) { if (!StringUtils.endsWith(request.getRequestURI(), ".html") || !StringUtils.contains(response.getContentType(), "html")) { // Do not inject around non-HTML requests return false; } final ComponentContext componentContext = WCMUtils.getComponentContext(request); if (componentContext == null // ComponentContext is null || componentContext.getComponent() == null // Component is null || componentContext.isRoot()) { // Suppress on root context return false; } // Check to make sure the suppress key has not been added to the request if (this.isComponentErrorHandlingSuppressed(request)) { // Suppress key is detected, skip handling return false; } // Check to make sure the SlingRequest's resource isn't in the suppress list final SlingHttpServletRequest slingRequest = (SlingHttpServletRequest) request; for (final String suppressedResourceType : suppressedResourceTypes) { if (slingRequest.getResource().isResourceType(suppressedResourceType)) { return false; } } return true; }
protected final boolean accepts(final SlingHttpServletRequest request, final SlingHttpServletResponse response) { if (!StringUtils.endsWith(request.getRequestURI(), ".html") || !StringUtils.contains(response.getContentType(), "html")) {
public AbstractCacheKey(SlingHttpServletRequest request, HttpCacheConfig cacheConfig) { this.authenticationRequirement = cacheConfig.getAuthenticationRequirement(); this.uri = request.getRequestURI(); this.resourcePath = unmangle(request.getResource().getPath()); this.hierarchyResourcePath = makeHierarchyResourcePath(this.resourcePath); this.customExpiryTime = cacheConfig.getExpiryOnCreate(); this.expiryForAccessTime = cacheConfig.getExpiryOnCreate(); this.expiryForUpdateTime = cacheConfig.getExpiryForUpdate(); this.expiryForAccessTime = cacheConfig.getExpiryForAccess(); }
@Override protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException { response.setContentType("application/json"); response.setCharacterEncoding("UTF-8"); if (!this.accepts(request)) { response.setStatus(SlingHttpServletResponse.SC_NOT_FOUND); response.getWriter().write(new JSONObject().toString()); } /* Servlet accepts this request */ RequestUtil.setRequestAttribute(request, REQ_ATTR, true); final String namespace = URLDecoder.decode(PathInfoUtil.getSelector(request, NAME_PROPERTY_SELECTOR_INDEX), "UTF-8"); final RequestDispatcherOptions options = new RequestDispatcherOptions(); options.setReplaceSelectors(AEM_CQ_INCLUDE_SELECTORS); final BufferingResponse bufferingResponse = new BufferingResponse(response); request.getRequestDispatcher(request.getResource(), options).forward(request, bufferingResponse); try { final JSONObject json = new JSONObject(bufferingResponse.getContents()); final PropertyNamespaceUpdater propertyNamespaceUpdater = new PropertyNamespaceUpdater(namespace); propertyNamespaceUpdater.accept(json); response.getWriter().write(json.toString()); } catch (JSONException e) { log.error("Error composing the cqinclude JSON representation of the widget overlay for [ {} ]", request.getRequestURI(), e); response.setStatus(SlingHttpServletResponse.SC_INTERNAL_SERVER_ERROR); response.getWriter().write(new JSONObject().toString()); } }