Thierry,
Thanks -- I knew I was missing something simple :-)
Best,
Jeff
On 4/4/07, Thierry Boileau <[EMAIL PROTECTED]> wrote:
Hello Jeff,
your application has been instantiated with its parent context, i.e the
one of the component.
You should proceed like this
component.getDefaultHost().attach("", new
TestApplication(component.getContext()));
Best regards,
Thierry Boileau
> Hey All,
>
> I'm trying simply to access some files in a directory and am getting a
> NPE in the ApplicationDispatcher.handle method.
>
> Here's my example:
>
> TestLauncher.java
>
> import org.restlet.Component ;
> import org.restlet.data.Protocol;
>
> public class TestLauncher {
>
> public static void main(String[] args) {
> try {
> Component component = new Component();
> component.getServers ().add(Protocol.HTTP, 8181);
> component.getClients().add(Protocol.FILE);
>
> component.getDefaultHost().attach("", new
TestApplication());
>
> component.start();
> }
> catch (Exception e) {
> e.printStackTrace();
> }
> }
> }
>
> TestApplication.java
>
> import org.restlet.Application;
> import org.restlet.Directory ;
> import org.restlet.Restlet;
> import org.restlet.Router;
>
> public class TestApplication extends Application {
>
> @Override
> public Restlet createRoot() {
> Router rootRouter = new Router();
>
> Directory imagesDirectory = new Directory(getContext(),
> "file:///C:/images/");
> rootRouter.attach("/images/", imagesDirectory);
>
> return rootRouter;
> }
> }
>
> And this is the error I get on every request to
> http://localhost:8181/images/somefile.gif
>
> java.lang.NullPointerException
> at
> com.noelios.restlet.application.ApplicationDispatcher.handle(
ApplicationDispatcher.java:81)
> at
> com.noelios.restlet.TemplateDispatcher.handle(TemplateDispatcher.java
:89)
> at org.restlet.Uniform.handle (Uniform.java:97)
> at org.restlet.Uniform.get(Uniform.java:74)
> at
> com.noelios.restlet.local.DirectoryResource.<init>(
DirectoryResource.java:142)
> at com.noelios.restlet.Engine.createDirectoryResource
> (Engine.java:253)
> at org.restlet.Directory.findTarget(Directory.java:145)
> at org.restlet.Finder.handle(Finder.java:268)
> at org.restlet.Filter.doHandle(Filter.java:105)
> at org.restlet.Filter.handle (Filter.java:134)
> at org.restlet.Router.handle(Router.java:441)
> at org.restlet.Filter.doHandle(Filter.java:105)
> at org.restlet.Filter.handle(Filter.java:134)
> at org.restlet.Filter.doHandle(Filter.java :105)
> at com.noelios.restlet.StatusFilter.doHandle(StatusFilter.java:87)
> at org.restlet.Filter.handle(Filter.java:134)
> at org.restlet.Filter.doHandle(Filter.java:105)
> at org.restlet.Filter.handle (Filter.java:134)
> at
> com.noelios.restlet.application.ApplicationHelper.handle(
ApplicationHelper.java:92)
> at org.restlet.Application.handle(Application.java:290)
> at org.restlet.Filter.doHandle(Filter.java :105)
> at org.restlet.Filter.handle(Filter.java:134)
> at org.restlet.Router.handle(Router.java:441)
> at org.restlet.Filter.doHandle(Filter.java:105)
> at org.restlet.Filter.handle(Filter.java:134)
> at org.restlet.Router.handle(Router.java:441)
> at org.restlet.Filter.doHandle(Filter.java:105)
> at com.noelios.restlet.StatusFilter.doHandle(StatusFilter.java:87)
> at org.restlet.Filter.handle(Filter.java :134)
> at org.restlet.Filter.doHandle(Filter.java:105)
> at org.restlet.Filter.handle(Filter.java:134)
> at
> com.noelios.restlet.component.ComponentHelper.handle(
ComponentHelper.java:115)
> at org.restlet.Component.handle (Component.java:228)
> at org.restlet.Server.handle(Server.java:266)
> at com.noelios.restlet.ServerHelper.handle(ServerHelper.java:99)
> at
> com.noelios.restlet.http.HttpServerHelper.handle(HttpServerHelper.java
> :94)
> at
> com.noelios.restlet.ext.jetty.JettyServerHelper$WrappedServer.handle(
JettyServerHelper.java:232)
> at
> org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:458)
> at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete
> (HttpConnection.java:776)
> at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:500)
> at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:209)
> at org.mortbay.jetty.HttpConnection.handle ( HttpConnection.java
:358)
> at
> org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java
:336)
> at
> org.mortbay.thread.BoundedThreadPool$PoolThread.run(
BoundedThreadPool.java:442)
>
> I'm using Jetty and the latest code (downloaded yesterday) from
> http://www.restlet.org/downloads/1.0/current. zip
> <http://www.restlet.org/downloads/1.0/current.zip>
>
> Am I missing something here?
>
> Thanks,
> Jeff