You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@sling.apache.org by Christopher Rockwell <cm...@umich.edu> on 2015/07/15 20:08:14 UTC

SlingServlet SO Question

Hi all.  I’m having trouble with a servlet that extends SlingAllMethodsServlet. I’ve posted about the problem … http://stackoverflow.com/questions/31437806/custom-sling-post-servlet-not-working Any input would be much appreciated.

Thanks
Chris Rockwell
LSA CMS/Web Services 	
cmrockwe@umich.edu 	










Re: SlingServlet SO Question

Posted by Christopher Rockwell <cm...@umich.edu>.
That’s interesting stuff. I made a second service to handle the post. It's associated it with a selector and the resourceType "sling/servlet/default” It seems to work as I’m intending. Thanks for your help



On Jul 16, 2015, at 11:32 AM, Jason Bailey <Ja...@sas.com> wrote:

> I think this may be a combination of things. Including the difference between how GET and POST are handled. 
>  
> I’m referring to the information here: https://sling.apache.org/documentation/the-sling-engine/url-to-script-resolution.html
>  
> When determining the resource GET uses both the extension and the selectors, the POST operation doesn't. So even though you are defining a selector and extension in the POST servlet and that’s what it’s being assigned to listen to, that’s not representative of what’s being resolved.
>  
> So in the case of your POST:
>  
> You’re performing a POST to /content/michigan-lsa/web-services/en/people/our-staff/cmrockwe.edit.html
> The POST resolution service strips off the extension and the selector which leaves /content/michigan-lsa/web-services/en/people/our-staff/cmrockwe as the identified resource, which has a resource type of ‘company/components/pages/thepage’  The post resolution service then looks for the handler for that resource.
>  
> Meanwhile your POST servlet was created as virtual resource /apps/company/components/pages/thepage/edit.html.POST.servlet which is not the resource it’s looking for. So it ends up with the default POST handler.
>  
> If you created a secondary service which associates your POST with the resourceType of ‘company/components/pages/thepage’  That should map just fine.
>  
> That said, defining POST handlers yourself can end up causing you more headaches then not. As you are overriding one of the core features of the platform.
>  
> -Jason
>  
>  
> From: Christopher Rockwell <cm...@umich.edu>
> Sent: Wednesday, July 15, 2015 4:42 PM
> To: users@sling.apache.org
> Subject: Re: SlingServlet SO Question
>  
> I think it's the later case you mentioned. The matching property would be under the child jrc:content node. I think my doPost would handle this if it ran. SlingPostServlet has a 500 since the property is not on this node. But I might be misinterpreting the error messages...
>  
> 
>  
> 15.07.2015 16:18:35.128 *ERROR* [0:0:0:0:0:0:0:1 [1436991515125] POST /content/michigan-lsa/web-services/en/people/our-staff/cmrockwe.edit.html HTTP/1.1] org.apache.sling.servlets.post.impl.operations.ModifyOperation Exception during response processing.
> javax.jcr.nodetype.ConstraintViolationException: No matching property definition: firstName = Chris
> at org.apache.jackrabbit.oak.jcr.delegate.NodeDelegate.setProperty(NodeDelegate.java:522)
> at org.apache.jackrabbit.oak.jcr.session.NodeImpl$35.perform(NodeImpl.java:1308)
> at org.apache.jackrabbit.oak.jcr.session.NodeImpl$35.perform(NodeImpl.java:1297)
> at org.apache.jackrabbit.oak.jcr.delegate.SessionDelegate.perform(SessionDelegate.java:294)
> at org.apache.jackrabbit.oak.jcr.session.ItemImpl.perform(ItemImpl.java:113)
> at org.apache.jackrabbit.oak.jcr.session.NodeImpl.internalSetProperty(NodeImpl.java:1297)
> at org.apache.jackrabbit.oak.jcr.session.NodeImpl.setProperty(NodeImpl.java:422)
> at org.apache.sling.servlets.post.impl.helper.SlingPropertyValueHandler.store(SlingPropertyValueHandler.java:592)
> at org.apache.sling.servlets.post.impl.helper.SlingPropertyValueHandler.setPropertyAsIs(SlingPropertyValueHandler.java:305)
> at org.apache.sling.servlets.post.impl.helper.SlingPropertyValueHandler.setProperty(SlingPropertyValueHandler.java:159)
> at org.apache.sling.servlets.post.impl.operations.ModifyOperation.writeContent(ModifyOperation.java:411)
> at org.apache.sling.servlets.post.impl.operations.ModifyOperation.doRun(ModifyOperation.java:101)
> at org.apache.sling.servlets.post.AbstractPostOperation.run(AbstractPostOperation.java:92)
> at org.apache.sling.servlets.post.impl.SlingPostServlet.doPost(SlingPostServlet.java:199)
> at org.apache.sling.api.servlets.SlingAllMethodsServlet.mayService(SlingAllMethodsServlet.java:148)
> at org.apache.sling.api.servlets.SlingSafeMethodsServlet.service(SlingSafeMethodsServlet.java:344)
> at org.apache.sling.api.servlets.SlingSafeMethodsServlet.service(SlingSafeMethodsServlet.java:375)
> at org.apache.sling.engine.impl.request.RequestData.service(RequestData.java:511)
> at org.apache.sling.engine.impl.filter.SlingComponentFilterChain.render(SlingComponentFilterChain.java:45)
> at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:64)
>  
>  
> 
>  
> On Jul 15, 2015, at 4:28 PM, Jason Bailey <Ja...@sas.com> wrote:
> 
> 
> The 500 response is a server error, so it's not just handling it off to the default POST handler, but it's encountering a problem when it does it. So if you take a look at your log files while you post, or the content of the 500 message itself it should provide some additional details as to the problem that you are encountering. Or is it just yelling at you because it's trying to write to that path?
> 
> 
> 
> -----Original Message-----
> From: Christopher Rockwell [mailto:cmrockwe@umich.edu] 
> Sent: Wednesday, July 15, 2015 4:13 PM
> To: users@sling.apache.org
> Subject: Re: SlingServlet SO Question
> 
> Request URL:http://localhost:4502/content/michigan-lsa/web-services/en/people/our-staff/cmrockwe.edit.html
> Request Method:POST
> Status Code:500 Server Error
> 
> Hi Jason. I copied the URL information from Chrome Tools' Network tab. Let me know if you wanted something else. Thanks!
> 
> 
> 
> 
> 
> 
> On Jul 15, 2015, at 3:42 PM, Jason Bailey <Ja...@sas.com> wrote:
> 
> 
> Hi Chris,
> 
> Can you capture what the post url looks like? 
> 
> -Jason
> 
> 
> -----Original Message-----
> From: Christopher Rockwell [mailto:cmrockwe@umich.edu] 
> Sent: Wednesday, July 15, 2015 2:08 PM
> To: users@sling.apache.org
> Subject: SlingServlet SO Question
> 
> Hi all.  I'm having trouble with a servlet that extends SlingAllMethodsServlet. I've posted about the problem ...http://stackoverflow.com/questions/31437806/custom-sling-post-servlet-not-working Any input would be much appreciated.
> 
> Thanks
> Chris Rockwell
> LSA CMS/Web Services 
> cmrockwe@umich.edu
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
>  
>  


