SlingHttpServletRequestWrapper Example?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

SlingHttpServletRequestWrapper Example?

Christopher Rockwell
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





Reply | Threaded
Open this post in threaded view
|

Re: SlingHttpServletRequestWrapper Example?

Bertrand Delacretaz
Hi Cris,

On Mon, Jun 25, 2018 at 9:55 PM Cris Rockwell <[hidden email]> 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
Reply | Threaded
Open this post in threaded view
|

Re: SlingHttpServletRequestWrapper Example?

Jason E Bailey-2
In reply to this post by Christopher Rockwell
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
>
>
>
>
>
Reply | Threaded
Open this post in threaded view
|

Re: SlingHttpServletRequestWrapper Example?

Christopher Rockwell
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 <[hidden email]> 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
>>
>>
>>
>>
>>