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 lee <sk...@gmail.com> on 2010/10/14 23:43:30 UTC

/etc/map to serve shorten url

Hey,

I want http request:
GET /imgs/a/b/c/640x480/r/img.jpg

to be resolved to the JCR node:
/content/images/a/b/c/img.jpg/jcr:content/thumbnails/640x480

I looked at:
http://sling.apache.org/site/mappings-for-resource-resolution.html

And, my current /etc/map is:
/etc/map/any (sling:Mapping)
- sling:match = http://[^/]+/imgs/(.+)/([^/]+)/r/([^/]+)$
- sling:internalRedirect = /content/images/$1/$3/jcr:content/thumbnails/$2

But, GET /imgs/a/b/c/640x480/of/img.jpg  gives me 404.
Is there something I'm doing wrong?

Am I approaching the problem properly?
Using regex seems brittle.

If I were to write a class that knows how to convert short path to actual
jcr path, what interface should the class implement? And, how can I register
it to sling's DefaultGetServlet?

Thanks.
Sam

Re: /etc/map to serve shorten url

Posted by sam lee <sk...@gmail.com>.
regex for sling:amtch had to be:
http/[^/]+/imgs/(.+)/([^/]+)/r/([^/]+)$

JcrResourceResolver2.getMapPath("http", "localhost", 8080,
"/imgs/2010/10/14/190x190/r/img.jpg")
==>
http/localhost.8080/imgs/2010/10/14/190x190/r/img.jpg


So, this solved:
curl -F'sling:match=http/[^/]+/imgs/(.+)/([^/]+)/r/([^/]+)$'
-F'sling:internalRedirect=/content/images/$1/$3/jcr:content/thumbnails/$2'
-F'jcr:primaryType=sling:Mapping' http://admin:admin@localhost
:8080/etc/map/any

On Thu, Oct 14, 2010 at 10:48 PM, sam lee <sk...@gmail.com> wrote:

> Oops, it's a typo.
> Request is to "r", too.
> I'll have to step through and see what's happening.
>
> This is the script I used on
> org.apache.sling.launchpad.app-5-incubator.jar:
>
> curl -F'jcr:primaryType=sling:Folder' http://admin:admin@localhost
> :8080/etc/map
> curl -F'sling:match=http://[^/]+/imgs/(.+)/([^/]+)/r/([^/]+)$'
> -F'sling:internalRedirect=/content/images/$1/$3/jcr:content/thumbnails/$2'
> -F'jcr:primaryType=sling:Mapping' http://admin:admin@localhost
> :8080/etc/map/any
> curl -F'jcr:primaryType=sling:Folder' http://admin:admin@localhost
> :8080/content/images/2010/10/14
> curl -F'jcr:primaryType=nt:unstructured' http://admin:admin@localhost
> :8080/content/images/2010/10/14/img.jpg
> curl -F'jcr:primaryType=nt:unstructured' http://admin:admin@localhost
> :8080/content/images/2010/10/14/img.jpg/jcr:content
> curl -F'jcr:primaryType=sling:Folder' http://admin:admin@localhost
> :8080/content/images/2010/10/14/img.jpg/jcr:content/thumbnails
> curl -T 190x190 http://admin:admin@localhost
> :8080/content/images/2010/10/14/img.jpg/jcr:content/thumbnails/190x190
>
>
>
> After running the script, I can see
> http://localhost:8080/system/console/jcrresolver  has patterns that I
> need.
> But when I test it on the page (felix web console 3.1.2), I get
> NonExistingResource, path=/imgs/2010/10/14/190x190/r/img.jpg
>
> I'll have to step through this..
> Is there a way to attach debugger from eclipse?
> I started sling with:
> java -Xmx384M -Xdebug -Xnoagent -Djava.compiler=NONE
> -Xrunjdwp:transport=dt_socket,address=30303,server=y,suspend=n -jar
> org.apache.sling.launchpad.app-5-incubator.jar
>
> And on eclipse, I created a Debug Configuration that connects to
> localhost:30303 and Source Lookup Path includes
> org.apache.sling.launchpad.app-5-incubator-sources.jar
>
> But I get:
> Failed to connect to remote VM. Connection refused.
> Connection refused
>
>
>
>
>
> On Thu, Oct 14, 2010 at 7:46 PM, Justin Edelson <ju...@justinedelson.com>wrote:
>
>> This might be a typo or the source of your problem, but you have this:
>>
>> > /imgs/a/b/c/640x480/r/img.jpg
>>
>> but are requesting
>>
>> > /imgs/a/b/c/640x480/of/img.jpg
>>
>> look at the second-to-last path segment. Is "r" in the first example
>> (and your regex) and "of" in the second example.
>>
>> Justin
>>
>> On Thu, Oct 14, 2010 at 5:43 PM, sam lee <sk...@gmail.com> wrote:
>> > Hey,
>> >
>> > I want http request:
>> > GET /imgs/a/b/c/640x480/r/img.jpg
>> >
>> > to be resolved to the JCR node:
>> > /content/images/a/b/c/img.jpg/jcr:content/thumbnails/640x480
>> >
>> > I looked at:
>> > http://sling.apache.org/site/mappings-for-resource-resolution.html
>> >
>> > And, my current /etc/map is:
>> > /etc/map/any (sling:Mapping)
>> > - sling:match = http://[^/]+/imgs/(.+)/([^/]+)/r/([^/]+)$
>> > - sling:internalRedirect =
>> /content/images/$1/$3/jcr:content/thumbnails/$2
>> >
>> > But, GET /imgs/a/b/c/640x480/of/img.jpg  gives me 404.
>> > Is there something I'm doing wrong?
>> >
>> > Am I approaching the problem properly?
>> > Using regex seems brittle.
>> >
>> > If I were to write a class that knows how to convert short path to
>> actual
>> > jcr path, what interface should the class implement? And, how can I
>> register
>> > it to sling's DefaultGetServlet?
>> >
>> > Thanks.
>> > Sam
>> >
>>
>
>

