You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by Andreas Schaefer <sc...@me.com.INVALID> on 2020/06/02 04:10:24 UTC

Intra Sling Calls

Hi

As of know - and place correct me if I am wrong - there is no way for a service to call Sling internally as a request in a full fledged manner.

Even though one can call Sling internally through SlingRequestProcessor usable Request and Response objects are only available as Mock objects and therefore limited In their abilities.

So I am wondering if you guys would mind for me to build a service providing the means to make internal Sling calls through the HTTP stack with an official internal Sling Request / Response object that provides all features applicable internally and removing most of the Unsupported Operation Exceptions?

Cheers - Andy

Re: Intra Sling Calls

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

On Tue, Jun 2, 2020 at 6:10 AM Andreas Schaefer
<sc...@me.com.invalid> wrote:
> ...So I am wondering if you guys would mind for me to build a service providing the means to make
> internal Sling calls through the HTTP stack with an official internal Sling Request / Response object
> that provides all features applicable internally and removing most of the Unsupported Operation Exceptions?...

That sounds interesting but what's your use case?

I'm using internal requests to retrieve schemas in
https://github.com/apache/sling-org-apache-sling-graphql-core/ and
that works quite well, keeping just the parts of the incoming request
(ResourceResolver for identity and selectors which make sense for
schemas) using the
https://github.com/apache/sling-org-apache-sling-servlet-helpers with
some customization.

That works well for my use cases but maybe your needs are different.

-Bertrand

Re: FYI, fluent helper for internal requests (was: Intra Sling Calls)

Posted by Bertrand Delacretaz <bd...@apache.org>.
On Thu, Jun 11, 2020 at 8:20 PM Andreas Schaefer
<sc...@me.com.invalid> wrote:

>... Nevermind. I just realized that getResponse().getStatus() gives me access to the status code...

Yes, but you have to ignore the status check explicitly by calling
checkStatus() with no argument, meaning "I want to ignore the status
value".

I think that's a reasonable API to avoid forgetting to check the
status, while allowing for special cases where you don't care.

Note that I had to rework the APIs to make sure an actual resource is
provided for the "direct servlet execution" mode - no big differences
and that's clearer now IMO, just committed those changes about half an
hour ago.

-Bertrand

Re: FYI, fluent helper for internal requests (was: Intra Sling Calls)

Posted by Andreas Schaefer <sc...@me.com.INVALID>.

> On Jun 11, 2020, at 11:03 AM, Andreas Schaefer <sc...@me.com.INVALID> wrote:
> 
> Hi
> 
> 
>> On Jun 11, 2020, at 1:38 AM, Bertrand Delacretaz <bd...@apache.org> wrote:
>> 
>> Hi Andy,
>> 
>> On Wed, Jun 10, 2020 at 7:14 PM Andreas Schaefer
>> <sc...@me.com.invalid> wrote:
>>> 
>>> I will try to fit into my use case....I am thinking of having big files or images than then later are streamed
>>> to the caller outside of Sling...
>> 
>> My current use cases are about small String inputs and outputs, so I
>> haven't addressed the multi-part and large data thing so far.
>> 
>> I'm planning to make a release of that servlet helpers module in a few
>> days along with the GraphQL core that uses it with small amounts of
>> input and output, but it's fine to add what you need later, I think
>> that would be useful!
> 
> That is fine with me. Dealing with output streaming as well as multipart forms need some changes in the Mock Request / Response and that will take some time. Right now I do not have a use case for it.
> 
>> 
>>> ...Also the current code from GitHub is having the checkStatus() on the execute(). I think that having a separate
>>> method (checkStatus()) is better than having on the execute()...
>> 
>> I had that first and then moved to checking status as part of
>> execute() to make sure people don't forget to do that.
>> 
>> However I agree that a separate checkStatus method makes things more
>> obvious. I'll re-add that method but add an automatic check for 200
>> status before providing any response data to the client, unless status
>> has been checked already, to make sure status is indeed checked.
> 
> I am not sure if we should make the check mandatory. If the response is returning a stack trace it might help to understand what is going on and so the response is still valid even if the call failed.
> So for that I would suggest the following signatures:
> 
> 	InternalRequest checkStatus(String … expectedStatusCodes)
> 	InternalRequest checkStatus(Integer currentStatusCode, String … expectedStatusCodes)
> 
> The ‘currentStatusCode’ is set in the checkStatus() with the statusCode from the call. The checkStatus() is accepting a status code when one of the ‘expectedStatusCodes’ matches the current.
> 
> This way the caller can respond depending on the status code.

