@Override public boolean onRequestReceive(SlingHttpServletRequest request) { // Return true only if Http method is GET. return HTTP_GET_METHOD.equals(request.getMethod()); } }
@Override public boolean onRequestReceive(SlingHttpServletRequest request) { // Return true only if Http method is GET. return HTTP_GET_METHOD.equals(request.getMethod()); } }
@Override protected boolean mayService(@Nonnull SlingHttpServletRequest request, @Nonnull SlingHttpServletResponse response) throws ServletException, IOException { if (super.mayService(request, response)) { return true; } if ("PATCH".equals(request.getMethod())) { doPatch(request, response); return true; } return false; }
@Override protected final boolean doHandleGet(final String formName, final SlingHttpServletRequest request) { //noinspection SimplifiableIfStatement if (StringUtils.equalsIgnoreCase("GET", request.getMethod())) { return (CookieUtil.getCookie(request, this.getGetLookupKey(formName)) != null); } else { return false; } }
/** * Checks if this Form Manager should handle this request as a GET request. * * @param formName * @param request * @return */ protected boolean doHandleGet(final String formName, final SlingHttpServletRequest request) { //noinspection SimplifiableIfStatement if (StringUtils.equalsIgnoreCase("GET", request.getMethod())) { return (StringUtils.isNotBlank(request.getParameter(this.getGetLookupKey(formName)))); } else { return false; } }
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { SlingHttpServletRequest servletRequest = (SlingHttpServletRequest) request; // only intercept POST requests if (METHOD_POST.equalsIgnoreCase(servletRequest.getMethod())) { String name = request.getParameter(NAME); String type = request.getParameter(TYPE); if (type != null && name != null) { String filter = format(FACTORY_FILTER_PATTERN, name, type); try { ServiceReference[] services = context.getAllServiceReferences(DistributionAgent.class.getName(), filter); if (services != null && services.length > 0) { String errorMessage = format("An agent named '%s' of different type than '%s' was already previously registered, please change the Agent name.", name, type); ((HttpServletResponse) response).sendError(SC_CONFLICT, errorMessage); return; } } catch (InvalidSyntaxException e) { // should not happen... log.error("Impossible to access to {} references", DistributionAgent.class.getName(), e); } } } chain.doFilter(request, response); }
/** * Determines of this FormHelper should handle the POST request. * * @param formName * @param request * @return */ protected final boolean doHandlePost(final String formName, final SlingHttpServletRequest request) { if (StringUtils.equalsIgnoreCase("POST", request.getMethod())) { // Form should have a hidden input with the name this.getLookupKey(..) and value formName return StringUtils.equals(formName, request.getParameter(this.getPostLookupKey(formName))); } else { return false; } }
@Override protected final boolean doHandleGet(final String formName, final SlingHttpServletRequest request) { //noinspection SimplifiableIfStatement if (StringUtils.equalsIgnoreCase("GET", request.getMethod())) { return (CookieUtil.getCookie(request, this.getGetLookupKey(formName)) != null); } else { return false; } }
/** * Determines of this FormHelper should handle the POST request. * * @param formName * @param request * @return */ protected final boolean doHandlePost(final String formName, final SlingHttpServletRequest request) { if (StringUtils.equalsIgnoreCase("POST", request.getMethod())) { // Form should have a hidden input with the name this.getLookupKey(..) and value formName return StringUtils.equals(formName, request.getParameter(this.getPostLookupKey(formName))); } else { return false; } }
/** * Checks if this Form Manager should handle this request as a GET request. * * @param formName * @param request * @return */ protected boolean doHandleGet(final String formName, final SlingHttpServletRequest request) { //noinspection SimplifiableIfStatement if (StringUtils.equalsIgnoreCase("GET", request.getMethod())) { return (StringUtils.isNotBlank(request.getParameter(this.getGetLookupKey(formName)))); } else { return false; } }
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { if (request instanceof SlingHttpServletRequest) { SlingHttpServletRequest slingRequest = (SlingHttpServletRequest) request; if (ArrayUtils.contains(VALID_METHODS, slingRequest.getMethod())) { Object editEnabled = slingRequest.getAttribute(CMSConstants.ATTR_EDIT_ENABLED); if (!"true".equals(editEnabled) && !CMSUtils.isPublished(slingRequest.getResource())) { ((HttpServletResponse) response).sendError(404); return; } } } chain.doFilter(request, response); }
@Override public HttpMethod getRequestMethod() { return HttpMethod.valueOf(getSlingRequest().getMethod()); } }
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(); }
/** * Helper method which causes an appropriate HTTP response to be sent for an * unhandled HTTP request method. In case of HTTP/1.1 a 405 status code * (Method Not Allowed) is returned, otherwise a 400 status (Bad Request) is * returned. * * @param request The HTTP request from which the method and protocol values * are extracted to build the appropriate message. * @param response The HTTP response to which the error status is sent. * @throws IOException Thrown if the status cannot be sent to the client. */ protected void handleMethodNotImplemented(@NotNull SlingHttpServletRequest request, @NotNull SlingHttpServletResponse response) throws IOException { String protocol = request.getProtocol(); String msg = "Method " + request.getMethod() + " not supported"; if (protocol.endsWith("1.1")) { // for HTTP/1.1 use 405 Method Not Allowed response.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, msg); } else { // otherwise use 400 Bad Request response.sendError(HttpServletResponse.SC_BAD_REQUEST, msg); } }
/** * This filter only processes GET requests that targets a nt:file resource. * @param request * @return true if the filter accepts the given request */ private boolean accepts(SlingHttpServletRequest request) { return request.getMethod().equalsIgnoreCase(METHOD_GET) && request.getResource() != null && StringUtils.equals(request.getResource().getValueMap().get(JCR_PRIMARYTYPE, String.class), NT_FILE); }
private boolean accepts(final SlingHttpServletRequest slingRequest) { final Resource resource = slingRequest.getResource(); if (!StringUtils.equalsIgnoreCase("get", slingRequest.getMethod())) { // Only inject on GET requests return false; } else if (!StringUtils.startsWithAny(resource.getPath(), prefixes)) { return false; } else if (StringUtils.equals(slingRequest.getHeader("X-Requested-With"), "XMLHttpRequest")) { // Do not inject into XHR requests return false; } return true; }
private boolean accepts(final SlingHttpServletRequest slingRequest) { final Resource resource = slingRequest.getResource(); if (!StringUtils.equalsIgnoreCase("get", slingRequest.getMethod())) { // Only inject on GET requests return false; } else if (!StringUtils.startsWithAny(resource.getPath(), prefixes)) { return false; } else if (StringUtils.equals(slingRequest.getHeader("X-Requested-With"), "XMLHttpRequest")) { // Do not inject into XHR requests return false; } return true; }
String method = request.getMethod(); if (HttpConstants.METHOD_POST.equals(method)) { doPost(request, response);
/** * Gateway method the Filter uses to determine if the request is a candidate for processing by Assets Folder Properties Support. * These checks should be fast and fail broadest and fastest first. * * @param request the request * @return true if Assets Folder Properties Support should process this request. */ @SuppressWarnings("squid:S3923") protected boolean accepts(SlingHttpServletRequest request) { if (!StringUtils.equalsIgnoreCase(POST_METHOD, request.getMethod())) { // Only POST methods are processed return false; } else if (!DAM_FOLDER_SHARE_OPERATION.equals(request.getParameter(OPERATION))) { // Only requests with :operation=dam.share.folder are processed return false; } else if (!StringUtils.startsWith(request.getResource().getPath(), DAM_PATH_PREFIX)) { // Only requests under /content/dam are processed return false; } else if (!request.getResource().isResourceType(JcrResourceConstants.NT_SLING_FOLDER) && !request.getResource().isResourceType(JcrResourceConstants.NT_SLING_ORDERED_FOLDER)) { // Only requests to sling:Folders or sling:Ordered folders are processed return false; } // If the above checks do not fail, treat as a valid request return true; }
/** * Creates a <code>ResourceCollector</code> for the given * <code>request</code>. If the request is a GET or HEAD request, a * specialized instance is returned which also takes the request selectors * and request extension into account for finding servlet resources. * Otherwise an instance of this class itself is returned which just takes * the resource type and request method name into account. * * @param request The <code>SlingHttpServletRequest</code> for which to * return a <code>ResourceCollector</code>. * @return The <code>ResourceCollector</code> to find servlets and scripts * suitable for handling the <code>request</code>. */ public static ResourceCollector create( final SlingHttpServletRequest request, final String[] executionPaths, final String[] defaultExtensions) { final RequestPathInfo requestPathInfo = request.getRequestPathInfo(); final boolean isDefaultExtension = ArrayUtils.contains(defaultExtensions, requestPathInfo.getExtension()); return new ResourceCollector(request.getResource(), requestPathInfo.getExtension(), executionPaths, isDefaultExtension, request.getMethod(), requestPathInfo.getSelectors()); }