Serving Directory under WEB-INF

5 messages Options
Embed this post
Permalink
Erick Fleming

Serving Directory under WEB-INF

Reply Threaded More More options
Print post
Permalink
Given the following route: router.attach("/js", new Directory(getContext, "war:///WEB-INF/js/dojorest.js"))
  
http://localhost:8080/js Returns the javascript file.

But given this route:
router.attach("/js", new Directory(getContext, "war:///WEB-INF/js"))

http://localhost:8080/js/dojorest.js does not.

Am I missing someting?
StephanKoo

Re: Serving Directory under WEB-INF

Reply Threaded More More options
Print post
Permalink
Hi Erick,

maybe the TunnelService sees the extension .js and knows, that it
typically means a JavaScript file, and overrides the accept-mime-type
with JavaScript, and eats up the ".js".
But that this is not useful for directories. You could disable this
behaviour in Application.getTunnelService().setExtensionTunnel(false)
[may be the method name differs a bit].

best regards
   Stephan

Erick Fleming schrieb:

> Given the following route: router.attach("/js", new
> Directory(getContext, "war:///WEB-INF/js/dojorest.js"))
>  
> http://localhost:8080/js Returns the javascript file.
>
> But given this route: router.attach("/js", new Directory(getContext,
> "war:///WEB-INF/js"))
>
> http://localhost:8080/js/dojorest.js does not.
>
> Am I missing someting?

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2411487
jlouvel

RE: Serving Directory under WEB-INF

Reply Threaded More More options
Print post
Permalink
Hi Erick,

I've just did a test with this code:

package test;

import org.restlet.Application;
import org.restlet.Request;
import org.restlet.Response;
import org.restlet.Restlet;
import org.restlet.resource.Directory;
import org.restlet.routing.Router;

public class MyApplication2 extends Application {

    @Override
    public Restlet createInboundRoot() {
        Router root = new Router(getContext());
        Directory dir = new Directory(getContext(), "war:///WEB-INF/js");
        root.attach("/js", dir);
        return root;
    }

    @Override
    public void handle(Request request, Response response) {
        super.handle(request, response);
    }

}

In my browser, those URIs work fine and return the content of my dojorest.js
file:
http://localhost:8080/TestMultiple/2/js/dojorest.js 
http://localhost:8080/TestMultiple/2/js/dojorest

I'm using SVN trunk.

Best regards,
Jerome Louvel
--
Restlet ~ Founder and Lead developer ~ http://www.restlet.org
Noelios Technologies ~ Co-founder ~ http://www.noelios.com




-----Message d'origine-----
De : [hidden email] [mailto:[hidden email]]
Envoyé : lundi 26 octobre 2009 20:17
À : [hidden email]
Objet : Re: Serving Directory under WEB-INF

Hi Erick,

maybe the TunnelService sees the extension .js and knows, that it
typically means a JavaScript file, and overrides the accept-mime-type
with JavaScript, and eats up the ".js".
But that this is not useful for directories. You could disable this
behaviour in Application.getTunnelService().setExtensionTunnel(false)
[may be the method name differs a bit].

best regards
   Stephan

Erick Fleming schrieb:

> Given the following route: router.attach("/js", new
> Directory(getContext, "war:///WEB-INF/js/dojorest.js"))
>  
> http://localhost:8080/js Returns the javascript file.
>
> But given this route: router.attach("/js", new Directory(getContext,
> "war:///WEB-INF/js"))
>
> http://localhost:8080/js/dojorest.js does not.
>
> Am I missing someting?

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=24114
87

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2413720
Fabian Mandelbaum

Re: Serving Directory under WEB-INF

Reply Threaded More More options
Print post
Permalink
In reply to this post by StephanKoo
Hello Jerome, Erick,

I have a similar situation, but I'd need to serve 'static' files from
inside a .jar instead.

The staticres.jar is in the classpath, and my Application's
createInboundRoot code looks like this:

public synchronized Restlet createInboundRoot() {
        Router router = new Router(getContext());
        // Files on /, public
        router.attach("/", RootFolderResource.class);
        router.attach("/{fname}.{ext}", RootFolderResource.class);
        Directory dir = new Directory(getContext(), "jar:staticres.jar!/res");
        router.attach("/res", dir);
        // Rest of the system, guarded
// Here comes the rest of the routes mapping, for all guarded resources
}

Now, if I try this in my browser:

http://localhost:9000/res/logo.png

Instead of seeing the logo, I see an error page, and in the logs I get
an HTTP 404 (not found):

INFO: Starting the internal HTTP server
05/11/2009 09:58:54 org.restlet.engine.local.DirectoryServerResource getVariants
INFO: Getting variants for : jar://staticres.jar!/res/logo.png
05/11/2009 09:58:54 org.restlet.engine.local.DirectoryServerResource doInit
INFO: Converted target URI: jar://staticres.jar!/res/logo.png
05/11/2009 09:58:54 org.restlet.engine.log.LogFilter afterHandle
INFO: 2009-11-05 09:58:54 0:0:0:0:0:0:0:1 - - 9000 GET /res/logo.png - 404 330 - 12 http://localhost:9000        Mozilla/5.0
(X11; U; Linux i686; es-AR; rv:1.9.0.15) Gecko/2009102815 Ubuntu/9.04
(jaunty) Firefox/3.0.15 -

The structure of the jar is as follows:

/META-INF
/res/logo.png
/res/other_resources_here

Any ideas? What am I doing wrong?

Thanks in advance.

On Mon, Nov 2, 2009 at 8:21 AM, Jerome Louvel <[hidden email]> wrote:

> Hi Erick,
>
> I've just did a test with this code:
>
> package test;
>
> import org.restlet.Application;
> import org.restlet.Request;
> import org.restlet.Response;
> import org.restlet.Restlet;
> import org.restlet.resource.Directory;
> import org.restlet.routing.Router;
>
> public class MyApplication2 extends Application {
>
>    @Override
>    public Restlet createInboundRoot() {
>        Router root = new Router(getContext());
>        Directory dir = new Directory(getContext(), "war:///WEB-INF/js");
>        root.attach("/js", dir);
>        return root;
>    }
>
>    @Override
>    public void handle(Request request, Response response) {
>        super.handle(request, response);
>    }
>
> }
>
> In my browser, those URIs work fine and return the content of my dojorest.js
> file:
> http://localhost:8080/TestMultiple/2/js/dojorest.js
> http://localhost:8080/TestMultiple/2/js/dojorest
>
> I'm using SVN trunk.
>
> Best regards,
> Jerome Louvel
> --
> Restlet ~ Founder and Lead developer ~ http://www.restlet.org
> Noelios Technologies ~ Co-founder ~ http://www.noelios.com
>
>
>
>
> -----Message d'origine-----
> De : [hidden email] [mailto:[hidden email]]
> Envoyé : lundi 26 octobre 2009 20:17
> À : [hidden email]
> Objet : Re: Serving Directory under WEB-INF
>
> Hi Erick,
>
> maybe the TunnelService sees the extension .js and knows, that it
> typically means a JavaScript file, and overrides the accept-mime-type
> with JavaScript, and eats up the ".js".
> But that this is not useful for directories. You could disable this
> behaviour in Application.getTunnelService().setExtensionTunnel(false)
> [may be the method name differs a bit].
>
> best regards
>   Stephan
>
> Erick Fleming schrieb:
>> Given the following route: router.attach("/js", new
>> Directory(getContext, "war:///WEB-INF/js/dojorest.js"))
>>
>> http://localhost:8080/js Returns the javascript file.
>>
>> But given this route: router.attach("/js", new Directory(getContext,
>> "war:///WEB-INF/js"))
>>
>> http://localhost:8080/js/dojorest.js does not.
>>
>> Am I missing someting?
>
> ------------------------------------------------------
> http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=24114
> 87
>
> ------------------------------------------------------
> http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2413720
>



--
Fabián Mandelbaum
IS Engineer

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2414690
jlouvel

RE: Serving Directory under WEB-INF

Reply Threaded More More options
Print post
Permalink
Hi Fabian,

It is easy to achieve using the CLAP pseudo-protocol. Use an URI like "clap://system/res/logo.png".

Of course, you need to declare a CLAP client in your parent component (or via the ServerServlet configuration).

Best regards,
Jerome Louvel
--
Restlet ~ Founder and Lead developer ~ http://www.restlet.org
Noelios Technologies ~ Co-founder ~ http://www.noelios.com



-----Message d'origine-----
De : Fabian Mandelbaum [mailto:[hidden email]]
Envoyé : jeudi 5 novembre 2009 13:28
À : [hidden email]
Objet : Re: Serving Directory under WEB-INF