Nevermind. I just realized that getResponse().getStatus() gives me access to the status code.

> 
>> 
>>> ...I think we also should support multiple Status to be accepted...
>> 
>> -Bertrand


Re: FYI, fluent helper for internal requests (was: Intra Sling Calls)

Posted by Andreas Schaefer <sc...@me.com.INVALID>.
Hi


> On Jun 11, 2020, at 1:38 AM, Bertrand Delacretaz <bd...@apache.org> wrote:
> 
> Hi Andy,
> 
> On Wed, Jun 10, 2020 at 7:14 PM Andreas Schaefer
> <sc...@me.com.invalid> wrote:
>> 
>> I will try to fit into my use case....I am thinking of having big files or images than then later are streamed
>> to the caller outside of Sling...
> 
> My current use cases are about small String inputs and outputs, so I
> haven't addressed the multi-part and large data thing so far.
> 
> I'm planning to make a release of that servlet helpers module in a few
> days along with the GraphQL core that uses it with small amounts of
> input and output, but it's fine to add what you need later, I think
> that would be useful!

That is fine with me. Dealing with output streaming as well as multipart forms need some changes in the Mock Request / Response and that will take some time. Right now I do not have a use case for it.

> 
>> ...Also the current code from GitHub is having the checkStatus() on the execute(). I think that having a separate
>> method (checkStatus()) is better than having on the execute()...
> 
> I had that first and then moved to checking status as part of
> execute() to make sure people don't forget to do that.
> 
> However I agree that a separate checkStatus method makes things more
> obvious. I'll re-add that method but add an automatic check for 200
> status before providing any response data to the client, unless status
> has been checked already, to make sure status is indeed checked.

I am not sure if we should make the check mandatory. If the response is returning a stack trace it might help to understand what is going on and so the response is still valid even if the call failed.
So for that I would suggest the following signatures:

	InternalRequest checkStatus(String … expectedStatusCodes)
	InternalRequest checkStatus(Integer currentStatusCode, String … expectedStatusCodes)

The ‘currentStatusCode’ is set in the checkStatus() with the statusCode from the call. The checkStatus() is accepting a status code when one of the ‘expectedStatusCodes’ matches the current.

This way the caller can respond depending on the status code.

> 
>> ...I think we also should support multiple Status to be accepted...
> 
> -Bertrand


Re: FYI, fluent helper for internal requests (was: Intra Sling Calls)

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

On Wed, Jun 10, 2020 at 7:14 PM Andreas Schaefer
<sc...@me.com.invalid> wrote:
>
> I will try to fit into my use case....I am thinking of having big files or images than then later are streamed
> to the caller outside of Sling...

My current use cases are about small String inputs and outputs, so I
haven't addressed the multi-part and large data thing so far.

I'm planning to make a release of that servlet helpers module in a few
days along with the GraphQL core that uses it with small amounts of
input and output, but it's fine to add what you need later, I think
that would be useful!

> ...Also the current code from GitHub is having the checkStatus() on the execute(). I think that having a separate
> method (checkStatus()) is better than having on the execute()...

I had that first and then moved to checking status as part of
execute() to make sure people don't forget to do that.

However I agree that a separate checkStatus method makes things more
obvious. I'll re-add that method but add an automatic check for 200
status before providing any response data to the client, unless status
has been checked already, to make sure status is indeed checked.

> ...I think we also should support multiple Status to be accepted...

-Bertrand

Re: FYI, fluent helper for internal requests (was: Intra Sling Calls)

Posted by Andreas Schaefer <sc...@me.com.INVALID>.
I tested the InternalRequest in my use cases and its works just fine.

