Hi All,
I'm having a little trouble getting my restlet application to serve static files
(files and directories) when deploying via Tomcat and was wondering if
anyone had any suggestions (I'm a bit of a newbie too - please bear with
me).
I've created an Application class (myApplication) that extends
org.restlet.Application and have configured it for Tomcat deployment in
web.xml as described in the ServerServlet API docs. I've also also
attached some basic path/resource combinations to a router object that's
returned by the createRoot() function of my application. So my class
looks something like:
public class myApplication extends Application {
public myApplication(){
super();
}
public myApplication(Context c){
super(c);
}
public Restlet createRoot(){
Router r = new Router(this.getContext);
r.attach("/",MyResource.class);
return r;
}
}
When deploying this servlet via tomcat, I have no problem accessing
MyResource by simply going to http://localhost:8080/ (I set my
application to be the root context).
However, I'm having trouble attaching a directory to a path.
I've tried to create and attach a directory to the router in the createRoot()
function of my class by doing something like:
this.getConnectorService().getClientProtocols().add(Protocol.FILE);
LocalReference l = LocalReference.createFileReference("/path_to/imgdir/");
Directory d = new Directory(this.getContext,l);
router.attach("/images/",d);
However, I can't seem to access the directory or it's contents after tomcat
deployment (http://localhost:8080/images/image.gif produces 404 errors).
I haven't had any problems attaching a directory when using Restlet's built
in http server. For instance, the following allows me to access a directory
and it's contents correctly...
Component component = new Component();
component.getServers().add(Protocol.HTTP, 8182);
component.getClients().add(Protocol.FILE);
LocalReference l = LocalReference.createFileReference("/path/to/images_dir/");
Directory d = new Directory(component.getContext(), l);
component.getDefaultHost().attach("/images/", d);
component.start();
(http://localhost:8182/images/image.gif works)
I'm a little stumped - I don't know if I'm creating/attaching the directory
incorrectly or maybe not adding the FILE protocol correctly. Any
suggestions/insight would be greatly appreciated.
Many thanks,
-Rob-