1 2 Previous Next 16 Replies Latest reply on Apr 29, 2015 7:49 AM by kiran.kumar

    Replacement for context.xml in AS7? Access files outside the WAR?

    cgaffga

      hi,

       

      I'm in big trouble migrating from AS6 to AS7, as of the missing possibility to configure the tomcat catalina container via context.xml. In AS6 I had a WEB-INF/context.xml like this to set a custom DirContext implementation:

      {code:xml}<?xml version="1.0" encoding="UTF-8"?>

      <Context allowLinking="true" cookies="true" crossContext="true" override="true">

          <Resources allowLinking="true" className="com.triplemind.site.engine.SourceResolverContext"

              homeDir="/home/myapp/files" />

      </Context>{code}

       

      This custom SourceResolverContext was wrapping the FileDirContext and made it possible for my webapp to access files not bundles with the WAR.

       

      As the context.xml file is not supported in JBoss AS 7 anymore, here my question:

      Is there any way to configure a custom "Resource" for SevletContext.getResource/AsStream()? Could I access the Catalina Container directly somehow? Then I could use Container.setResource(MyDirContextImplementation) to set it directly (maybe from within a ServletContainerInitializer). How could I look up the Catalina Container for my WAR?

       

      Or any better idea how to make files outside the WAR accessable from SevletContext.getResource()?

       

      I would appreciate any help on this topic. Thanks

        • 1. Re: Replacement for context.xml in AS7? Access files outside the WAR?
          cgaffga

          no I did a really ugly patch to JBossAS7, so far I can work with my old DirContext now.

          This is not really a solution for me

          diff --git a/web/src/main/java/org/jboss/as/web/deployment/WarDeploymentProcessor.java b/web/src/main/java/org/jboss/as/web/deployment/WarDeploym
          index fcc1165..6e015af 100644
          --- a/web/src/main/java/org/jboss/as/web/deployment/WarDeploymentProcessor.java
          +++ b/web/src/main/java/org/jboss/as/web/deployment/WarDeploymentProcessor.java
          @@ -67,6 +67,7 @@ import java.util.Collections;
           import java.util.List;
           import java.util.Map;
           import java.util.Set;
          +import java.util.logging.Logger;
           
          @@ -124,6 +125,11 @@ public class WarDeploymentProcessor implements DeploymentUnitProcessor {
                   final StandardContext webContext = new StandardContext();
                   final ContextConfig config = new JBossContextConfig(deploymentUnit);
           
          +        // TODO need a different DirContext for looking up resources...
          +        Logger log = Logger.getLogger(WarDeploymentProcessor.class.getName());
          +        log.info("initialized a new StandardContext, registering customized resources...");
          +        webContext.setResources(new MyDirContextWrapper(webContext.getResources()));
          +
                   List valves = metaData.getValves();
                   if(valves == null) {
                       metaData.setValves(valves = new ArrayList());
          
          • 2. Re: Replacement for context.xml in AS7? Access files outside the WAR?
            guinotphil

            I'm looking for a replacement too...

             

            I used to have in JBoss AS 4's server.xml some context like that :

             

            <Context path="/static"

            docBase="C:\static"

            reloadable="false"

            debug="0"

            trusted="false"/>

             

             

            I've seen that JBoss web 7 have a static resources configuration: http://docs.jboss.org/jbossweb/7.0.x/config/static.html

            But I haven't managed to find where to configure aliases....

            • 3. Re: Replacement for context.xml in AS7? Access files outside the WAR?
              cgaffga

              guinotphil wrote:

               

              I'm looking for a replacement too...

              I used to have in JBoss AS 4's server.xml some context like that :

              <Context path="/static" docBase="C:\static" reloadable="false" debug="0" trusted="false"/

              I've seen that JBoss web 7 have a static resources configuration: http://docs.jboss.org/jbossweb/7.0.x/config/static.html

              But I haven't managed to find where to configure aliases....

               

              exactly that is my problem, too. Those things are described in JbossWeb 7 documentation, but they simplay are not cinfigurable. The issue is, that the JbossWeb7 ducumentation is simply a copy of the Tomcat6 docs, anthere there this is configurable. But if you check the sources in org.jboss.as.web, you will find that the configuration is done in a different way, neigther server.xml or context.xml is read.

               

              I would be a great improvement if there would be some place to add custom context configuration like in Jboss4, 5, and 6, some place to add things theat before were stored in server.xml and context.xml.

               

              Do you think people form Jboss-Dev-Team read this here? maybe we should forward it to the Dev list...

              • 4. Re: Replacement for context.xml in AS7? Access files outside the WAR?
                jaikiran
                • 5. Re: Replacement for context.xml in AS7? Access files outside the WAR?
                  guinotphil

                  I've found something in JBoss Web  7 documentation:

                  It seems you can define context resources, see an example here:

                  http://docs.jboss.org/jbossweb/7.0.x/manager-howto.html

                   

                  The documentation referer to a conf directory, that contains the default servlet configuration:

                  http://docs.jboss.org/jbossweb/7.0.x/default-servlet.html

                   

                  The documentation refers to CATALINA_HOME:

                  http://docs.jboss.org/jbossweb/7.0.x/introduction.html

                   

                  "Toughout the docs, you may notice references to $CATALINA_HOME. In JBossWeb 7.0.x that is where the webapp are  deployed The default location in the Stanalone Server is configured by jboss.server.temp.dir normally jboss.home.dir/standalone/tmp."

                   

                  So, I'm not really sure where I should put this configuration in JBoss AS 7. Does anyone here has already configured the default servlet in AS 7 ? Thanks.

                  • 6. Re: Replacement for context.xml in AS7? Access files outside the WAR?
                    guinotphil

                    Hello,

                     

                    I've been investigating a bit the JBoss Web 7 documentation to understand how I could configure the web.xml, context.xml and server.xml.

                     

                    The documentation says: http://docs.jboss.org/jbossweb/7.0.x/index.html

                     

                    This is the top-level entry point of the documentation bundle for the JBoss Web Servlet/JSP container, which is based on the Apache Tomcat 6.0 project developed by the Apache Software Foundation.

                     

                    And the JBoss Web 7 documention, as Tomcat 6's documentation, refers to conf/server.xml :

                    http://docs.jboss.org/jbossweb/7.0.x/jndi-resources-howto.html

                     

                    For JBoss Web, these entries in per-web-application InitialContext are configured in the <Context> elements that can be specified in either $CATALINA_HOME/conf/server.xml.

                     

                    In my server, I notice the property catalina.home refers indeed to the standalone/tmp directory as stated in the documentation: http://docs.jboss.org/jbossweb/7.0.x/introduction.html

                     

                    Throughout the docs, you may notice references to $CATALINA_HOME. In JBossWeb 7.0.x that is where the webapp are  deployed The default location in the Stanalone Server is configured by jboss.server.temp.dir normally jboss.home.dir/standalone/tmp.

                     

                    However, I notice that, unlike Tomcat 6, in Jboss Web 7, in the class org.apache.catalina.startup.ContextConfig, the method init which created digesters and parsed the configuration with the method contextConfig() does no longer does that in JBoss Web 7.0.1. I guess JBoss AS expects to find the configuration elsewhere (standalone.xml probably), but where ? I must ask, as the documentation does not reflect the way JBoss Web seems to work...

                     

                     

                    Thank you

                    • 7. Re: Replacement for context.xml in AS7? Access files outside the WAR?
                      jfclere

                      The jbossweb docs is being cleaned, reference to context.xml, server.xml etc are wrong.

                      The minimal you need is under http://docs.jboss.org/jbossweb/7.0.x/config

                      1 of 1 people found this helpful
                      • 8. Re: Replacement for context.xml in AS7? Access files outside the WAR?
                        cgaffga

                        Jean-Frederic Clere wrote:

                         

                        The jbossweb docs is being cleaned, reference to context.xml, server.xml etc are wrong.

                        The minimal you need is under http://docs.jboss.org/jbossweb/7.0.x/config

                        yes, just saw that the JBoss Web docs are quite reduced now. So it seems that all the nice config options from Tomcat are gone for JBoss. As I started the thread, I can only say, that me meanwhile solved the problem with only spec-compilant solutions. Was a good move anyway, instead to depend on vendor-specific enhancements and config options.

                         

                        So all static rtesources we now handle with a "ExternalFilesServlet", that simply fetches the files needed. Everything else (facelets) we moved inside the WAR. But bad news for people that fetch their facelets, JSPs etc. from DB or some other non-filesystme source, then you still need to patch JBoss...

                        • 9. Re: Replacement for context.xml in AS7? Access files outside the WAR?
                          guinotphil

                          Does this mean that it won't be possible to configure the Default Servlet anymore ?

                          • 11. Re: Replacement for context.xml in AS7? Access files outside the WAR?
                            jfclere
                            • 12. Re: Replacement for context.xml in AS7? Access files outside the WAR?
                              guinotphil

                              I've ended up making my own servlet for this based on DefaultServlet:

                               

                              /**

                              * Servlet to serve files from a static directory

                              */

                              public class FileServingServlet extends DefaultServlet

                              {

                               

                                  public void init() throws ServletException {

                               

                                      super.init();

                                    

                                      final Hashtable<String, Object> env = new Hashtable<String, Object>();

                                      env.put(ProxyDirContext.HOST, resources.getHostName());

                                      env.put(ProxyDirContext.CONTEXT, resources.getContextName());

                                    

                                      final String docBaseProperty = getServletConfig().getInitParameter("docBaseProperty");

                                      if (docBaseProperty == null || docBaseProperty.trim().equals("")) {

                                               throw new RuntimeException("docBaseProperty parameter must not be blank");

                                     }

                                    

                                     final String docBase = System.getProperty(docBaseProperty);

                                     if (docBase == null || docBase.trim().equals("")) {

                                               throw new RuntimeException("docBase property " + docBaseProperty + " must be set");

                                     }

                                    

                                     final FileDirContext context = new FileDirContext(env);

                                     context.setDocBase(docBase);

                                    

                                     // Load the proxy dir context.

                                     resources = new ProxyDirContext(env, context);

                               

                               

                                     if (super.debug > 0) {

                                        log("FileServingServlet:  docBase=" + docBase);

                                    }

                                    

                                 }

                                 

                              }

                               

                               

                               

                              Which I use like this in the web.xml

                               

                                 <servlet>

                                      <servlet-name>fileServing</servlet-name>

                                      <servlet-class>xxxx.FileServingServlet</servlet-class>

                                      <init-param>

                                          <param-name>debug</param-name>

                                          <param-value>0</param-value>

                                      </init-param>

                                      <init-param>

                                          <param-name>listings</param-name>

                                          <param-value>false</param-value>

                                      </init-param>

                                      <init-param>

                                          <param-name>docBaseProperty</param-name>

                                          <!-- Name of the system property containg the base dir -->

                                          <param-value>my.basedir.directory</param-value>

                                      </init-param>

                                      <load-on-startup>1</load-on-startup>

                                  </servlet>

                               

                               

                                  <servlet-mapping>

                                      <servlet-name>fileServing</servlet-name>

                                      <url-pattern>/directory/*</url-pattern>

                                  </servlet-mapping>

                               

                               

                              It maps to /directory the content of the local directory specified in the System property my.basedir.directory. I use such a property because I did not want to hard code the local directory in the web.xml as it can be different in various deployement context.

                              1 of 1 people found this helpful
                              • 13. Re: Replacement for context.xml in AS7? Access files outside the WAR?
                                cgaffga

                                yes, I solved it the same way

                                • 14. Re: Replacement for context.xml in AS7? Access files outside the WAR?
                                  r.reimann

                                  Hello Jean-Frederic,

                                  Jean-Frederic Clere schrieb:

                                   

                                  The jbossweb docs is being cleaned, reference to context.xml, server.xml etc are wrong.

                                  The minimal you need is under http://docs.jboss.org/jbossweb/7.0.x/config

                                  In AS6 the "cache" attibute for the Authenticator Valves (e.g. org.apache.catalina.authenticator.BasicAuthenticator) could be configured inside context.xml.

                                  Unfortunately i couldn't find a way how to configure the cache attribute within AS7 after dessupport of context.xml. Neither the jboss-as-web_1_1.xsd nor the current docs seem to cover this.

                                   

                                  Could you please take a look into https://community.jboss.org/message/719779 and suggest a way how the principal cache can be disabled in AS7?

                                   

                                  Thanks in advance

                                  Robert

                                  1 2 Previous Next