Hi,

I'm playing around with setting up a Maven repository using Sling. The
basic setup is to have a /content/maven
[sling:resourceType=sling/maven/repo] sling:Folder and then the whole
repository contents as nt:folder and nt:file objects.

Serving files with the default GET servlet works perfectly, but uploads
(using PUT) do not, since parent directories are not auto-created. I am
reluctat to extend the Simple WebDav Servlet since that's not always
deployed; I would rather use something that is always available.

So I came up with the idea of serving the repository using suffixes,
e.g.

/content/maven.html/org/apache/sling/sling-foo/1.0/sling-foo-1.0.jar

would actually serve 

/content/maven.html/org/apache/sling/sling-foo/1.0/sling-foo-1.0.jar

Note that I am breaking the pattern of referencing the whole resource
path in the suffix, since that looks awkward. But it's not a big deal.

I would like to resources to be served by the default GET servlet,
since it contains lots of logic and optimisation around downloads.
However, I did not yet find a very good way to do so.

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.DefaultGetServlet)")
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.

However, both steps seems brittle to me.

Does anyone have any suggestions on how to improve this solution?

Thanks,
Robert

Reply via email to