Re: SlingServlet SO Question

Posted by Jason Bailey <Ja...@sas.com>.
I think this may be a combination of things. Including the difference between how GET and POST are handled.



I'm referring to the information here: https://sling.apache.org/documentation/the-sling-engine/url-to-script-resolution.html



When determining the resource GET uses both the extension and the selectors, the POST operation doesn't. So even though you are defining a selector and extension in the POST servlet and that's what it's being assigned to listen to, that's not representative of what's being resolved.



So in the case of your POST:



You're performing a POST to /content/michigan-lsa/web-services/en/people/our-staff/cmrockwe.edit.html

The POST resolution service strips off the extension and the selector which leaves /content/michigan-lsa/web-services/en/people/our-staff/cmrockwe as the identified resource, which has a resource type of 'company/components/pages/thepage'  The post resolution service then looks for the handler for that resource.



Meanwhile your POST servlet was created as virtual resource /apps/company/components/pages/thepage/edit.html.POST.servlet which is not the resource it's looking for. So it ends up with the default POST handler.



If you created a secondary service which associates your POST with the resourceType of 'company/components/pages/thepage'  That should map just fine.



That said, defining POST handlers yourself can end up causing you more headaches then not. As you are overriding one of the core features of the platform.



-Jason





________________________________
From: Christopher Rockwell <cm...@umich.edu>
Sent: Wednesday, July 15, 2015 4:42 PM
To: users@sling.apache.org
Subject: Re: SlingServlet SO Question

I think it's the later case you mentioned. The matching property would be under the child jrc:content node. I think my doPost would handle this if it ran. SlingPostServlet has a 500 since the property is not on this node. But I might be misinterpreting the error messages...