> On Jun 10, 2020, at 10:14 AM, Andreas Schaefer <sc...@me.com.INVALID> wrote:
> 
> I will try to fit into my use case. That said I am sort of confused with the OutputStream. As far as I understand it the output stream is when I write to a sink but not read from a source. If we want to support streaming in the InternalRequest it needs to provide an InputStream and the ResponseBondySupports needs to be using a Buffered Output Stream to facilitates that. I am thinking of having big files or images than then later are streamed to the caller outside of Sling.
> 
> Also the current code from GitHub is having the checkStatus() on the execute(). I think that having a separate method (checkStatus()) is better than having on the execute(). That said I think we also should support multiple Status to be accepted.
> 
> Cheers - Andy
> 
>> On Jun 10, 2020, at 7:07 AM, Bertrand Delacretaz <bd...@apache.org> wrote:
>> 
>> Hi,
>> 
>> On Wed, Jun 3, 2020 at 11:03 AM Bertrand Delacretaz
>> <bd...@apache.org> wrote:
>>> ...for my use cases a fluent interface to the SlingRequestProcessor would be nice...
>> 
>> I have now implemented a fluent helper for internal requests, using
>> either the SlingRequestProcessor (for full fidelity compared to HTTP
>> requests) or the ServletResolver (faster, no Servlet Filters - thanks
>> Radu for mentioning that option), at SLING-9512 and [1].
>> 
>> Here's a usage example, the tests [1] have more:
>> 
>> OutputStream os = InternalRequest
>> .servletRequest(resourceResolver, servletResolver, "/some/path")
>> .withResourceType("website/article/news")
>> .withResourceSuperType("website/article")
>> .withSelectors("print", "a4")
>> .withExtension("pdf")
>> .execute()
>> .checkStatus(200)
>> .checkResponseContentType("application/pdf")
>> .getResponse()
>> .getOutputStream();
>> 
>> Feedback is welcome! I'm using this in the GraphQL core that I'd like
>> to release soon, will need to release the servlet-helpers module as
>> well.
>> 
>> -Bertrand
>> 
>> [1] https://github.com/apache/sling-org-apache-sling-servlet-helpers
> 


Re: FYI, fluent helper for internal requests (was: Intra Sling Calls)

Posted by Andreas Schaefer <sc...@me.com.INVALID>.
I will try to fit into my use case. That said I am sort of confused with the OutputStream. As far as I understand it the output stream is when I write to a sink but not read from a source. If we want to support streaming in the InternalRequest it needs to provide an InputStream and the ResponseBondySupports needs to be using a Buffered Output Stream to facilitates that. I am thinking of having big files or images than then later are streamed to the caller outside of Sling.

Also the current code from GitHub is having the checkStatus() on the execute(). I think that having a separate method (checkStatus()) is better than having on the execute(). That said I think we also should support multiple Status to be accepted.

Cheers - Andy

> On Jun 10, 2020, at 7:07 AM, Bertrand Delacretaz <bd...@apache.org> wrote:
> 
> Hi,
> 
> On Wed, Jun 3, 2020 at 11:03 AM Bertrand Delacretaz
> <bd...@apache.org> wrote:
>> ...for my use cases a fluent interface to the SlingRequestProcessor would be nice...
> 
> I have now implemented a fluent helper for internal requests, using
> either the SlingRequestProcessor (for full fidelity compared to HTTP
> requests) or the ServletResolver (faster, no Servlet Filters - thanks
> Radu for mentioning that option), at SLING-9512 and [1].
> 
> Here's a usage example, the tests [1] have more:
> 
> OutputStream os = InternalRequest
>  .servletRequest(resourceResolver, servletResolver, "/some/path")
>  .withResourceType("website/article/news")
>  .withResourceSuperType("website/article")
>  .withSelectors("print", "a4")
>  .withExtension("pdf")
>  .execute()
>  .checkStatus(200)
>  .checkResponseContentType("application/pdf")
>  .getResponse()
>  .getOutputStream();
> 
> Feedback is welcome! I'm using this in the GraphQL core that I'd like
> to release soon, will need to release the servlet-helpers module as
> well.
> 
> -Bertrand
> 
> [1] https://github.com/apache/sling-org-apache-sling-servlet-helpers


