You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@sling.apache.org by sam ” <sk...@gmail.com> on 2011/12/19 23:20:27 UTC

registering a servlet to handle /imgs/

Hey,

In repository, there is no resource /imgs.

And, I want to register a servlet in osgi bundle that will handle all
requests to /imgs/*

For example,

GET /imgs/some/image.jpg
GET /imgs/foo/bar.tags.xml
GET /imgs.json
GET /imgs.xml
GET /imgs/foo/bar.html

and POST..

I tried:
@Property(name = "sling.servlet.prefix", value = "/imgs")
@Property(name = "sling.servlet.selectors", value={"tags"})

But that alone does not properly register the servlet.


Is there a way to register a servlet at  /some-prefix-path ?

I cannot create resources under /imgs. If I could, I could create them and
set sling:resourceType.
And, I cannot use sling/servlet/default  because that conflicts with other
servlets ( /some/existing/resource.tags.html  will also be handled by the
servlet registered with sling.servlet.resourceTypes =
"sling/servlet/default").

Re: registering a servlet to handle /imgs/

Posted by Justin Edelson <ju...@justinedelson.com>.
Ummmm... OK. Sling's ResourceProviders provide a way to create
synthetic resources for an entire sub-tree.

But if you want to use PHP, that's up to you.

Justin

On Tue, Dec 20, 2011 at 12:51 PM, sam ” <sk...@gmail.com> wrote:
> Do not complicate things.
> Do not change urls.
> Use repository path as is (with very minimum url rewrite.. such as
> /foo/bar  to  /content/foobar.com/foo/bar).
>
> For dynamic resources (resources that do not exist), use something other
> than Sling.
>
> I solved my problem by implementing it in php.
>
>
>
>
>
> On Tue, Dec 20, 2011 at 12:17 PM, Mark Adamcin <ad...@gmail.com> wrote:
>
>> I am trying to tackle the same problem right now, with an additional
>> wrinkle. The public canonical URL for a certain page type is significantly
>> different than the underlying resource path in the repository. Not only
>> will I need to register a servlet with the HttpService for handling inbound
>> requests, but I will also need to rewrite the internal resource path back
>> to the canonical URL in html responses. And unfortunately, a regular
>> expression replacement in a mapping config node is not sufficient for
>> outbound rewriting.
>>
>> Might there be a recommended way to override the ResourceResolver.map()
>> method with a custom implementation (perhaps with a ResourceDecorator and a
>> wrapping ResourceResolver), or do you think this will require a custom
>> transformer factory?
>>
>> Thanks,
>>
>> Mark Adamcin
>> Acquity Group
>>
>>
>>
>> On Tue, Dec 20, 2011 at 7:37 AM, Felix Meschberger <fmeschbe@adobe.com
>> >wrote:
>>
>> > Hi
>> >
>> > Am 20.12.2011 um 16:22 schrieb sam ”:
>> >
>> > > sling.servlet.paths = "/imgs"  only registers the servlet for:
>> > >
>> > > GET /imgs
>> > >
>> > > The servlet should be registered for:
>> > > GET /imgs/blah/blah.jpg, too.
>> >
>> > It would also be for
>> >
>> > GET /imgs.ext/blah/blah/blah.jpg
>> >
>> > where /blah/blah/blah.jpg would be the request suffix.
>> >
>> > Other than that, we don't currently have a mechanism in Sling to register
>> > a servlet for a subtree.
>> >
>> > Outside of Sling you could register a servlet for /imgs directly with the
>> > OSGi Http Service. You would just have to provide an OSGi HttpContext
>> > implementation whose handleSecurity method calls the
>> > AuthenticationSupport.handleSecurity method.
>> >
>> > Regards
>> > Felix
>> >
>> > >
>> > >
>> > >
>> > > On Mon, Dec 19, 2011 at 5:42 PM, Alexander Klimetschek
>> > > <ak...@adobe.com>wrote:
>> > >
>> > >> On 19.12.11 23:35, "Alexander Klimetschek" <ak...@adobe.com>
>> wrote:
>> > >>> Also, you could put it under /content/imgs or /libs/imgs
>> > >>
>> > >> Ups, I meant /apps/imgs or maybe /etc/imgs (/apps & /libs should
>> usually
>> > >> be closed as much as possible for public instances to avoid any chance
>> > of
>> > >> exposing code or configuration).
>> > >>
>> > >> Chees,
>> > >> Alex
>> > >>
>> > >> --
>> > >> Alexander Klimetschek
>> > >> Developer // Adobe (Day) // Berlin - Basel
>> > >>
>> > >>
>> > >>
>> > >>
>> > >>
>> >
>> >
>>

Re: registering a servlet to handle /imgs/

Posted by sam ” <sk...@gmail.com>.
Do not complicate things.
Do not change urls.
Use repository path as is (with very minimum url rewrite.. such as
/foo/bar  to  /content/foobar.com/foo/bar).

For dynamic resources (resources that do not exist), use something other
than Sling.

I solved my problem by implementing it in php.





On Tue, Dec 20, 2011 at 12:17 PM, Mark Adamcin <ad...@gmail.com> wrote:

> I am trying to tackle the same problem right now, with an additional
> wrinkle. The public canonical URL for a certain page type is significantly
> different than the underlying resource path in the repository. Not only
> will I need to register a servlet with the HttpService for handling inbound
> requests, but I will also need to rewrite the internal resource path back
> to the canonical URL in html responses. And unfortunately, a regular
> expression replacement in a mapping config node is not sufficient for
> outbound rewriting.
>
> Might there be a recommended way to override the ResourceResolver.map()
> method with a custom implementation (perhaps with a ResourceDecorator and a
> wrapping ResourceResolver), or do you think this will require a custom
> transformer factory?
>
> Thanks,
>
> Mark Adamcin
> Acquity Group
>
>
>
> On Tue, Dec 20, 2011 at 7:37 AM, Felix Meschberger <fmeschbe@adobe.com
> >wrote:
>
> > Hi
> >
> > Am 20.12.2011 um 16:22 schrieb sam ”:
> >
> > > sling.servlet.paths = "/imgs"  only registers the servlet for:
> > >
> > > GET /imgs
> > >
> > > The servlet should be registered for:
> > > GET /imgs/blah/blah.jpg, too.
> >
> > It would also be for
> >
> > GET /imgs.ext/blah/blah/blah.jpg
> >
> > where /blah/blah/blah.jpg would be the request suffix.
> >
> > Other than that, we don't currently have a mechanism in Sling to register
> > a servlet for a subtree.
> >
> > Outside of Sling you could register a servlet for /imgs directly with the
> > OSGi Http Service. You would just have to provide an OSGi HttpContext
> > implementation whose handleSecurity method calls the
> > AuthenticationSupport.handleSecurity method.
> >
> > Regards
> > Felix
> >
> > >
> > >
> > >
> > > On Mon, Dec 19, 2011 at 5:42 PM, Alexander Klimetschek
> > > <ak...@adobe.com>wrote:
> > >
> > >> On 19.12.11 23:35, "Alexander Klimetschek" <ak...@adobe.com>
> wrote:
> > >>> Also, you could put it under /content/imgs or /libs/imgs
> > >>
> > >> Ups, I meant /apps/imgs or maybe /etc/imgs (/apps & /libs should
> usually
> > >> be closed as much as possible for public instances to avoid any chance
> > of
> > >> exposing code or configuration).
> > >>
> > >> Chees,
> > >> Alex
> > >>
> > >> --
> > >> Alexander Klimetschek
> > >> Developer // Adobe (Day) // Berlin - Basel
> > >>
> > >>
> > >>
> > >>
> > >>
> >
> >
>

Re: registering a servlet to handle /imgs/

Posted by Mark Adamcin <ad...@gmail.com>.
I am trying to tackle the same problem right now, with an additional
wrinkle. The public canonical URL for a certain page type is significantly
different than the underlying resource path in the repository. Not only
will I need to register a servlet with the HttpService for handling inbound
requests, but I will also need to rewrite the internal resource path back
to the canonical URL in html responses. And unfortunately, a regular
expression replacement in a mapping config node is not sufficient for
outbound rewriting.

Might there be a recommended way to override the ResourceResolver.map()
method with a custom implementation (perhaps with a ResourceDecorator and a
wrapping ResourceResolver), or do you think this will require a custom
transformer factory?

Thanks,

Mark Adamcin
Acquity Group



On Tue, Dec 20, 2011 at 7:37 AM, Felix Meschberger <fm...@adobe.com>wrote:

> Hi
>
> Am 20.12.2011 um 16:22 schrieb sam ”:
>
> > sling.servlet.paths = "/imgs"  only registers the servlet for:
> >
> > GET /imgs
> >
> > The servlet should be registered for:
> > GET /imgs/blah/blah.jpg, too.
>
> It would also be for
>
> GET /imgs.ext/blah/blah/blah.jpg
>
> where /blah/blah/blah.jpg would be the request suffix.
>
> Other than that, we don't currently have a mechanism in Sling to register
> a servlet for a subtree.
>
> Outside of Sling you could register a servlet for /imgs directly with the
> OSGi Http Service. You would just have to provide an OSGi HttpContext
> implementation whose handleSecurity method calls the
> AuthenticationSupport.handleSecurity method.
>
> Regards
> Felix
>
> >
> >
> >
> > On Mon, Dec 19, 2011 at 5:42 PM, Alexander Klimetschek
> > <ak...@adobe.com>wrote:
> >
> >> On 19.12.11 23:35, "Alexander Klimetschek" <ak...@adobe.com> wrote:
> >>> Also, you could put it under /content/imgs or /libs/imgs
> >>
> >> Ups, I meant /apps/imgs or maybe /etc/imgs (/apps & /libs should usually
> >> be closed as much as possible for public instances to avoid any chance
> of
> >> exposing code or configuration).
> >>
> >> Chees,
> >> Alex
> >>
> >> --
> >> Alexander Klimetschek
> >> Developer // Adobe (Day) // Berlin - Basel
> >>
> >>
> >>
> >>
> >>
>
>

Re: registering a servlet to handle /imgs/

Posted by sam ” <sk...@gmail.com>.
ResourceProvider implementation seems to be what I need.

@Component
@Service
@Properties({
    @Property(name = ResourceProvider.ROOTS, value={"/imgs"})
})
public class SyntheticResourceProvider implements ResourceProvider {
    @Override
    public Resource getResource(ResourceResolver resourceResolver, String
path) {
        log.info("getResource: path: {}", path);
        return new SyntheticResource(resourceResolver, path, "saml");
    }



Then, I can create a servlet:
@Component
@Service
@Properties({ @Property(name="service.description", value="Hello World Type
Servlet"),
    @Property(name="service.vendor", value="The Apache Software
Foundation"),
    @Property(name = "sling.servlet.resourceTypes", value = "saml")
})
public class ByResourceTypeServlet extends SlingSafeMethodsServlet {



And, these work
GET /imgs/foo/bar.html
GET /imgs/foo/bar.xml
GET /imgs/foo/bar.jpg




On Tue, Dec 20, 2011 at 1:18 PM, Colin Flanagan <up...@gmail.com>wrote:

>
> Could a SlingOptingServlet be adapted for this purpose?
>
>
> On Dec 20, 2011, at 10:37 AM, Felix Meschberger <fm...@adobe.com>
> wrote:
>
> > Hi
> >
> > Am 20.12.2011 um 16:22 schrieb sam ”:
> >
> >> sling.servlet.paths = "/imgs"  only registers the servlet for:
> >>
> >> GET /imgs
> >>
> >> The servlet should be registered for:
> >> GET /imgs/blah/blah.jpg, too.
> >
> > It would also be for
> >
> > GET /imgs.ext/blah/blah/blah.jpg
> >
> > where /blah/blah/blah.jpg would be the request suffix.
> >
> > Other than that, we don't currently have a mechanism in Sling to
> register a servlet for a subtree.
> >
> > Outside of Sling you could register a servlet for /imgs directly with
> the OSGi Http Service. You would just have to provide an OSGi HttpContext
> implementation whose handleSecurity method calls the
> AuthenticationSupport.handleSecurity method.
> >
> > Regards
> > Felix
> >
> >>
> >>
> >>
> >> On Mon, Dec 19, 2011 at 5:42 PM, Alexander Klimetschek
> >> <ak...@adobe.com>wrote:
> >>
> >>> On 19.12.11 23:35, "Alexander Klimetschek" <ak...@adobe.com> wrote:
> >>>> Also, you could put it under /content/imgs or /libs/imgs
> >>>
> >>> Ups, I meant /apps/imgs or maybe /etc/imgs (/apps & /libs should
> usually
> >>> be closed as much as possible for public instances to avoid any chance
> of
> >>> exposing code or configuration).
> >>>
> >>> Chees,
> >>> Alex
> >>>
> >>> --
> >>> Alexander Klimetschek
> >>> Developer // Adobe (Day) // Berlin - Basel
> >>>
> >>>
> >>>
> >>>
> >>>
> >
>

Re: registering a servlet to handle /imgs/

Posted by Felix Meschberger <fm...@adobe.com>.
Hi,

Am 20.12.2011 um 19:18 schrieb Colin Flanagan:

> 
> Could a SlingOptingServlet be adapted for this purpose?

No, because this only comes into play, when canidate servlets and scripts have already been selected by the ServletResolver. And the servlet configuration setup comes nto play when the resolver selects the servlets.

As a result: when it comes to SlingOptingServlet it is probably already too late.

Regards
Felix

> 
> 
> On Dec 20, 2011, at 10:37 AM, Felix Meschberger <fm...@adobe.com> wrote:
> 
>> Hi
>> 
>> Am 20.12.2011 um 16:22 schrieb sam ”:
>> 
>>> sling.servlet.paths = "/imgs"  only registers the servlet for:
>>> 
>>> GET /imgs
>>> 
>>> The servlet should be registered for:
>>> GET /imgs/blah/blah.jpg, too.
>> 
>> It would also be for
>> 
>> GET /imgs.ext/blah/blah/blah.jpg
>> 
>> where /blah/blah/blah.jpg would be the request suffix.
>> 
>> Other than that, we don't currently have a mechanism in Sling to register a servlet for a subtree.
>> 
>> Outside of Sling you could register a servlet for /imgs directly with the OSGi Http Service. You would just have to provide an OSGi HttpContext implementation whose handleSecurity method calls the AuthenticationSupport.handleSecurity method.
>> 
>> Regards
>> Felix
>> 
>>> 
>>> 
>>> 
>>> On Mon, Dec 19, 2011 at 5:42 PM, Alexander Klimetschek
>>> <ak...@adobe.com>wrote:
>>> 
>>>> On 19.12.11 23:35, "Alexander Klimetschek" <ak...@adobe.com> wrote:
>>>>> Also, you could put it under /content/imgs or /libs/imgs
>>>> 
>>>> Ups, I meant /apps/imgs or maybe /etc/imgs (/apps & /libs should usually
>>>> be closed as much as possible for public instances to avoid any chance of
>>>> exposing code or configuration).
>>>> 
>>>> Chees,
>>>> Alex
>>>> 
>>>> --
>>>> Alexander Klimetschek
>>>> Developer // Adobe (Day) // Berlin - Basel
>>>> 
>>>> 
>>>> 
>>>> 
>>>> 
>> 


Re: registering a servlet to handle /imgs/

Posted by Colin Flanagan <up...@gmail.com>.
Could a SlingOptingServlet be adapted for this purpose?


On Dec 20, 2011, at 10:37 AM, Felix Meschberger <fm...@adobe.com> wrote:

> Hi
> 
> Am 20.12.2011 um 16:22 schrieb sam ”:
> 
>> sling.servlet.paths = "/imgs"  only registers the servlet for:
>> 
>> GET /imgs
>> 
>> The servlet should be registered for:
>> GET /imgs/blah/blah.jpg, too.
> 
> It would also be for
> 
> GET /imgs.ext/blah/blah/blah.jpg
> 
> where /blah/blah/blah.jpg would be the request suffix.
> 
> Other than that, we don't currently have a mechanism in Sling to register a servlet for a subtree.
> 
> Outside of Sling you could register a servlet for /imgs directly with the OSGi Http Service. You would just have to provide an OSGi HttpContext implementation whose handleSecurity method calls the AuthenticationSupport.handleSecurity method.
> 
> Regards
> Felix
> 
>> 
>> 
>> 
>> On Mon, Dec 19, 2011 at 5:42 PM, Alexander Klimetschek
>> <ak...@adobe.com>wrote:
>> 
>>> On 19.12.11 23:35, "Alexander Klimetschek" <ak...@adobe.com> wrote:
>>>> Also, you could put it under /content/imgs or /libs/imgs
>>> 
>>> Ups, I meant /apps/imgs or maybe /etc/imgs (/apps & /libs should usually
>>> be closed as much as possible for public instances to avoid any chance of
>>> exposing code or configuration).
>>> 
>>> Chees,
>>> Alex
>>> 
>>> --
>>> Alexander Klimetschek
>>> Developer // Adobe (Day) // Berlin - Basel
>>> 
>>> 
>>> 
>>> 
>>> 
> 

Re: registering a servlet to handle /imgs/

Posted by Felix Meschberger <fm...@adobe.com>.
Hi

Am 20.12.2011 um 16:22 schrieb sam ”:

> sling.servlet.paths = "/imgs"  only registers the servlet for:
> 
> GET /imgs
> 
> The servlet should be registered for:
> GET /imgs/blah/blah.jpg, too.

It would also be for

GET /imgs.ext/blah/blah/blah.jpg

where /blah/blah/blah.jpg would be the request suffix.

Other than that, we don't currently have a mechanism in Sling to register a servlet for a subtree.

Outside of Sling you could register a servlet for /imgs directly with the OSGi Http Service. You would just have to provide an OSGi HttpContext implementation whose handleSecurity method calls the AuthenticationSupport.handleSecurity method.

Regards
Felix

> 
> 
> 
> On Mon, Dec 19, 2011 at 5:42 PM, Alexander Klimetschek
> <ak...@adobe.com>wrote:
> 
>> On 19.12.11 23:35, "Alexander Klimetschek" <ak...@adobe.com> wrote:
>>> Also, you could put it under /content/imgs or /libs/imgs
>> 
>> Ups, I meant /apps/imgs or maybe /etc/imgs (/apps & /libs should usually
>> be closed as much as possible for public instances to avoid any chance of
>> exposing code or configuration).
>> 
>> Chees,
>> Alex
>> 
>> --
>> Alexander Klimetschek
>> Developer // Adobe (Day) // Berlin - Basel
>> 
>> 
>> 
>> 
>> 


Re: registering a servlet to handle /imgs/

Posted by sam ” <sk...@gmail.com>.
sling.servlet.paths = "/imgs"  only registers the servlet for:

GET /imgs

The servlet should be registered for:
GET /imgs/blah/blah.jpg, too.



On Mon, Dec 19, 2011 at 5:42 PM, Alexander Klimetschek
<ak...@adobe.com>wrote:

> On 19.12.11 23:35, "Alexander Klimetschek" <ak...@adobe.com> wrote:
> >Also, you could put it under /content/imgs or /libs/imgs
>
> Ups, I meant /apps/imgs or maybe /etc/imgs (/apps & /libs should usually
> be closed as much as possible for public instances to avoid any chance of
> exposing code or configuration).
>
> Chees,
> Alex
>
> --
> Alexander Klimetschek
> Developer // Adobe (Day) // Berlin - Basel
>
>
>
>
>

Re: registering a servlet to handle /imgs/

Posted by Alexander Klimetschek <ak...@adobe.com>.
On 19.12.11 23:35, "Alexander Klimetschek" <ak...@adobe.com> wrote:
>Also, you could put it under /content/imgs or /libs/imgs

Ups, I meant /apps/imgs or maybe /etc/imgs (/apps & /libs should usually
be closed as much as possible for public instances to avoid any chance of
exposing code or configuration).

Chees,
Alex

-- 
Alexander Klimetschek
Developer // Adobe (Day) // Berlin - Basel





Re: registering a servlet to handle /imgs/

Posted by Alexander Klimetschek <ak...@adobe.com>.
On 19.12.11 23:20, "sam ²" <sk...@gmail.com> wrote:
>And, I want to register a servlet in osgi bundle that will handle all
>requests to /imgs/*
>
>For example,
>
>GET /imgs/some/image.jpg
>GET /imgs/foo/bar.tags.xml
>GET /imgs.json
>GET /imgs.xml
>GET /imgs/foo/bar.html
>
>and POST..
>
>I tried:
>@Property(name = "sling.servlet.prefix", value = "/imgs")
>@Property(name = "sling.servlet.selectors", value={"tags"})
>
>But that alone does not properly register the servlet.

Use sling.servlet.paths = "/imgs". See
http://sling.apache.org/site/servlets.html

But I would always avoid that if possible, since its not transparent and
you don't benefit from JCR ACLs (your servlet has to check access control
itself).

>I cannot create resources under /imgs. If I could, I could create them and
>set sling:resourceType.

Why not? If you can install code, why can't you add something to the
content structure?

Also, you could put it under /content/imgs or /libs/imgs and if you really
need the URLs to be /imgs for whatever reason, you can use rewrite rules
on the web layer in the apache.

Cheers,
Alex

-- 
Alexander Klimetschek
Developer // Adobe (Day) // Berlin - Basel