[cid:3FA3E81F-2BC7-46A9-869B-1857A0272AEB@adsroot.itcs.umich.edu]

15.07.2015 16:18:35.128 *ERROR* [0:0:0:0:0:0:0:1 [1436991515125] POST /content/michigan-lsa/web-services/en/people/our-staff/cmrockwe.edit.html HTTP/1.1] org.apache.sling.servlets.post.impl.operations.ModifyOperation Exception during response processing.
javax.jcr.nodetype.ConstraintViolationException: No matching property definition: firstName = Chris
at org.apache.jackrabbit.oak.jcr.delegate.NodeDelegate.setProperty(NodeDelegate.java:522)
at org.apache.jackrabbit.oak.jcr.session.NodeImpl$35.perform(NodeImpl.java:1308)
at org.apache.jackrabbit.oak.jcr.session.NodeImpl$35.perform(NodeImpl.java:1297)
at org.apache.jackrabbit.oak.jcr.delegate.SessionDelegate.perform(SessionDelegate.java:294)
at org.apache.jackrabbit.oak.jcr.session.ItemImpl.perform(ItemImpl.java:113)
at org.apache.jackrabbit.oak.jcr.session.NodeImpl.internalSetProperty(NodeImpl.java:1297)
at org.apache.jackrabbit.oak.jcr.session.NodeImpl.setProperty(NodeImpl.java:422)
at org.apache.sling.servlets.post.impl.helper.SlingPropertyValueHandler.store(SlingPropertyValueHandler.java:592)
at org.apache.sling.servlets.post.impl.helper.SlingPropertyValueHandler.setPropertyAsIs(SlingPropertyValueHandler.java:305)
at org.apache.sling.servlets.post.impl.helper.SlingPropertyValueHandler.setProperty(SlingPropertyValueHandler.java:159)
at org.apache.sling.servlets.post.impl.operations.ModifyOperation.writeContent(ModifyOperation.java:411)
at org.apache.sling.servlets.post.impl.operations.ModifyOperation.doRun(ModifyOperation.java:101)
at org.apache.sling.servlets.post.AbstractPostOperation.run(AbstractPostOperation.java:92)
at org.apache.sling.servlets.post.impl.SlingPostServlet.doPost(SlingPostServlet.java:199)
at org.apache.sling.api.servlets.SlingAllMethodsServlet.mayService(SlingAllMethodsServlet.java:148)
at org.apache.sling.api.servlets.SlingSafeMethodsServlet.service(SlingSafeMethodsServlet.java:344)
at org.apache.sling.api.servlets.SlingSafeMethodsServlet.service(SlingSafeMethodsServlet.java:375)
at org.apache.sling.engine.impl.request.RequestData.service(RequestData.java:511)
at org.apache.sling.engine.impl.filter.SlingComponentFilterChain.render(SlingComponentFilterChain.java:45)
at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:64)



On Jul 15, 2015, at 4:28 PM, Jason Bailey <Ja...@sas.com>> wrote:


The 500 response is a server error, so it's not just handling it off to the default POST handler, but it's encountering a problem when it does it. So if you take a look at your log files while you post, or the content of the 500 message itself it should provide some additional details as to the problem that you are encountering. Or is it just yelling at you because it's trying to write to that path?



-----Original Message-----
From: Christopher Rockwell [mailto:cmrockwe@umich.edu]
Sent: Wednesday, July 15, 2015 4:13 PM
To: users@sling.apache.org<ma...@sling.apache.org>
Subject: Re: SlingServlet SO Question

Request URL:http://localhost:4502/content/michigan-lsa/web-services/en/people/our-staff/cmrockwe.edit.html
Request Method:POST
Status Code:500 Server Error

Hi Jason. I copied the URL information from Chrome Tools' Network tab. Let me know if you wanted something else. Thanks!






On Jul 15, 2015, at 3:42 PM, Jason Bailey <Ja...@sas.com>> wrote:


Hi Chris,

Can you capture what the post url looks like?

-Jason


-----Original Message-----
From: Christopher Rockwell [mailto:cmrockwe@umich.edu]
Sent: Wednesday, July 15, 2015 2:08 PM
To: users@sling.apache.org<ma...@sling.apache.org>
Subject: SlingServlet SO Question

Hi all.  I'm having trouble with a servlet that extends SlingAllMethodsServlet. I've posted about the problem ... http://stackoverflow.com/questions/31437806/custom-sling-post-servlet-not-working Any input would be much appreciated.