Hello Jerome, Erick,

I have a similar situation, but I'd need to serve 'static' files from
inside a .jar instead.

The staticres.jar is in the classpath, and my Application's
createInboundRoot code looks like this:

public synchronized Restlet createInboundRoot() {
        Router router = new Router(getContext());
        // Files on /, public
        router.attach("/", RootFolderResource.class);
        router.attach("/{fname}.{ext}", RootFolderResource.class);
        Directory dir = new Directory(getContext(), "jar:staticres.jar!/res");
        router.attach("/res", dir);
        // Rest of the system, guarded
// Here comes the rest of the routes mapping, for all guarded resources
}

Now, if I try this in my browser:

http://localhost:9000/res/logo.png

Instead of seeing the logo, I see an error page, and in the logs I get
an HTTP 404 (not found):

INFO: Starting the internal HTTP server
05/11/2009 09:58:54 org.restlet.engine.local.DirectoryServerResource getVariants
INFO: Getting variants for : jar://staticres.jar!/res/logo.png
05/11/2009 09:58:54 org.restlet.engine.local.DirectoryServerResource doInit
INFO: Converted target URI: jar://staticres.jar!/res/logo.png
05/11/2009 09:58:54 org.restlet.engine.log.LogFilter afterHandle
INFO: 2009-11-05 09:58:54 0:0:0:0:0:0:0:1 - - 9000 GET /res/logo.png - 404 330 - 12 http://localhost:9000        Mozilla/5.0
(X11; U; Linux i686; es-AR; rv:1.9.0.15) Gecko/2009102815 Ubuntu/9.04
(jaunty) Firefox/3.0.15 -

The structure of the jar is as follows:

/META-INF
/res/logo.png
/res/other_resources_here

Any ideas? What am I doing wrong?

Thanks in advance.

On Mon, Nov 2, 2009 at 8:21 AM, Jerome Louvel <[hidden email]> wrote:

> Hi Erick,
>
> I've just did a test with this code:
>
> package test;
>
> import org.restlet.Application;
> import org.restlet.Request;
> import org.restlet.Response;
> import org.restlet.Restlet;
> import org.restlet.resource.Directory;
> import org.restlet.routing.Router;
>
> public class MyApplication2 extends Application {
>
>    @Override
>    public Restlet createInboundRoot() {
>        Router root = new Router(getContext());
>        Directory dir = new Directory(getContext(), "war:///WEB-INF/js");
>        root.attach("/js", dir);
>        return root;
>    }
>
>    @Override
>    public void handle(Request request, Response response) {
>        super.handle(request, response);
>    }
>
> }
>
> In my browser, those URIs work fine and return the content of my dojorest.js
> file:
> http://localhost:8080/TestMultiple/2/js/dojorest.js
> http://localhost:8080/TestMultiple/2/js/dojorest
>
> I'm using SVN trunk.
>
> Best regards,
> Jerome Louvel
> --
> Restlet ~ Founder and Lead developer ~ http://www.restlet.org
> Noelios Technologies ~ Co-founder ~ http://www.noelios.com
>
>
>
>
> -----Message d'origine-----
> De : [hidden email] [mailto:[hidden email]]
> Envoyé : lundi 26 octobre 2009 20:17
> À : [hidden email]
> Objet : Re: Serving Directory under WEB-INF
>
> Hi Erick,
>
> maybe the TunnelService sees the extension .js and knows, that it
> typically means a JavaScript file, and overrides the accept-mime-type
> with JavaScript, and eats up the ".js".
> But that this is not useful for directories. You could disable this
> behaviour in Application.getTunnelService().setExtensionTunnel(false)
> [may be the method name differs a bit].
>
> best regards
>   Stephan
>
> Erick Fleming schrieb:
>> Given the following route: router.attach("/js", new
>> Directory(getContext, "war:///WEB-INF/js/dojorest.js"))
>>
>> http://localhost:8080/js Returns the javascript file.
>>
>> But given this route: router.attach("/js", new Directory(getContext,
>> "war:///WEB-INF/js"))
>>
>> http://localhost:8080/js/dojorest.js does not.
>>
>> Am I missing someting?
>
> ------------------------------------------------------
> http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=24114
> 87
>
> ------------------------------------------------------
> http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2413720
>



--
Fabián Mandelbaum
IS Engineer

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2414690

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2416467