FYI, fluent helper for internal requests (was: Intra Sling Calls)

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

On Wed, Jun 3, 2020 at 11:03 AM Bertrand Delacretaz
<bd...@apache.org> wrote:
> ...for my use cases a fluent interface to the SlingRequestProcessor would be nice...

I have now implemented a fluent helper for internal requests, using
either the SlingRequestProcessor (for full fidelity compared to HTTP
requests) or the ServletResolver (faster, no Servlet Filters - thanks
Radu for mentioning that option), at SLING-9512 and [1].

Here's a usage example, the tests [1] have more:

OutputStream os = InternalRequest
  .servletRequest(resourceResolver, servletResolver, "/some/path")
  .withResourceType("website/article/news")
  .withResourceSuperType("website/article")
  .withSelectors("print", "a4")
  .withExtension("pdf")
  .execute()
  .checkStatus(200)
  .checkResponseContentType("application/pdf")
  .getResponse()
  .getOutputStream();

Feedback is welcome! I'm using this in the GraphQL core that I'd like
to release soon, will need to release the servlet-helpers module as
well.

-Bertrand

[1] https://github.com/apache/sling-org-apache-sling-servlet-helpers

Re: Intra Sling Calls

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

On Tue, Jun 2, 2020 at 7:06 PM Andreas Schaefer
<sc...@me.com.invalid> wrote:
> ...I do not like to use a “Mock” class for a in-production code..

If you don't have a request but need a request, you do need to mock it ;-)

I agree that the term "mocks" is often connected to testing but if you
look at our servlet helper classes [1] I don't see anything that makes
them specific to testing.

Their automated test coverage is quite good and it all looks like
solid code to me, they look perfectly fine as "production mocks".

> ...I cannot do multiparts forms in the Mock classes (getParts(), getPart() is throwing an Unsupported Operation Exception)...

How about improving that servlet-helpers module to support that?

IMHO, internal requests using the SlingRequestProcessor is a powerful
mechanism, I'm all for making it easier to use - but I think we have a
good foundation with that module.

As a sidenote (which might be relevant if we improve this), for my use
cases a fluent interface to the SlingRequestProcessor would be nice,
something like

InternalRequest.Get(SlingRequestProcessor, ResourceResolver)
  .forPath("/yocats").withSelectors("farenheit", "451").withExtension("json")
  .execute()
  .checkStatus(200)
  .checkContentType("application/json")
  .getContentAsStream()

-Bertrand

[1] https://github.com/apache/sling-org-apache-sling-servlet-helpers/tree/master/src/main/java/org/apache/sling/servlethelpers

Re: Intra Sling Calls

Posted by Andreas Schaefer <sc...@me.com.INVALID>.
Hi Dirk

First I do not like to use a “Mock” class for a in-production code. Second I cannot do multiparts forms in the Mock classes (getParts(), getPart() is throwing an Unsupported Operation Exception).

- Andy

> On Jun 2, 2020, at 12:14 AM, Dirk Rudolph <di...@netcentric.biz> wrote:
> 
> The mock implementations in o.a.s.servlet-helpers are actually quite
> complete for common use cases. What do you have in mind that might be
> missing?
> 
> Kind regards,
> Dirk
> 
> On Tue, 2 Jun 2020 at 08:58, Konrad Windszus <ko...@gmx.de> wrote:
> 
>> If you don’t have a request at hand it will be impossible to implement
>> fully. If you have a request just use regular request dispatching.
>> Konrad
>> 
>> 
>>> Am 02.06.2020 um 08:21 schrieb Carsten Ziegeler <cz...@apache.org>:
>>> 
>>> So you want to make an HTTP request from within Sling to itself?
>>> I wouldn't recommend doing this, but I see no problem of having this as
>> a new separate module, maybe starting in the whiteboard.
>>> 
>>> Regards
>>> Carsten
>>> 
>>>> Am 02.06.2020 um 06:10 schrieb Andreas Schaefer:
>>>> Hi
>>>> As of know - and place correct me if I am wrong - there is no way for a
>> service to call Sling internally as a request in a full fledged manner.
>>>> Even though one can call Sling internally through SlingRequestProcessor
>> usable Request and Response objects are only available as Mock objects and
>> therefore limited In their abilities.
>>>> So I am wondering if you guys would mind for me to build a service
>> providing the means to make internal Sling calls through the HTTP stack
>> with an official internal Sling Request / Response object that provides all
>> features applicable internally and removing most of the Unsupported
>> Operation Exceptions?
>>>> Cheers - Andy
>>> 
>>> --
>>> --
>>> Carsten Ziegeler
>>> Adobe Research Switzerland
>>> cziegeler@apache.org
>> 
>> --
> 
> Dirk Rudolph | Senior Software Engineer
> 
> Netcentric AG
> 
> M: +41 79 642 37 11
> D: +49 174 966 84 34
> 
> dirk.rudolph@netcentric.biz | www.netcentric.biz