Re: /etc/map to serve shorten url

Posted by sam lee <sk...@gmail.com>.
Oops, it's a typo.
Request is to "r", too.
I'll have to step through and see what's happening.

This is the script I used on org.apache.sling.launchpad.app-5-incubator.jar:

curl -F'jcr:primaryType=sling:Folder' http://admin:admin@localhost
:8080/etc/map
curl -F'sling:match=http://[^/]+/imgs/(.+)/([^/]+)/r/([^/]+)$'
-F'sling:internalRedirect=/content/images/$1/$3/jcr:content/thumbnails/$2'
-F'jcr:primaryType=sling:Mapping' http://admin:admin@localhost
:8080/etc/map/any
curl -F'jcr:primaryType=sling:Folder' http://admin:admin@localhost
:8080/content/images/2010/10/14
curl -F'jcr:primaryType=nt:unstructured' http://admin:admin@localhost
:8080/content/images/2010/10/14/img.jpg
curl -F'jcr:primaryType=nt:unstructured' http://admin:admin@localhost
:8080/content/images/2010/10/14/img.jpg/jcr:content
curl -F'jcr:primaryType=sling:Folder' http://admin:admin@localhost
:8080/content/images/2010/10/14/img.jpg/jcr:content/thumbnails
curl -T 190x190 http://admin:admin@localhost
:8080/content/images/2010/10/14/img.jpg/jcr:content/thumbnails/190x190



After running the script, I can see
http://localhost:8080/system/console/jcrresolver  has patterns that I need.
But when I test it on the page (felix web console 3.1.2), I get
NonExistingResource, path=/imgs/2010/10/14/190x190/r/img.jpg

I'll have to step through this..
Is there a way to attach debugger from eclipse?
I started sling with:
java -Xmx384M -Xdebug -Xnoagent -Djava.compiler=NONE
-Xrunjdwp:transport=dt_socket,address=30303,server=y,suspend=n -jar
org.apache.sling.launchpad.app-5-incubator.jar

And on eclipse, I created a Debug Configuration that connects to
localhost:30303 and Source Lookup Path includes
org.apache.sling.launchpad.app-5-incubator-sources.jar

But I get:
Failed to connect to remote VM. Connection refused.
Connection refused




On Thu, Oct 14, 2010 at 7:46 PM, Justin Edelson <ju...@justinedelson.com>wrote:

