Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to provide access to an external resource (file) for a GlassFish web application?

I am a bit of a GlassFish beginner, so please forgive my ingnorance on the subject.

Basically we are serving a game website, and to make the client downloadable by our web app we copy it into a directory within domain1. The problem with this is that when redeploying the web app the client downloadable is lost and we have to copy it across again.

I'd like to be able to store the client downloadable in some external location and have GlassFish provide access to it.

I could just hardcode the link into the web app, but then we would lose portability so that's the reason for having GlassFish handle it.

I could also put the client downloadable into our database but that seems like poor use of a database and could also result in poor database performance.

The third option I have found is to add a custom resource mapping from some name to the file location, and then provide a method in one of my beans to retrieve the file location. This seems like a lot of work just to have an external resource, I feel like there must be an easier way.

So what should I do?

like image 945
PiersyP Avatar asked Jul 16 '10 15:07

PiersyP


1 Answers

With GlassFish you can define an alternate document root to serve files from outside the war. From the documentation:

Alternate Document Roots

An alternate document root (docroot) allows a web application to serve requests for certain resources from outside its own docroot, based on whether those requests match one (or more) of the URI patterns of the web application's alternate docroots.

To specify an alternate docroot for a web application or a virtual server, use the alternatedocroot_n property, where n is a positive integer that allows specification of more than one. This property can be a subelement of a sun-web-app element in the sun-web.xml file or a virtual server property. For more information about these elements, see sun-web-app in Oracle GlassFish Server 3.0.1 Application Deployment Guide.

So you could configure something like this:

<property name="alternatedocroot_1" value="from=/ext/* dir=/path/to/ext"/>

Refer to the documentation for full details.

like image 99
Pascal Thivent Avatar answered Oct 06 '22 01:10

Pascal Thivent