You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@sling.apache.org by Cris Rockwell <cm...@umich.edu> on 2018/06/25 19:55:16 UTC

SlingHttpServletRequestWrapper Example?

Hello!

I posted a question to StackOverflow <https://stackoverflow.com/questions/51029340/sling-filter-for-wrapping-a-request-body> about some issue I’m facing. I would like to add a POST parameter in a Sling Filter using SlingHttpServletRequestWrapper <https://sling.apache.org/apidocs/sling10/org/apache/sling/api/wrappers/SlingHttpServletRequestWrapper.html>. I would appreciate any ideas or suggestions. 

Thanks!
Cris Rockwell






Re: SlingHttpServletRequestWrapper Example?

Posted by Cris Rockwell <cm...@umich.edu>.
Hi Jason
Thanks so much for your input! I’ll try what you suggest on SO, accept it, and add the corrected wrapper code.
Cris

> On Jun 26, 2018, at 12:17 PM, Jason E Bailey <je...@apache.org> wrote:
> 
> I answered there as well.
> 
> The problem with your existing attempt is that you are attempting to access the input stream after it has been opened. The parameters already exist when you're wrapping it and you just need to make sure your additional parameters are accessible as well. 
> 
> - Jason
> 
> On Mon, Jun 25, 2018, at 3:55 PM, Cris Rockwell wrote:
>> Hello!
>> 
>> I posted a question to StackOverflow 
>> <https://stackoverflow.com/questions/51029340/sling-filter-for-wrapping-a-request-body> 
>> about some issue I’m facing. I would like to add a POST parameter in a 
>> Sling Filter using SlingHttpServletRequestWrapper 
>> <https://sling.apache.org/apidocs/sling10/org/apache/sling/api/wrappers/SlingHttpServletRequestWrapper.html>. 
>> I would appreciate any ideas or suggestions. 
>> 
>> Thanks!
>> Cris Rockwell
>> 
>> 
>> 
>> 
>> 


Re: SlingHttpServletRequestWrapper Example?

Posted by Jason E Bailey <je...@apache.org>.
I answered there as well.

The problem with your existing attempt is that you are attempting to access the input stream after it has been opened. The parameters already exist when you're wrapping it and you just need to make sure your additional parameters are accessible as well. 

- Jason

On Mon, Jun 25, 2018, at 3:55 PM, Cris Rockwell wrote:
> Hello!
> 
> I posted a question to StackOverflow 
> <https://stackoverflow.com/questions/51029340/sling-filter-for-wrapping-a-request-body> 
> about some issue I’m facing. I would like to add a POST parameter in a 
> Sling Filter using SlingHttpServletRequestWrapper 
> <https://sling.apache.org/apidocs/sling10/org/apache/sling/api/wrappers/SlingHttpServletRequestWrapper.html>. 
> I would appreciate any ideas or suggestions. 
> 
> Thanks!
> Cris Rockwell
> 
> 
> 
> 
> 

Re: SlingHttpServletRequestWrapper Example?

Posted by Bertrand Delacretaz <bd...@apache.org>.
Hi Cris,

On Mon, Jun 25, 2018 at 9:55 PM Cris Rockwell <cm...@umich.edu> wrote:
> ...I would like to add a POST parameter in a Sling Filter using SlingHttpServletRequestWrapper...

As per https://sling.apache.org/apidocs/sling7/org/apache/sling/api/SlingHttpServletRequest.html
you probably need to consistently override the Sling-specific methods
that return org.apache.sling.api.request.RequestParameter objects, I
think that's what the PostServlet uses internally.

Also, there are a number of examples that use that class in the Sling
codebase, maybe one of those help:

./sling-whiteboard/scripting-resolver/org-apache-sling-scripting-resolver/src/main/java/org/apache/sling/scripting/resolver/internal/RequestWrapper.java
./samples/fling/src/main/java/org/apache/sling/samples/fling/internal/FormServlet.java
./sling-org-apache-sling-models-impl/src/test/java/org/apache/sling/models/impl/RequestDisposalTest.java
./sling-org-apache-sling-models-impl/src/main/java/org/apache/sling/models/impl/ResourceOverridingRequestWrapper.java
./sling-org-apache-sling-models-impl/src/main/java/org/apache/sling/models/impl/via/AbstractResourceTypeViaProvider.java
./sling-org-apache-sling-models-impl/src/main/java/org/apache/sling/models/impl/via/ChildResourceViaProvider.java
./sling-samples/fling/src/main/java/org/apache/sling/samples/fling/internal/FormServlet.java
./sling-org-apache-sling-scripting-core/src/main/java/org/apache/sling/scripting/core/impl/helper/OnDemandReaderRequest.java
./sling-org-apache-sling-api/src/main/java/org/apache/sling/api/wrappers/SlingHttpServletResponseWrapper.java
./sling-org-apache-sling-api/src/main/java/org/apache/sling/api/wrappers/SlingHttpServletRequestWrapper.java
./sling-org-apache-sling-i18n/src/main/java/org/apache/sling/i18n/impl/I18NFilter.java

If you find a solution, please post it here for future reference!

-Bertrand