RESTLET - Serving static content with Server Component

446 Views Asked by At

I have a problem when trying to use the org.restlet.Server Component to serve static content when using the Restlet Framework.

When I ran the following code, I get: HTTP ERROR: 404

Problem accessing /. Reason:

Not Found

Restlet throws the following exception: Unable to start the Restlet

java.lang.IllegalArgumentException: Relative references are only usable when a base reference is set. at org.restlet.data.Reference.getTargetRef(Reference.java:1954) at org.restlet.resource.Directory.(Directory.java:125)

My code is as below. I am using Restlet 2.3.9 JSE on Java 1.8JDK, Linux 64

public static final String ROOT_URI = "/home/user/templates/"; 
public class myApplication extends Application{

    Server app = new Server (Protocol.HTTP, 8110);
    app.getProtocols().add(Protocol.FILE);

    app.setNext(new myApplication());
    app.start();
}

@Override
 public Restlet createInboundRoot(){
      Router router = new Router(getContext());
      System.out.println("Inbound");

    Directory directory = new Directory(getContext(), ROOT_URI);
    directory.setListingAllowed(true);
    directory.setDeeplyAccessible(true);        
    router.attach("/",directory);       
    return router;
   }
}
0

There are 0 best solutions below