You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@sling.apache.org by Jörg Hoh <jh...@googlemail.com> on 2015/12/21 12:24:01 UTC

Fake request/response classes

Hi,

I want to write a warmup feature for my application, which should run
requests using SlingRequestProcessor against the instance.

I am looking now at slim implementations of HttpServletRequest and
HttpServletResponse, which I can provide as parameters to
Sling.RequestProcessor.processRequest(); these implementations shouldn't be
completed, I only need a small subset of the methods working (probably
setStatus/getStatus).

I checked the sling codebase, but I haven't found any class which could act
as basis for this? Do I really need to write my own class inheriting from
HttpServletRequest/HttpServletResponse and implement what I need? I've
found an implementation in oas.junit.scriptable.HttpResponse, but I don't
want to have a runtime dependency on this bundle.

Thanks!

-- 
Cheers,
Jörg

http://cqdump.wordpress.com
Twitter: @joerghoh

Re: Fake request/response classes

Posted by Bertrand Delacretaz <bd...@apache.org>.
On Wed, Jan 13, 2016 at 11:58 PM, Stefan Seifert <ss...@pro-vision.de> wrote:
> ... https://issues.apache.org/jira/browse/SLING-5428 ...

Thanks for this new servlet-helpers module!

I have mentioned it in the SlingRequestProcessor javadocs (rev
1724549) and added minimal docs at
http://sling.apache.org/documentation/bundles/servlet-helpers.html

-Bertrand

RE: Fake request/response classes

Posted by Stefan Seifert <ss...@pro-vision.de>.
i've created a ticket for this:
https://issues.apache.org/jira/browse/SLING-5428

stefan

>-----Original Message-----
>From: Bertrand Delacretaz [mailto:bdelacretaz@apache.org]
>Sent: Monday, December 21, 2015 5:02 PM
>To: users
>Subject: Re: Fake request/response classes
>
>Hi,
>
>On Mon, Dec 21, 2015 at 4:30 PM, Stefan Seifert <ss...@pro-vision.de>
>wrote:
>> ...here are the classes
>> https://svn.apache.org/repos/asf/sling/trunk/testing/mocks/sling-
>mock/src/main/java/org/apache/sling/testing/mock/sling/servlet
>>
>> most of them have no dependencies except some to commons-lang and guava
>which
>> could be eliminated if required...
>
>I think the best would be to create a new commons/servlet-helpers
>bundle with those classes, and minimize their dependencies, removing
>at least guava.
>
>I prefer keeping the engine bundle as lean as possible.
>
>-Bertrand

Re: Fake request/response classes

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

On Mon, Dec 21, 2015 at 4:30 PM, Stefan Seifert <ss...@pro-vision.de> wrote:
> ...here are the classes
> https://svn.apache.org/repos/asf/sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/servlet
>
> most of them have no dependencies except some to commons-lang and guava which
> could be eliminated if required...

I think the best would be to create a new commons/servlet-helpers
bundle with those classes, and minimize their dependencies, removing
at least guava.

I prefer keeping the engine bundle as lean as possible.

-Bertrand

Re: Fake request/response classes