Thanks
Chris Rockwell
LSA CMS/Web Services
cmrockwe@umich.edu<ma...@umich.edu>












Re: SlingServlet SO Question

Posted by Christopher Rockwell <cm...@umich.edu>.
I think it's the later case you mentioned. The matching property would be under the child jrc:content node. I think my doPost would handle this if it ran. SlingPostServlet has a 500 since the property is not on this node. But I might be misinterpreting the error messages...



15.07.2015 16:18:35.128 *ERROR* [0:0:0:0:0:0:0:1 [1436991515125] POST /content/michigan-lsa/web-services/en/people/our-staff/cmrockwe.edit.html HTTP/1.1] org.apache.sling.servlets.post.impl.operations.ModifyOperation Exception during response processing.
javax.jcr.nodetype.ConstraintViolationException: No matching property definition: firstName = Chris
	at org.apache.jackrabbit.oak.jcr.delegate.NodeDelegate.setProperty(NodeDelegate.java:522)
	at org.apache.jackrabbit.oak.jcr.session.NodeImpl$35.perform(NodeImpl.java:1308)
	at org.apache.jackrabbit.oak.jcr.session.NodeImpl$35.perform(NodeImpl.java:1297)
	at org.apache.jackrabbit.oak.jcr.delegate.SessionDelegate.perform(SessionDelegate.java:294)
	at org.apache.jackrabbit.oak.jcr.session.ItemImpl.perform(ItemImpl.java:113)
	at org.apache.jackrabbit.oak.jcr.session.NodeImpl.internalSetProperty(NodeImpl.java:1297)
	at org.apache.jackrabbit.oak.jcr.session.NodeImpl.setProperty(NodeImpl.java:422)
	at org.apache.sling.servlets.post.impl.helper.SlingPropertyValueHandler.store(SlingPropertyValueHandler.java:592)
	at org.apache.sling.servlets.post.impl.helper.SlingPropertyValueHandler.setPropertyAsIs(SlingPropertyValueHandler.java:305)
	at org.apache.sling.servlets.post.impl.helper.SlingPropertyValueHandler.setProperty(SlingPropertyValueHandler.java:159)
	at org.apache.sling.servlets.post.impl.operations.ModifyOperation.writeContent(ModifyOperation.java:411)
	at org.apache.sling.servlets.post.impl.operations.ModifyOperation.doRun(ModifyOperation.java:101)
	at org.apache.sling.servlets.post.AbstractPostOperation.run(AbstractPostOperation.java:92)
	at org.apache.sling.servlets.post.impl.SlingPostServlet.doPost(SlingPostServlet.java:199)
	at org.apache.sling.api.servlets.SlingAllMethodsServlet.mayService(SlingAllMethodsServlet.java:148)
	at org.apache.sling.api.servlets.SlingSafeMethodsServlet.service(SlingSafeMethodsServlet.java:344)
	at org.apache.sling.api.servlets.SlingSafeMethodsServlet.service(SlingSafeMethodsServlet.java:375)
	at org.apache.sling.engine.impl.request.RequestData.service(RequestData.java:511)
	at org.apache.sling.engine.impl.filter.SlingComponentFilterChain.render(SlingComponentFilterChain.java:45)
	at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:64)
	




On Jul 15, 2015, at 4:28 PM, Jason Bailey <Ja...@sas.com> wrote:

> The 500 response is a server error, so it's not just handling it off to the default POST handler, but it's encountering a problem when it does it. So if you take a look at your log files while you post, or the content of the 500 message itself it should provide some additional details as to the problem that you are encountering. Or is it just yelling at you because it's trying to write to that path?
> 
> 
> 
> -----Original Message-----
> From: Christopher Rockwell [mailto:cmrockwe@umich.edu] 
> Sent: Wednesday, July 15, 2015 4:13 PM
> To: users@sling.apache.org
> Subject: Re: SlingServlet SO Question
> 
> Request URL:http://localhost:4502/content/michigan-lsa/web-services/en/people/our-staff/cmrockwe.edit.html
> Request Method:POST
> Status Code:500 Server Error
> 
> Hi Jason. I copied the URL information from Chrome Tools' Network tab. Let me know if you wanted something else. Thanks!
> 
> 
> 
> 
> 
> 
> On Jul 15, 2015, at 3:42 PM, Jason Bailey <Ja...@sas.com> wrote:
> 
>> Hi Chris,
>> 
>> Can you capture what the post url looks like? 
>> 
>> -Jason
>> 
>> 
>> -----Original Message-----
>> From: Christopher Rockwell [mailto:cmrockwe@umich.edu] 
>> Sent: Wednesday, July 15, 2015 2:08 PM
>> To: users@sling.apache.org
>> Subject: SlingServlet SO Question
>> 
>> Hi all.  I'm having trouble with a servlet that extends SlingAllMethodsServlet. I've posted about the problem ... http://stackoverflow.com/questions/31437806/custom-sling-post-servlet-not-working Any input would be much appreciated.
>> 
>> Thanks
>> Chris Rockwell
>> LSA CMS/Web Services 	
>> cmrockwe@umich.edu 	
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> 
> 


