sling-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Konrad Windszus <konra...@gmx.de>
Subject Re: Changing the resource to render and the handling servlet in a request
Date Tue, 15 Oct 2019 09:21:52 GMT
Nice, can you add this to https://sling.apache.org/documentation/bundles/rendering-content-default-get-servlets.html?
<https://sling.apache.org/documentation/bundles/rendering-content-default-get-servlets.html?>
Thanks,
Konrad

> On 15. Oct 2019, at 11:19, Robert Munteanu <rombert@apache.org> wrote:
> 
> Hi Julian,
> 
> On Mon, 2019-09-30 at 21:40 +0200, Julian Sedding wrote:
>> Hi Robert (again)
>> 
>> I tried what I suggested and found exactly what you described: the
>> extension of the forwarded request is not changed.
>> 
>> However, there is a workaround. You can change the extension if you
>> append one to the path passed into the RequestDispatcher, i.e. the
>> path to your binary. The default GET servlet supports stream
>> rendering
>> (spooling binaries) for both the "null" extension and for ".res"[0].
>> Therefore the following should work.
>> 
>>    String suffix = request.getRequestPathInfo().getSuffix();
>>    request
>>        .getRequestDispatcher("/content/maven" + suffix + ".res")
>>        .forward(request, response);
>> 
>> Not particularly obvious or nice, so an API enhancement would still
>> be
>> a good thing.
> 
> That works, and without an API change, so that's extra nice :-) Thanks
> for digging into this.
> 
> Robert
> 
>> 
>> Regards
>> Julian
>> 
>> [0] 
>> https://github.com/apache/sling-org-apache-sling-servlets-get/blob/master/src/main/java/org/apache/sling/servlets/get/impl/DefaultGetServlet.java#L223-L227
>> 
>> On Fri, Sep 27, 2019 at 11:21 AM Julian Sedding <jsedding@gmail.com>
>> wrote:
>>> Hi Robert
>>> 
>>> Have you tried "forwarding" instead of "including"? AFAIK that
>>> should
>>> clear any previous reuest path info etc.
>>> 
>>> Regards
>>> Julian
>>> 
>>> On Thu, Sep 26, 2019 at 4:54 PM Robert Munteanu <rombert@apache.org
>>>> wrote:
>>>> On Thu, 2019-09-26 at 13:32 +0200, Radu Cotescu wrote:
>>>>> Hi Robert,
>>>>> 
>>>>>> On 26 Sep 2019, at 13:08, Robert Munteanu <rombert@apache.org
>>>>>>> 
>>>>>> wrote:
>>>>>> 
>>>>>> 
>>>>>> My solution has two steps:
>>>>>> 
>>>>>> 1. wrap the original request using a
>>>>>> SlingHttpServletRequestWrapper
>>>>>> and
>>>>>> overriding getResource() to return the new resource. Also
>>>>>> overriding
>>>>>> getRequestPathInfo to return an object that points to the new
>>>>>> resource
>>>>>> 
>>>>>> 2. obtain a reference to the DefaultGetServlet via
>>>>>> 
>>>>>> @Reference(target =
>>>>>> "(component.name=org.apache.sling.servlets.get.DefaultGetServ
>>>>>> let)")
>>>>>> private Servlet getServlet;
>>>>>> 
>>>>>> (I guess I could use the component pid as a slight
>>>>>> improvement).
>>>>>> 
>>>>>> and invoke its service() method with the altered request and
>>>>>> the
>>>>>> same response.
>>>>>> 
>>>>> 
>>>>> Why can’t you use the RequestDispatcher in the second step
>>>>> instead of
>>>>> directly referencing the DefaultGetServlet?
>>>> 
>>>> Good question :-) There are two answers to this:
>>>> 
>>>> 1. I did not think of that
>>>> 2. It does not allow me to override the extension. But that
>>>> should be a
>>>> simple change. So I filed
>>>> 
>>>>  https://issues.apache.org/jira/browse/SLING-8742
>>>> 
>>>> to allow overriding the extension when including a resource.
>>>> 
>>>> Thanks,
>>>> Robert
>>>> 
> 


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message