views:

50

answers:

2

Hi guys,

Is there any way of making a folder that is NOT packaged in the war file accesible via GET.

Probably setting something in web.xml ?

+4  A: 

Yes, you can use the alternatedocroot property (in Glassfish) to serve files (like images) from outside the war.

This property can be a subelement of a sun-web-app element in the sun-web.xml file or a virtual-server element in the domain.xml file

See here: http://docs.sun.com/app/docs/doc/820-4496/geqpl?l=en&a=view

example:

<property name="alternatedocroot_1" value="from=/images/* dir=/usr/gifs"/>
JoseK
This looks like what I'm looking for. Thanks.
Bogdan
+1  A: 

You could add a servlet to your application which reads the file.

Example (needs error handling)

public class FileDownloadServlet extends HttpServlet {

        protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        String filename = request.getParameter( "filename" );
        InputStream is;
        try {
            is = FileUtils.openInputStream( new File( filename ) );
            byte[] buf = new byte[ 8192 ];
            int bytesRead;
            while ( ( bytesRead = is.read( buf ) ) != -1 )
                os.write( buf, 0, bytesRead );
        }
        catch( ... ) {
        }
        finally {
            is.close();
            os.close();
        }
        response.setContentType( "application/octet-stream" );
      }
    }
stacker
+1 for a nice alternative. Thanks ;)
Bogdan