File Serving in JBoss 4.2.3?
Right now I am using Apache to do some very simple file serving. We also have a JBoss 4.2.3 instance that does all our application serving. I'd like to just use JBoss for everything. In Apache, I am doing the following in the httpd.conf file to perform the file serving:
Alias /reports "C:/driveReports/"
<Directory "C:/driveReports/*">
AllowOverride All
Options Indexes FollowSymLinks
Order allow,deny
Allow from all
</Directory>
Is there something equivalent I can do in JBoss to accomplish the same thing? It seems easy enough, but I haven't been able to find anything that leads me to believe there is a solution that doesn't involve Apache being linked to JBoss's Tomcat.
I know I could easily enough just move the files from their "C:/driveReports" location in to the JBoss web deployer location, but I'd rather not have t开发者_开发技巧o do that. Thanks.
Try to take help from this wiki page about static file serving.
I'm not sure if JBoss AS has some such feature out of the box. It's an application server, after all.
You may use a servlet for such purpose, similar to Jetty's default servlet, with a code such like this:
private void dispatchFileForDownload( File file, HttpServletRequest req, HttpServletResponse resp ) throws ServletException, IOException {
// Check the file existence.
if( !file.exists() )
throw new IllegalStateException("File "+file.getPath()+" does not exist.");
if( !file.isFile() )
throw new IllegalStateException("File "+file.getPath()+" is not a regular file.");
// HTTP stuff.
resp.setContentLength( (int)file.length() );
if( artifactInfo.getFileName().endsWith(".jar") )
resp.setContentType("application/java-archive");
else if( artifactInfo.getFileName().endsWith(".xml") )
resp.setContentType("text/xml");
else
resp.setContentType("application/octet-stream");
resp.setHeader("Content-Disposition", "attachment; filename="+file.getName());
ServletOutputStream os = resp.getOutputStream();
FileInputStream in = new FileInputStream(file);
IOUtils.copy(in, os);
in.close();
os.close();
}
精彩评论