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));
}
Aggregations