in src/main/java/org/apache/sling/jcr/jackrabbit/accessmanager/post/AbstractAccessPostServlet.java [78:162]
protected void doPost(SlingHttpServletRequest request,
SlingHttpServletResponse httpResponse) throws ServletException,
IOException {
// prepare the response
PostResponse response = createPostResponse(request);
response.setReferer(request.getHeader("referer"));
// calculate the paths
String path = getItemPath(request);
response.setPath(path);
// location
response.setLocation(externalizePath(request, path));
// parent location
path = getParentPath(path);
if (path != null) {
response.setParentLocation(externalizePath(request, path));
}
Session session = request.getResourceResolver().adaptTo(Session.class);
final List<Modification> changes = new ArrayList<>();
try {
handleOperation(request, response, changes);
// set changes on html response
for(Modification change : changes) {
switch ( change.getType() ) {
case MODIFY : response.onModified(change.getSource()); break;
case DELETE : response.onDeleted(change.getSource()); break;
case MOVE : response.onMoved(change.getSource(), change.getDestination()); break;
case COPY : response.onCopied(change.getSource(), change.getDestination()); break;
case CREATE : response.onCreated(change.getSource()); break;
case ORDER : response.onChange("ordered", change.getSource(), change.getDestination()); break;
default:
break;
}
}
if (session.hasPendingChanges()) {
session.save();
}
} catch (ResourceNotFoundException rnfe) {
response.setStatus(HttpServletResponse.SC_NOT_FOUND,
rnfe.getMessage());
} catch (Exception throwable) {
log.debug(String.format("Exception while handling POST %s with %s",
request.getResource().getPath(), getClass().getName()), throwable);
response.setError(throwable);
} finally {
try {
if (session.hasPendingChanges()) {
session.refresh(false);
}
} catch (RepositoryException e) {
log.warn("RepositoryException in finally block: {}",
e.getMessage(), e);
}
}
// check for redirect URL if processing succeeded
if (response.isSuccessful()) {
String redirect = null;
try {
redirect = getRedirectUrl(request, response);
} catch (IOException e) {
if (log.isDebugEnabled()) {
log.debug(String.format("Exception while handling redirect for POST %s with %s",
request.getResource().getPath(), getClass().getName()), e);
}
// http status code for 422 Unprocessable Entity
response.setStatus(422, "invalid redirect");
response.setError(e);
}
if (redirect != null) {
httpResponse.sendRedirect(redirect); // NOSONAR
return;
}
}
// create a html response and send if unsuccessful or no redirect
response.send(httpResponse, isSetStatus(request));
}