JBoss6 serve external file static content docBase vhost
Par PlaceOweb le vendredi, novembre 11 2011, 18:32 - JAVA - Lien permanent
There are no more "virtual directories" in JBoss 6. Apparently this went out with JBoss 5. The only availables options or solutions I've found are :
- Way 1 : using 2 war, one for your project, one other to publish static files (under another
- Way 2 : symlink (to a simple file system or on a war folder with inside a blank /WEB-INF)
Using ExternalDirectories doesn't work with JBoss 6
<Host name="localhost" ...> <!-- ADD static images DIRECTORY --> <Context path="/images" docBase="/home/myuser/images" reloadable="true"> </Context> <!-- The rest of your Host entity --> </Host>
This Context deployement result :
ERROR [AbstractKernelController] Error installing to Start: name=WebServer state=Create: org.jboss.xb.binding.JBossXBException: Failed to parse source: xml_stream@163,112 Caused by: org.jboss.xb.binding.JBossXBRuntimeException: DefaultContext not found as a child of Host in unordered_sequence: Listener* Valve* Alias* Realm? attributes? Caused by: org.jboss.xb.binding.JBossXBRuntimeException: Context not found as a child of Host in unordered_sequence: Listener* Valve* Alias* Realm? attributes? Caused by: org.jboss.xb.binding.JBossXBRuntimeException: Context not found as a child of Context in unordered_sequence: Valve* Parameters* Loader? Overlay* InstanceListener* WrapperListener* Listener* SessionCookie? WrapperLifecycle* Manager? Realm? attributes? Resources? DEPLOYMENTS IN ERROR: Deployment "WebServer" is in error due to the following reason(s): **ERROR**, org.jboss.xb.binding.JBossXBRuntimeException: DefaultContext not found as a child of Host in unordered_sequence: Listener* Valve* Alias* Realm? attributes? Deployment "jboss.web:service=WebServer" is in error due to the following reason(s): ** NOT FOUND Depends on 'jboss.web:service=WebServer' **
Solution : Way 1
Under you war (unzipped when deployed), in file "myProject\WebContent\WEB-INF\jboss-web.xml"
<?xml version="1.0" encoding="UTF-8"?> <!-- http://www.jboss.org/schema/jbossweb/jboss-web_6_0.xsd --> <jboss-web xmlns="http://www.jboss.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.jboss.com/xml/ns/javaee http://www.jboss.org/j2ee/schema/jboss-web_6_0.xsd" version="6.0"> <context-root>/files</context-root> <virtual-host>publicweb1</virtual-host> </jboss-web>
With your backoffice, write in this unzipped deployed war, to serve static files.
Solution : Way 2
Adding allowLinking="true" in Jboss context (C:\jboss-6.1.0.Final\server\default\deploy\jbossweb.sar\context.xml)
<Context cookies="true" crossContext="true" allowLinking="true">
...
or only in your project (DeployedProject\WebContent\WEB-INF\context.xml)
<Context allowLinking="false"> </Context>
All others context (with or not vhost) inherit the attribute allowLinking="true" and the symbolic link is working inside my DeployedProject.war/mySymLink
Adding the system symbolic link : DeployedProject.war/mySymLink linked to /tmp
DeployedProject.war# ln -s /tmp mySymLink
Now, you can access to http://localhost:8080/DeployedProject/mySymLink/myPicture.jpg and myPicture.jpg is stored in /tmp/myPicture.jpg
Enjoy, and if you can solve this problem without symlink...
An alternative way to returning files outside war, seem to be using a servlet, for get and return external file system... not try, but exemples in followings links.
External Static Directories Ressources
- Community > Wiki > ExternalDirectories
- How to serve the images in JBoss faster
- JBoss 6 Virtual Directory-Virtual Path
- tomcat server.xml configuration not working as expected.
- jboss with website root which sits deep in the app
- Serving Static Content JBoss5.0.0.GA
- Legacy JBoss Application Server 6 : JBAS-2290 : TomcatDeployer should look for context.xml in META-INF as well as WEB-INF
- stackoverflow
- Simplest way to serve static data from outside the application server in a Java web application
- External Directory mapping in jboss-6.0.0.Final?
- jboss 6 virtual directory There are no more 'virtual directories' in JBoss 6. Apparently this went out with JBoss 5. The only available option or solution I've found are: symlink on a war folder with inside a blank /WEB-INF/web.xml
- jbossweb
- The Resources Component The Resources element represents the web application static resources, from which classes will be loaded, HTML, JSP and the other static files will be served. Note: Running a webapp with non-filesystem based Resources implementations is only possible when the webapp does not rely on direct filesystem access to its own resources, and uses the methods in the ServletContext interface to access them.
- The Context Container The Context element represents a web application, which is run within a particular virtual host.
- docBase : The Document Base (also known as the Context Root) directory for this web application, or the pathname to the web application archive file (if this web application is being executed directly from the WAR file). You may specify an absolute pathname for this directory or WAR file, or a pathname that is relative to the appBase directory of the owning Host.
- path : The context path of this web application, which is matched against the beginning of each request URI to select the appropriate web application for processing. All of the context paths within a particular Host must be unique. If you specify a context path of an empty string (""), you are defining the default web application for this Host, which will process all requests not assigned to other Contexts. The value of this field must not be set except when statically defining a Context in server.xml, as it will be inferred from the filenames used for either the .xml context file or the docBase.
- http://docs.jboss.org/jbossas/docs/
- The JBoss 4 Application Server Web Developer Reference : JBoss AS 4.0.5
- The server.xml file
- Setting the context root of a web application
- Setting up Virtual Hosts
- Serving Static Content
- The JBoss 4 Application Server Guide : JBoss AS 4.0.3
- Web Applications
- Serving Static Content: JBoss provides a default application that serves content for the root application context. This default context is the ROOT.war application in the jbossweb-tomcat50.sar directory. You can serve static files not associated with any other application by adding that content to the ROOT.war directory. For example, if you want to have a shared image directory you could create an image subdirectory inside of ROOT.war and place the images there. You could then access an image named myimage.jpg at http://localhost:8080/images/myimage.jpg.
- Tomcat
- 5.5
- The Context Container
- The Host Container
- 6
- The Context Container
- The Host Container
- 7
- The Context Container
- The Resources Component
Which tomcat is embedded in jboss6
With jboss-6.1.0.Final, headers are :
Server Apache-Coyote/1.1 X-Powered-By Servlet/3.0; JBossAS-6
On failure page, signature are :
JBoss Web/3.0.0-CR2
- Tomcat version within JBoss? from JBoss 4.2 and upwards, it doesn't come bundled with Tomcat, but a forked version of it, called JBossWeb
- VersionOfTomcatInJBossAS
- 4.2.3 JBoss Web 2.0.1
- 6.0.0 JBoss Web 3.0.0-CR1
- 6.1.0 JBoss Web/3.0.0-CR2
- VersionOfTomcatInJBossAS
- JBoss Web : Changelog
Jmx console
- http://localhost:8080/jmx-console/
- jboss.web
- J2EEApplication=none,J2EEServer=none,j2eeType=WebModule,name=//localhost/Test6
- jboss.web
docBase /jboss-6.1.0.Final/server/default/deploy/Test6.war The document root for this web application workDir work/jboss.web/localhost/Test6 statisticsProvider Performance statistics support for this managed object ( )True (X)False engineName jboss.web Name of the engine domain, if different from the context domain modelerType org.apache.catalina.core.StandardContext Type of the modeled resource. Can be set only once crossContext (X)True ( )False welcomeFiles index.html index.htm index.jsp default.html default.htm default.jsp The welcome files for this context staticResources (javax.naming.directory.DirContext) org.apache.naming.resources.ProxyDirContext@49c79f50 Static resources associated with the context. path /Test6 The context path for this Context deploymentDescriptorString deployment descriptor override ( )True (X)False The DefaultContext override flag for this web application cachingAllowed (X)True ( )False Should we cache static resources for this webapp namingContextListener (org.apache.catalina.core.NamingContextListener) javax.management.ReflectionException: Cannot find getter method getNamingContextListener Associated naming context listener. privileged ( )True (X)False Access to tomcat internals allowLinking ( )True (X)False Allow symlinking to outside the webapp root directory, if the webapp is an exploded directory Test6 index.html index.htm index.jsp default.html default.htm default.jsp
Trying to change any value return : "An error has occurred."
ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/jmx-console].[HtmlAdaptor]] (http-0.0.0.0-8080-8) "Servlet.service()" pour la servlet HtmlAdaptor a généré une exception: java.lang.NoSuchMethodException: org.apache.catalina.core.StandardContext.setEventProvider(boolean)
DefaultServlet
DefaultServlet
<servlet-class>org.apache.catalina.servlets.DefaultServlet</servlet-class>
org.apache.catalina.servlets.DefaultServlet.java
https://issues.apache.org/bugzilla/...
Listener Valve Alias Realm
- apache-tomcat-6.0.26-src » org.apache » catalina » storeconfig » StandardHostSF
* Store the specified Host properties and childs * (Listener,Alias,Realm,Valve,Cluster, Context)
- JBoss 6.1.0.Final
- org.jboss.web.tomcat.service.deployers.JBossContextConfig
- jbossweb 3.0.0-CR2 : org.apache.catalina.startup.ContextConfig
- org.jboss.web.tomcat.service.deployers.TomcatService
- JBoss 5.1.0.GA
- org.jboss.web.tomcat.service.deployers.JBossContextConfig
- org.jboss.web.tomcat.service.deployers.TomcatService