> This might be a typo or the source of your problem, but you have this:
>
> > /imgs/a/b/c/640x480/r/img.jpg
>
> but are requesting
>
> > /imgs/a/b/c/640x480/of/img.jpg
>
> look at the second-to-last path segment. Is "r" in the first example
> (and your regex) and "of" in the second example.
>
> Justin
>
> On Thu, Oct 14, 2010 at 5:43 PM, sam lee <sk...@gmail.com> wrote:
> > Hey,
> >
> > I want http request:
> > GET /imgs/a/b/c/640x480/r/img.jpg
> >
> > to be resolved to the JCR node:
> > /content/images/a/b/c/img.jpg/jcr:content/thumbnails/640x480
> >
> > I looked at:
> > http://sling.apache.org/site/mappings-for-resource-resolution.html
> >
> > And, my current /etc/map is:
> > /etc/map/any (sling:Mapping)
> > - sling:match = http://[^/]+/imgs/(.+)/([^/]+)/r/([^/]+)$
> > - sling:internalRedirect =
> /content/images/$1/$3/jcr:content/thumbnails/$2
> >
> > But, GET /imgs/a/b/c/640x480/of/img.jpg  gives me 404.
> > Is there something I'm doing wrong?
> >
> > Am I approaching the problem properly?
> > Using regex seems brittle.
> >
> > If I were to write a class that knows how to convert short path to actual
> > jcr path, what interface should the class implement? And, how can I
> register
> > it to sling's DefaultGetServlet?
> >
> > Thanks.
> > Sam
> >
>

Re: /etc/map to serve shorten url

Posted by Justin Edelson <ju...@justinedelson.com>.
This might be a typo or the source of your problem, but you have this:

> /imgs/a/b/c/640x480/r/img.jpg

but are requesting

> /imgs/a/b/c/640x480/of/img.jpg

look at the second-to-last path segment. Is "r" in the first example
(and your regex) and "of" in the second example.

Justin

On Thu, Oct 14, 2010 at 5:43 PM, sam lee <sk...@gmail.com> wrote:
> Hey,
>
> I want http request:
> GET /imgs/a/b/c/640x480/r/img.jpg
>
> to be resolved to the JCR node:
> /content/images/a/b/c/img.jpg/jcr:content/thumbnails/640x480
>
> I looked at:
> http://sling.apache.org/site/mappings-for-resource-resolution.html
>
> And, my current /etc/map is:
> /etc/map/any (sling:Mapping)
> - sling:match = http://[^/]+/imgs/(.+)/([^/]+)/r/([^/]+)$
> - sling:internalRedirect = /content/images/$1/$3/jcr:content/thumbnails/$2
>
> But, GET /imgs/a/b/c/640x480/of/img.jpg  gives me 404.
> Is there something I'm doing wrong?
>
> Am I approaching the problem properly?
> Using regex seems brittle.
>
> If I were to write a class that knows how to convert short path to actual
> jcr path, what interface should the class implement? And, how can I register
> it to sling's DefaultGetServlet?
>
> Thanks.
> Sam
>

Re: /etc/map to serve shorten url

Posted by Alexander Klimetschek <ak...@adobe.com>.
Knowing this is about CQ assets in particular, and I hate those URLs as well: maybe you address the asset and add a suffix for the rendition, like

/content/dam/myimage.jpg/somerendition150x150.png

Not sure if that works stable, but it's something you can add yourself (resource type dam:Asset, if no suffix, redirect to the normal asset servlet).

Cheers,
Alex

On 09.10.2014, at 00:09, Nagz <na...@gmail.com> wrote:

> Hi,
> 
> Is there way to hide /jcr:content/renditions from the url. Just an opposite
> of your scenario, below is an example
> 
> /content/dam/myimage/someimage/jcr:content/renditions/someimage150x160.png
> 
> Expected result: 
> /content/dam/myimage/someimage/someimage150x160.png
>     or
> /content/dam/myimage/someimage/$1/$2/someimage150x160.png
> 
> any inputs or help in finding the solution will be higly appreciated.
> 
> 
> 
> --
> View this message in context: http://apache-sling.73963.n3.nabble.com/etc-map-to-serve-shorten-url-tp1704238p4041415.html
> Sent from the Sling - Users mailing list archive at Nabble.com.


Re: /etc/map to serve shorten url

Posted by Nagz <na...@gmail.com>.
Hi,

Is there way to hide /jcr:content/renditions from the url. Just an opposite
of your scenario, below is an example

/content/dam/myimage/someimage/jcr:content/renditions/someimage150x160.png

Expected result: 
/content/dam/myimage/someimage/someimage150x160.png
     or
/content/dam/myimage/someimage/$1/$2/someimage150x160.png

any inputs or help in finding the solution will be higly appreciated.



--
View this message in context: http://apache-sling.73963.n3.nabble.com/etc-map-to-serve-shorten-url-tp1704238p4041415.html
Sent from the Sling - Users mailing list archive at Nabble.com.