Skip to main content

Can I mapping an external directory to appear within the webapp?

5 replies [Last post]
whartung
Offline
Joined: 2003-06-13

Simple example.

I have mywebapp.war.

It gets deployed to: http://host/mywebapp

Now, say I have an images directory on the file system (say /usr/local/data/images), and inside that is img.gif.

In GF1.x, can I do anything so that I can have a url like: http://host/mywebapp/images/img.gif?

Map that external directory within the URL space of my web app as if the data we actually bundled with my WAR?

Most importantly, can I then map a filter in my application to /images and have it fire before the system tries to serve up any data from this external resource?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
whartung
Offline
Joined: 2003-06-13

Thanx Jan.

Do these mappings honor Servlet filter?

If I have a filter on "*.jpg", will that filter fire before the container serves up the resource like it would for an internal static resource??

Jan Luehe

glassfish@javadesktop.org wrote On 03/23/07 06:04 PM,:

>Thanx Jan.
>
>Do these mappings honor Servlet filter?
>
>If I have a filter on "*.jpg", will that filter fire before the container serves up the resource like it would for an internal static resource??
>
>

Yes, of course.

The alternate mappings are considered only by the following
javax.servlet.ServletContext methods:

getRealPath(String path)
getResource(String path)
getResourceAsStream(String path)

Jan

>[Message sent by forum member 'whartung' (whartung)]
>
>http://forums.java.net/jive/thread.jspa?messageID=209708
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
>For additional commands, e-mail: users-help@glassfish.dev.java.net
>
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: users-help@glassfish.dev.java.net

Jan Luehe

glassfish@javadesktop.org wrote On 03/16/07 03:10 PM,:

>Simple example.
>
>I have mywebapp.war.
>
>It gets deployed to: http://host/mywebapp
>
>Now, say I have an images directory on the file system (say /usr/local/data/images), and inside that is img.gif.
>
>In GF1.x, can I do anything so that I can have a url like: http://host/mywebapp/images/img.gif?
>
>Map that external directory within the URL space of my web app as if the data we actually bundled with my WAR?
>
>

Currently, we support this feature only for a virtual server's root context
(docroot), via alternate docroot settings.

See Item 4. (Alternate Docroots) at

http://blogs.sun.com/jluehe/entry/virtual_hosting_features_in_glassfish

and this forum thread:

http://forums.java.net/jive/thread.jspa?messageID=207031

We will support this feature for regular webapps as a future extension.

Jan

>Most importantly, can I then map a filter in my application to /images and have it fire before the system tries to serve up any data from this external resource?
>[Message sent by forum member 'whartung' (whartung)]
>
>http://forums.java.net/jive/thread.jspa?messageID=208519
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
>For additional commands, e-mail: users-help@glassfish.dev.java.net
>
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: users-help@glassfish.dev.java.net

Jan Luehe

Jan Luehe wrote On 03/16/07 03:43 PM,:

>
>
> glassfish@javadesktop.org wrote On 03/16/07 03:10 PM,:
>
>> Simple example.
>>
>> I have mywebapp.war.
>>
>> It gets deployed to: http://host/mywebapp
>>
>> Now, say I have an images directory on the file system (say
>> /usr/local/data/images), and inside that is img.gif.
>>
>> In GF1.x, can I do anything so that I can have a url like:
>> http://host/mywebapp/images/img.gif?
>>
>> Map that external directory within the URL space of my web app as if
>> the data we actually bundled with my WAR?
>>
>>
>
> Currently, we support this feature only for a virtual server's root
> context
> (docroot), via alternate docroot settings.
>
> See Item 4. (Alternate Docroots) at
>
> http://blogs.sun.com/jluehe/entry/virtual_hosting_features_in_glassfish
>
> and this forum thread:
>
> http://forums.java.net/jive/thread.jspa?messageID=207031
>
> We will support this feature for regular webapps as a future extension.

"Future" as in "now" (available in tonight's nightly v2 build). :)

Alternate docroots of a webapp are configured as properties in
sun-web.xml, using the same syntax as the virtual server properties
used for configuring alternate docroots for virtual servers.

I've attached the sun-web.xml of an imaginary webapp "myapp" deployed
at http://:
/myapp, which specifies exact, extension, and
path prefix URI patterns for the webapp's alternate docroots.

The exact matching pattern will map

http://:
/myapp/my.jpg

to

/svr/images/jpg/my.jpg

while the extension and path prefix pattern will cause any requests of
the form:

http://:
/myapp/*.jpg

and

http://:
/myapp/jpg/*

respectively, to be served from this directory:

/svr/images/jpg

For example,

http://:
/myapp/abc/def/my.jpg

will be mapped to:

/srv/images/jpg/abc/def/my.jpg

I am going to post a blog with more detailed info, but thought you
might be interested to learn about this feature sooner.

Jan

[sun-web.xml]
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: users-help@glassfish.dev.java.net

Jan Luehe

>>
>> glassfish@javadesktop.org wrote On 03/16/07 03:10 PM,:
>>
>>> Simple example.
>>>
>>> I have mywebapp.war.
>>>
>>> It gets deployed to: http://host/mywebapp
>>>
>>> Now, say I have an images directory on the file system (say
>>> /usr/local/data/images), and inside that is img.gif.
>>>
>>> In GF1.x, can I do anything so that I can have a url like:
>>> http://host/mywebapp/images/img.gif?
>>>
>>> Map that external directory within the URL space of my web app as if
>>> the data we actually bundled with my WAR?
>>>
>>

This is supported as of GlassFish v2, build 40.

See

http://blogs.sun.com/jluehe/entry/alternate_docroots_in_web_applications

for details.

Jan

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: users-help@glassfish.dev.java.net