Re: Intra Sling Calls

Posted by Dirk Rudolph <di...@netcentric.biz>.
The mock implementations in o.a.s.servlet-helpers are actually quite
complete for common use cases. What do you have in mind that might be
missing?

Kind regards,
Dirk

On Tue, 2 Jun 2020 at 08:58, Konrad Windszus <ko...@gmx.de> wrote:

> If you don’t have a request at hand it will be impossible to implement
> fully. If you have a request just use regular request dispatching.
> Konrad
>
>
> > Am 02.06.2020 um 08:21 schrieb Carsten Ziegeler <cz...@apache.org>:
> >
> > So you want to make an HTTP request from within Sling to itself?
> > I wouldn't recommend doing this, but I see no problem of having this as
> a new separate module, maybe starting in the whiteboard.
> >
> > Regards
> > Carsten
> >
> >> Am 02.06.2020 um 06:10 schrieb Andreas Schaefer:
> >> Hi
> >> As of know - and place correct me if I am wrong - there is no way for a
> service to call Sling internally as a request in a full fledged manner.
> >> Even though one can call Sling internally through SlingRequestProcessor
> usable Request and Response objects are only available as Mock objects and
> therefore limited In their abilities.
> >> So I am wondering if you guys would mind for me to build a service
> providing the means to make internal Sling calls through the HTTP stack
> with an official internal Sling Request / Response object that provides all
> features applicable internally and removing most of the Unsupported
> Operation Exceptions?
> >> Cheers - Andy
> >
> > --
> > --
> > Carsten Ziegeler
> > Adobe Research Switzerland
> > cziegeler@apache.org
>
> --

Dirk Rudolph | Senior Software Engineer

Netcentric AG

M: +41 79 642 37 11
D: +49 174 966 84 34

dirk.rudolph@netcentric.biz | www.netcentric.biz

Re: Intra Sling Calls

Posted by Konrad Windszus <ko...@gmx.de>.
If you don’t have a request at hand it will be impossible to implement fully. If you have a request just use regular request dispatching.
Konrad


> Am 02.06.2020 um 08:21 schrieb Carsten Ziegeler <cz...@apache.org>:
> 
> So you want to make an HTTP request from within Sling to itself?
> I wouldn't recommend doing this, but I see no problem of having this as a new separate module, maybe starting in the whiteboard.
> 
> Regards
> Carsten
> 
>> Am 02.06.2020 um 06:10 schrieb Andreas Schaefer:
>> Hi
>> As of know - and place correct me if I am wrong - there is no way for a service to call Sling internally as a request in a full fledged manner.
>> Even though one can call Sling internally through SlingRequestProcessor usable Request and Response objects are only available as Mock objects and therefore limited In their abilities.
>> So I am wondering if you guys would mind for me to build a service providing the means to make internal Sling calls through the HTTP stack with an official internal Sling Request / Response object that provides all features applicable internally and removing most of the Unsupported Operation Exceptions?
>> Cheers - Andy
> 
> -- 
> --
> Carsten Ziegeler
> Adobe Research Switzerland
> cziegeler@apache.org


Re: Intra Sling Calls

Posted by Carsten Ziegeler <cz...@apache.org>.
Hi,

