Hi,

Andreas Kollegger schrieb:
> With the current "Servlet Resolution" wiki page out-of-sync, does anyone
> have a bare-bones example of registering a servlet and/or filter with
> the Sling framework? It looks like a bundle just has to register a
> javax.servlet.Servlet service with the proper sling properties for it to
> get picked up. I've tried a simple OSGi Activator, but can't seem to get
> it to work.
> 
> Example BundleActivator.start...
> 
>     public void start( BundleContext bc )
>         throws Exception
>     {
>         Dictionary props = new Properties();
>     props.put("sling.servlet.paths", "/myservlet/html, /myservlet/txt");
>         bc.registerService( javax.servlet.Servlet.class.getName(), new
> MyServlet(), props );
>    }

This is almost correct. The property value is either a single string or
an array of strings. So your example should really be:

    props.put("sling.servlet.paths",
           new String[]{ "/myservlet/html", "/myservlet/txt" });

But since you registered with absolute paths, the resource types must
also be absolute. Thus your example (with the fix for the property
value) should work for .html and .txt requests to resources whose
resource type "/myservlet".

If your resource types are relative -- e.g. "myservlet" -- you should
register with relative paths as in :

    props.put("sling.servlet.paths",
           new String[]{ "myservlet/html", "myservlet/txt" });

or better yet to register with two properties, one for the resource type
and for the extensions supported:

    props.put("sling.servlet.resourceTypes", "myservlet");
    props.put("sling.servlet.extensions", new String[]{"html","txt"});


HTH

Regards
Felix

> 
> Thanks for any guidance,
> Andreas
> 
> 

Reply via email to