Skip to main content

[webtier] Re: serving images with glassfish

2 replies [Last post]
Anonymous

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Jan Luehe

On 01/30/09 09:59, glassfish@javadesktop.org wrote:
> I guess I'm confused.
>
> Why aren't you simply letting GF serve the images for you? i.e. why are you streaming at all? Are the images not part of your application?
>
> How is mod_jk et al relevant to this issue?
>
> Glassfish has "alternate doc roots" which will let you "mount" directories within your web app.
>
> Let's take a simple example.
>
> Let's say that you want to have a directory in your Webapp for external images.
>
> We'll place that directory at /ext_images.
>
> So, http://example.com/yourapp/ext_images/picture.png would be the URL for an image.
>
> On your disk, you will create the directory "/var/altdocroot/ext_images" and simply copy your image files in to that directory.
>
> Then, you would add the following to your sun-web.xml:
>
> [code]
>
> External Image mapping
>
> [/code]
>
> Trust me on this, this is the most aggravating bit of configuration, but it does work.
>
> Let me explain.
>
> First, "alternatedocroot_1" is a key word for the property that GF looks for. If you want more mappings, just use _2, _3, etc.
>
> Value is the point, WITHIN YOUR WEB APP that you want to "mount" the external directory.
>
> Dir is the "root" of that external directory.
>
> And here's the nut.
>
> What folks think is happening is that the web app directory "/ext_images" (in this case) is the same as "/var/altdocroot". And that's not the case, and it's not obvious either.
>
> Rather, "/var/altdocroot" is exactly that -- a DOC ROOT. When GF get a URL for /ext_images, it will prepend the alternate docroot, /var/altdocroot, to the URL. Thus /ext_images becomes /var/altdocroot/ext_images.
>
> So, for our example of http://example.com/yourapp/ext_images/picture.png, that in fact gets mapped to "/var/altdocroot/ext_images/picture.png".
>
> When first playing with this everyone (everyone!) gets it wrong right out the gate, and it can be tricky to debug.
>

Thanks for your great response to the user, Will!

I've also blogged about this common "misconception", see

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

Hopefully, the blog entry and your response on the forum will help clear any
misunderstandings.

Jan

> So, hopefully this will explain how to set it up and how it works so that you can use it first time.
>
> Once you've mounted this external directory using the alternatedocroot, then GF will simply serve those files up for you just like any other static resource. It's a great facility to let you separate your WAR application from a large amount of static data that you don't want to have to constantly recopy and redeploy.
> [Message sent by forum member 'whartung' (whartung)]
>
> http://forums.java.net/jive/thread.jspa?messageID=329272
>
> ---------------------------------------------------------------------
> 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: webtier-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: webtier-help@glassfish.dev.java.net

dominic_mcginnis
Offline
Joined: 2009-01-13
Points: 0

Hi, Is it possible to utilize JSTL and system properties within the sun-web.xml for the alternate docroot? Since our application will be deployed for multiple scenarios, this could change on each and I'd rather have a system property that is altered as opposed to a hard coded path within the sun-web.xml, currenlty it appears that it cannot (or rather it didn't translate my paramater).

Example: System property defined as: my_alt_docroot=/var/altdocroot

Then in sun-web.xml:

External Text Directory Mapping

What I am seeing is the following error:
[#|2009-02-06T21:08:32.878-0800|SEVERE|sun-appserver9.1|org.apache.catalina.core.StandardContext|_ThreadID=13;_ThreadName=pool-1-thread-13;_RequestID=a713cc60-6135-40f2-bc9d-c37466c1c3a2;|PWC4430: Document base /opt/glassfish/nodeagents/g1-a1/g1-i1/${my_alt_docroot}/text does not exist or is not a readable directory|#]

On the above, /opt/glassfish/nodeagents/g1-a1/g1-i1 is the ${com.sun.aas.instanceRoot} so I'm not certain why that is trying to factor into the equation as I don't have that there...

On a side note my context root is "/", does this have any affect?