so you rather want to call the http service instead (which then 
eventually calls Sling), correct?

Regards
Carsten

Am 02.06.2020 um 19:32 schrieb Andreas Schaefer:
> Hi Carsten
> 
> Not really an HTTP request but internally go through the HTTP stack.
> 
> We are using these Intra Sling Calls for Image Rendering and to delegate Composum Package handling because we cannot use an OSGI services, or there is code executed before hitting an OSGi service.
> 
> Cheers - Andy
> 
> 
>> On Jun 1, 2020, at 11:21 PM, Carsten Ziegeler <cz...@apache.org> wrote:
>>
>> So you want to make an HTTP request from within Sling to itself?
>> I wouldn't recommend doing this, but I see no problem of having this as a new separate module, maybe starting in the whiteboard.
>>
>> Regards
>> Carsten
>>
>> Am 02.06.2020 um 06:10 schrieb Andreas Schaefer:
>>> Hi
>>> As of know - and place correct me if I am wrong - there is no way for a service to call Sling internally as a request in a full fledged manner.
>>> Even though one can call Sling internally through SlingRequestProcessor usable Request and Response objects are only available as Mock objects and therefore limited In their abilities.
>>> So I am wondering if you guys would mind for me to build a service providing the means to make internal Sling calls through the HTTP stack with an official internal Sling Request / Response object that provides all features applicable internally and removing most of the Unsupported Operation Exceptions?
>>> Cheers - Andy
>>
>> -- 
>> --
>> Carsten Ziegeler
>> Adobe Research Switzerland
>> cziegeler@apache.org
> 

-- 
--
Carsten Ziegeler
Adobe Research Switzerland
cziegeler@apache.org

Re: Intra Sling Calls

Posted by Andreas Schaefer <sc...@me.com.INVALID>.
Hi Carsten

Not really an HTTP request but internally go through the HTTP stack.

We are using these Intra Sling Calls for Image Rendering and to delegate Composum Package handling because we cannot use an OSGI services, or there is code executed before hitting an OSGi service.

Cheers - Andy


> On Jun 1, 2020, at 11:21 PM, Carsten Ziegeler <cz...@apache.org> wrote:
> 
> So you want to make an HTTP request from within Sling to itself?
> I wouldn't recommend doing this, but I see no problem of having this as a new separate module, maybe starting in the whiteboard.
> 
> Regards
> Carsten
> 
> Am 02.06.2020 um 06:10 schrieb Andreas Schaefer:
>> Hi
>> As of know - and place correct me if I am wrong - there is no way for a service to call Sling internally as a request in a full fledged manner.
>> Even though one can call Sling internally through SlingRequestProcessor usable Request and Response objects are only available as Mock objects and therefore limited In their abilities.
>> So I am wondering if you guys would mind for me to build a service providing the means to make internal Sling calls through the HTTP stack with an official internal Sling Request / Response object that provides all features applicable internally and removing most of the Unsupported Operation Exceptions?
>> Cheers - Andy
> 
> -- 
> --
> Carsten Ziegeler
> Adobe Research Switzerland
> cziegeler@apache.org


Re: Intra Sling Calls

Posted by Carsten Ziegeler <cz...@apache.org>.
So you want to make an HTTP request from within Sling to itself?
I wouldn't recommend doing this, but I see no problem of having this as 
a new separate module, maybe starting in the whiteboard.

Regards
Carsten

Am 02.06.2020 um 06:10 schrieb Andreas Schaefer:
> Hi
> 
> As of know - and place correct me if I am wrong - there is no way for a service to call Sling internally as a request in a full fledged manner.
> 
> Even though one can call Sling internally through SlingRequestProcessor usable Request and Response objects are only available as Mock objects and therefore limited In their abilities.
> 
> So I am wondering if you guys would mind for me to build a service providing the means to make internal Sling calls through the HTTP stack with an official internal Sling Request / Response object that provides all features applicable internally and removing most of the Unsupported Operation Exceptions?
> 
> Cheers - Andy
> 

-- 
--
Carsten Ziegeler
Adobe Research Switzerland
cziegeler@apache.org