Open
Description
This is for Restlet 2.3.5 JSE. I set up a simple static file server like this:
public static void main(String[] args) {
Component component = new Component();
component.getServers().add(Protocol.HTTP, 8085);
component.getClients().add(Protocol.FILE);
component.getDefaultHost().attach("", new WebApplication());
component.start();
}
class WebApplication extends Application {
public Restlet createInboundRoot() {
final Router router = new Router(getContext());
router.setDefaultMatchingMode(Template.MODE_EQUALS);
final Directory dir = new Directory(getContext(), "file:///home/me/images");
dir.setDeeplyAccessible(true);
dir.setListingAllowed(false);
dir.setNegotiatingContent(false);
router.attach("", dir);
return router;
}
}
I can now access files located in /home/me/images
. But, for inaccessible files (like chmod 000), the server returns an HTTP 404 status code (and prints an IOException with a misleading message), when I would expect it to return 403, like Apache.
java.io.IOException: Couldn't get the stream. File not found
at org.restlet.representation.FileRepresentation.getStream(FileRepresentation.java:197)
at org.restlet.representation.FileRepresentation.write(FileRepresentation.java:261)
at org.restlet.engine.adapter.ServerCall.writeResponseBody(ServerCall.java:513)
at org.restlet.engine.adapter.ServerCall.sendResponse(ServerCall.java:457)
at org.restlet.engine.adapter.ServerAdapter.commit(ServerAdapter.java:187)
at org.restlet.engine.adapter.HttpServerHelper.handle(HttpServerHelper.java:144)
at org.restlet.engine.connector.HttpServerHelper$1.handle(HttpServerHelper.java:64)
at com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:79)
at sun.net.httpserver.AuthFilter.doFilter(AuthFilter.java:83)
at com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:82)
at sun.net.httpserver.ServerImpl$Exchange$LinkHandler.handle(ServerImpl.java:675)
at com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:79)
at sun.net.httpserver.ServerImpl$Exchange.run(ServerImpl.java:647)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)