Posted by Steven Walters <st...@icidigital.com>.
On Mon, Dec 21, 2015 at 10:30 AM, Stefan Seifert <ss...@pro-vision.de> wrote:
>
>>I know. But I don't want to deploy the Sling mocks library as a bundle
>>along with my Sling-based application to the OSGI container (haven't
>>checked if it's a bundle at all). I also don't want to embedd this jar file
>>into a custom bundle just because I need these few classes.
>
> sling-mocks is definitely not supposed to be deployed in an OSGi container (and will fail due to unresolvable internal dependencies if tried to). it's only supposed for unit test environment.
>
> refactoring the servlet api mocks from sling-mock to a separate and lightweight bundle would be an option. imho it should be a separate bundle instead of including them in the sling API.
>
> here are the classes
> https://svn.apache.org/repos/asf/sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/servlet
>
> most of them have no dependencies except some to commons-lang and guava which could be eliminated if required.
>
> if there is need for using them standalone please create a ticket.
>
> stefan

Since this is about utilizing the SlingRequestProcessor [1], some
handy/convenient light-weight implementations of request and response
would be pretty beneficial here.
I've seen quite a number of projects end up having to make their own
implementations of the request and response classes to utilize the
request processor, which is the path Jörg here is implicating he's
needing to go down currently as well.

I think it'd be something for the Sling project to look at evaluating
here to make SlingRequestProcessor's usage more convenient going
forward.
Or at least, that's my opinion.

- Steven

[1] https://sling.apache.org/apidocs/sling8/org/apache/sling/engine/SlingRequestProcessor.html

RE: Fake request/response classes

Posted by Stefan Seifert <ss...@pro-vision.de>.
>I know. But I don't want to deploy the Sling mocks library as a bundle
>along with my Sling-based application to the OSGI container (haven't
>checked if it's a bundle at all). I also don't want to embedd this jar file
>into a custom bundle just because I need these few classes.

sling-mocks is definitely not supposed to be deployed in an OSGi container (and will fail due to unresolvable internal dependencies if tried to). it's only supposed for unit test environment.

refactoring the servlet api mocks from sling-mock to a separate and lightweight bundle would be an option. imho it should be a separate bundle instead of including them in the sling API.

here are the classes
https://svn.apache.org/repos/asf/sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/servlet

most of them have no dependencies except some to commons-lang and guava which could be eliminated if required.

if there is need for using them standalone please create a ticket.

stefan

Re: Fake request/response classes

Posted by Jörg Hoh <jh...@googlemail.com>.
Hi Steven,

2015-12-21 16:03 GMT+01:00 Steven Walters <st...@icidigital.com>:

>
>
> Bertrand's referenced code is a portion of the Sling project's "Sling
> Mocks" module that gets released to maven as a jar like other Sling
> modules.
> See the documentation for Sling mocks at [1] for further detail on how
> to add it to a maven project and example usages.
>
>

I know. But I don't want to deploy the Sling mocks library as a bundle
along with my Sling-based application to the OSGI container (haven't
checked if it's a bundle at all). I also don't want to embedd this jar file
into a custom bundle just because I need these few classes.

Having these classes in the Sling Engine bundle (where the
SlingRequestProcessor service is located) would be more convenient. Or
maybe having some additional "sling engine helper" bundle. These mock
classes are useful beyond mocking requests and responses for unittests.


-- 
Cheers,
Jörg Hoh,

http://cqdump.wordpress.com
Twitter: @joerghoh

Re: Fake request/response classes

Posted by Steven Walters <st...@icidigital.com>.
Jörg,

On Mon, Dec 21, 2015 at 9:10 AM, Jörg Hoh <jh...@googlemail.com> wrote:
>
> Hi Bertrand
>
> 2015-12-21 13:56 GMT+01:00 Bertrand Delacretaz <bd...@apache.org>:
>
> >
> > Would the Sling mocks MockSlingHttpServletRequest and response work
> > for you? Or shall we maybe refactor them to inherit from new non-Sling
> > HttpServletRequest/Response mocks that are more generally usable?
> >
> > -Bertrand
> >
> > [1]
> > https://svn.apache.org/repos/asf/sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/servlet/
> >
>
> These would be sufficient. But I would like to have them in a "mainline"
> bundle and not in a codebase, which I normally use to run unittests.
>
> Jörg

Bertrand's referenced code is a portion of the Sling project's "Sling
Mocks" module that gets released to maven as a jar like other Sling
modules.
See the documentation for Sling mocks at [1] for further detail on how
to add it to a maven project and example usages.

- Steven

[1] https://sling.apache.org/documentation/development/sling-mock.html

Re: Fake request/response classes

Posted by Jörg Hoh <jh...@googlemail.com>.
Hi Bertrand

2015-12-21 13:56 GMT+01:00 Bertrand Delacretaz <bd...@apache.org>:

>
> Would the Sling mocks MockSlingHttpServletRequest and response work
> for you? Or shall we maybe refactor them to inherit from new non-Sling
> HttpServletRequest/Response mocks that are more generally usable?
>
> -Bertrand
>
> [1]
> https://svn.apache.org/repos/asf/sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/servlet/
>

These would be sufficient. But I would like to have them in a "mainline"
bundle and not in a codebase, which I normally use to run unittests.

Jörg

-- 
Cheers,
Jörg Hoh,

http://cqdump.wordpress.com
Twitter: @joerghoh

Re: Fake request/response classes

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

On Mon, Dec 21, 2015 at 12:24 PM, Jörg Hoh <jh...@googlemail.com> wrote:
> ...I checked the sling codebase, but I haven't found any class which could act
> as basis for this?...

Would the Sling mocks MockSlingHttpServletRequest and response work
for you? Or shall we maybe refactor them to inherit from new non-Sling
HttpServletRequest/Response mocks that are more generally usable?

-Bertrand

[1] https://svn.apache.org/repos/asf/sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/servlet/