RE: SlingServlet SO Question

Posted by Jason Bailey <Ja...@sas.com>.
The 500 response is a server error, so it's not just handling it off to the default POST handler, but it's encountering a problem when it does it. So if you take a look at your log files while you post, or the content of the 500 message itself it should provide some additional details as to the problem that you are encountering. Or is it just yelling at you because it's trying to write to that path?



-----Original Message-----
From: Christopher Rockwell [mailto:cmrockwe@umich.edu] 
Sent: Wednesday, July 15, 2015 4:13 PM
To: users@sling.apache.org
Subject: Re: SlingServlet SO Question

Request URL:http://localhost:4502/content/michigan-lsa/web-services/en/people/our-staff/cmrockwe.edit.html
Request Method:POST
Status Code:500 Server Error

Hi Jason. I copied the URL information from Chrome Tools' Network tab. Let me know if you wanted something else. Thanks!






On Jul 15, 2015, at 3:42 PM, Jason Bailey <Ja...@sas.com> wrote:

> Hi Chris,
> 
> Can you capture what the post url looks like? 
> 
> -Jason
> 
> 
> -----Original Message-----
> From: Christopher Rockwell [mailto:cmrockwe@umich.edu] 
> Sent: Wednesday, July 15, 2015 2:08 PM
> To: users@sling.apache.org
> Subject: SlingServlet SO Question
> 
> Hi all.  I'm having trouble with a servlet that extends SlingAllMethodsServlet. I've posted about the problem ... http://stackoverflow.com/questions/31437806/custom-sling-post-servlet-not-working Any input would be much appreciated.
> 
> Thanks
> Chris Rockwell
> LSA CMS/Web Services 	
> cmrockwe@umich.edu 	
> 
> 
> 
> 
> 
> 
> 
> 
> 


Re: SlingServlet SO Question

Posted by Christopher Rockwell <cm...@umich.edu>.
Request URL:http://localhost:4502/content/michigan-lsa/web-services/en/people/our-staff/cmrockwe.edit.html
Request Method:POST
Status Code:500 Server Error

Hi Jason. I copied the URL information from Chrome Tools' Network tab. Let me know if you wanted something else. Thanks!






On Jul 15, 2015, at 3:42 PM, Jason Bailey <Ja...@sas.com> wrote:

> Hi Chris,
> 
> Can you capture what the post url looks like? 
> 
> -Jason
> 
> 
> -----Original Message-----
> From: Christopher Rockwell [mailto:cmrockwe@umich.edu] 
> Sent: Wednesday, July 15, 2015 2:08 PM
> To: users@sling.apache.org
> Subject: SlingServlet SO Question
> 
> Hi all.  I'm having trouble with a servlet that extends SlingAllMethodsServlet. I've posted about the problem ... http://stackoverflow.com/questions/31437806/custom-sling-post-servlet-not-working Any input would be much appreciated.
> 
> Thanks
> Chris Rockwell
> LSA CMS/Web Services 	
> cmrockwe@umich.edu 	
> 
> 
> 
> 
> 
> 
> 
> 
> 


RE: SlingServlet SO Question

Posted by Jason Bailey <Ja...@sas.com>.
Hi Chris,

Can you capture what the post url looks like? 

-Jason


-----Original Message-----
From: Christopher Rockwell [mailto:cmrockwe@umich.edu] 
Sent: Wednesday, July 15, 2015 2:08 PM
To: users@sling.apache.org
Subject: SlingServlet SO Question

Hi all.  I'm having trouble with a servlet that extends SlingAllMethodsServlet. I've posted about the problem ... http://stackoverflow.com/questions/31437806/custom-sling-post-servlet-not-working Any input would be much appreciated.

Thanks
Chris Rockwell
LSA CMS/Web Services 	
cmrockwe@umich.edu