Search in sources :

Example 1 with PostOperation

use of org.apache.sling.servlets.post.PostOperation in project sling by apache.

the class SlingPostServlet method doPost.

@Override
protected void doPost(final SlingHttpServletRequest request, final SlingHttpServletResponse response) throws IOException {
    final VersioningConfiguration localVersioningConfig = createRequestVersioningConfiguration(request);
    request.setAttribute(VersioningConfiguration.class.getName(), localVersioningConfig);
    // prepare the response
    final PostResponse htmlResponse = createPostResponse(request);
    htmlResponse.setReferer(request.getHeader("referer"));
    final PostOperation operation = getSlingPostOperation(request);
    if (operation == null) {
        htmlResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Invalid operation specified for POST request");
    } else {
        request.getRequestProgressTracker().log("Calling PostOperation: {0}", operation.getClass().getName());
        final SlingPostProcessor[] processors = this.cachedPostProcessors;
        try {
            operation.run(request, htmlResponse, processors);
        } catch (ResourceNotFoundException rnfe) {
            htmlResponse.setStatus(HttpServletResponse.SC_NOT_FOUND, rnfe.getMessage());
        } catch (final Exception exception) {
            log.warn("Exception while handling POST " + request.getResource().getPath() + " with " + operation.getClass().getName(), exception);
            htmlResponse.setError(exception);
        }
    }
    // check for redirect URL if processing succeeded
    if (htmlResponse.isSuccessful()) {
        if (redirectIfNeeded(request, htmlResponse, response)) {
            return;
        }
    }
    // create a html response and send if unsuccessful or no redirect
    htmlResponse.send(response, isSetStatus(request));
}
Also used : SlingPostProcessor(org.apache.sling.servlets.post.SlingPostProcessor) VersioningConfiguration(org.apache.sling.servlets.post.VersioningConfiguration) ResourceNotFoundException(org.apache.sling.api.resource.ResourceNotFoundException) PostOperation(org.apache.sling.servlets.post.PostOperation) ServletException(javax.servlet.ServletException) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) ResourceNotFoundException(org.apache.sling.api.resource.ResourceNotFoundException) PostResponse(org.apache.sling.servlets.post.PostResponse)

Aggregations

IOException (java.io.IOException)1 URISyntaxException (java.net.URISyntaxException)1 ServletException (javax.servlet.ServletException)1 ResourceNotFoundException (org.apache.sling.api.resource.ResourceNotFoundException)1 PostOperation (org.apache.sling.servlets.post.PostOperation)1 PostResponse (org.apache.sling.servlets.post.PostResponse)1 SlingPostProcessor (org.apache.sling.servlets.post.SlingPostProcessor)1 VersioningConfiguration (org.apache.sling.servlets.post.VersioningConfiguration)1