You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by "Joerg Hoh (Jira)" <ji...@apache.org> on 2022/01/05 17:01:00 UTC
[jira] [Comment Edited] (SLING-11038) Change statuscode in SlingPostServlet for PersistenceException, take 2
[ https://issues.apache.org/jira/browse/SLING-11038?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17469423#comment-17469423 ]
Joerg Hoh edited comment on SLING-11038 at 1/5/22, 5:00 PM:
------------------------------------------------------------
The problem is that the {{doRun()}} is allowed to throw a PersistenceException as well. In the most [recent version|https://github.com/apache/sling-org-apache-sling-servlets-post/blob/8dba178207b05e757c804c377eac33eff7076f93/src/main/java/org/apache/sling/servlets/post/impl/operations/AbstractPostOperation.java#L103] (Sling Post Servlets 2.5.0) only for the post processor calls both the {{PreconditionViolatedPersistenceException}} and the {{TemporaryPersistenceException}} are handled separately, so these exceptions can be handled with a 409 statuscode.
This should include the {{doRun}} call as well.
{code}
try {
doRun(request, response, changes);
// invoke processors
if (processors != null) {
for (SlingPostProcessor processor : processors) {
processor.process(request, changes);
}
}
} catch (PreconditionViolatedPersistenceException|TemporaryPersistenceException e) {
throw e;
} catch (Exception e) {
throw new PersistenceException("Exception during response processing",e);
}
{code}
This requires that the doRun method not only throws the generic {{PersistenceException}}, but more specialized ones.
was (Author: joerghoh):
The problem is that the {{doRun()}} is allowed to throw a PersistenceException as well. In the most [recent version|https://github.com/apache/sling-org-apache-sling-servlets-post/blob/8dba178207b05e757c804c377eac33eff7076f93/src/main/java/org/apache/sling/servlets/post/impl/operations/AbstractPostOperation.java#L103] (Sling Post Servlets 2.5.0) only for the post processor calls both the {{PreconditionViolatedPersistenceException}} and the {{TemporaryPersistenceException}} are handled separately, so these exceptions can be handled with a 409 statuscode.
This should include the {{doRun}} call as well.
{code}
try {
doRun(request, response, changes);
// invoke processors
if (processors != null) {
for (SlingPostProcessor processor : processors) {
processor.process(request, changes);
}
}
} catch (PreconditionViolatedPersistenceException|TemporaryPersistenceException e) {
throw e;
} catch (Exception e) {
throw new PersistenceException("Exception during response processing",e);
}
{code}
> Change statuscode in SlingPostServlet for PersistenceException, take 2
> ----------------------------------------------------------------------
>
> Key: SLING-11038
> URL: https://issues.apache.org/jira/browse/SLING-11038
> Project: Sling
> Issue Type: Improvement
> Components: Servlets
> Affects Versions: Servlets Post 2.3.36
> Reporter: Thomas Mueller
> Assignee: Robert Munteanu
> Priority: Major
> Fix For: Servlets POST 2.4.2
>
>
> When the SlingPostServlet receives a PersistenceExceptions (e.g. when trying to POST to a read-only resource), Resource at '...' is not modifiable, then a 500 is returned
> This is similar to SLING-9896, but has a different code path.
> Example stacktrace:
> {noformat}
> 03.01.2022 10:45:54.476 *ERROR* [179.60.150.135 [1641206754473] POST /content/dpc/inpro-seal//it/search.html HTTP/1.1] org.apache.sling.servlets.post.impl.operations.ModifyOperation Exception during response processing.
> org.apache.sling.api.resource.PersistenceException: Resource at '/content/dpc/inpro-seal/it/search' is not modifiable.
> at org.apache.sling.servlets.post.impl.helper.SlingPropertyValueHandler.setProperty(SlingPropertyValueHandler.java:114) [org.apache.sling.servlets.post:2.4.2]
> at org.apache.sling.servlets.post.impl.operations.ModifyOperation.writeContent(ModifyOperation.java:372) [org.apache.sling.servlets.post:2.4.2]
> at org.apache.sling.servlets.post.impl.operations.ModifyOperation.doRun(ModifyOperation.java:93) [org.apache.sling.servlets.post:2.4.2]
> at org.apache.sling.servlets.post.impl.operations.AbstractPostOperation.run(AbstractPostOperation.java:105) [org.apache.sling.servlets.post:2.4.2]
> at org.apache.sling.servlets.post.impl.SlingPostServlet.doPost(SlingPostServlet.java:243) [org.apache.sling.servlets.post:2.4.2]
> at org.apache.sling.api.servlets.SlingAllMethodsServlet.mayService(SlingAllMethodsServlet.java:146) [org.apache.sling.api:2.22.0]
> at org.apache.sling.api.servlets.SlingSafeMethodsServlet.service(SlingSafeMethodsServlet.java:342) [org.apache.sling.api:2.22.0]
> at org.apache.sling.api.servlets.SlingSafeMethodsServlet.service(SlingSafeMethodsServlet.java:374) [org.apache.sling.api:2.22.0]
> at org.apache.sling.engine.impl.request.RequestData.service(RequestData.java:552) [org.apache.sling.engine:2.7.2]
> at org.apache.sling.engine.impl.filter.SlingComponentFilterChain.render(SlingComponentFilterChain.java:44) [org.apache.sling.engine:2.7.2]
> {noformat}
> The problem is in
> https://github.com/apache/sling-org-apache-sling-servlets-post/blob/org.apache.sling.servlets.post-2.4.2/src/main/java/org/apache/sling/servlets/post/impl/operations/AbstractPostOperation.java#L105
> {noformat}
> public void run(final SlingHttpServletRequest request,
> final PostResponse response,
> final SlingPostProcessor[] processors) throws PreconditionViolatedPersistenceException, TemporaryPersistenceException {
> final VersioningConfiguration versionableConfiguration = getVersioningConfiguration(request);
> try {
> ...
> doRun(request, response, changes); <<== here
> ...
> } catch (Exception e) {
> log.error("Exception during response processing.", e);
> response.setError(e);
> } finally {
> ...
> }
> }
> {noformat}
--
This message was sent by Atlassian Jira
(v8.20.1#820001)