2 Replies Latest reply on Feb 22, 2010 9:13 PM by ravindrakumar.ravindra.u.kumar.gmail.com

    Can components.properties be outside my war ?

    ravindrakumar.ravindra.u.kumar.gmail.com
      I was trying to use a wildcard entry in the components.xml.
      <
      component name="repositoryConfiguration">
      <property name="homeDirectory">@repositoryPath@</property>
      </component>

      Have the below entry in the components.properties
      repositoryPath=/home/repository/test1

      I don't want to keep the components.properties inside the <warFile>/WEB-INF/classes.  I have to keep it at the $<domainDir>/cfg.
      So mentioned the path for the property while setting the classpath. But for some reason, it is not able to detect the file.
      I am getting the below error:
      <Feb 16, 2010 3:29:34 PM MST> <Warning> <HTTP> <BEA-101162> <User defined listener org.jboss.seam.servlet.SeamListener failed: java.lang.RuntimeException: error while reading /WEB-INF/components.xml.
      java.lang.RuntimeException: error while reading /WEB-INF/components.xml
              at org.jboss.seam.init.Initialization.initComponentsFromXmlDocument(Initialization.java:221)
              at org.jboss.seam.init.Initialization.create(Initialization.java:124)
              at org.jboss.seam.servlet.SeamListener.contextInitialized(SeamListener.java:34)
              at weblogic.servlet.internal.EventsManager$FireContextListenerAction.run(EventsManager.java:458)
              at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
              Truncated. see log file for complete stacktrace
      java.lang.IllegalArgumentException: null value
              at org.jboss.seam.util.Conversions$FlatPropertyValue.<init>(Conversions.java:291)
              at org.jboss.seam.init.Initialization.getPropertyValue(Initialization.java:622)
              at org.jboss.seam.init.Initialization.installComponentFromXmlElement(Initialization.java:501)
              at org.jboss.seam.init.Initialization.installComponentsFromXmlElements(Initialization.java:266)
              at org.jboss.seam.init.Initialization.initComponentsFromXmlDocument(Initialization.java:217)
              Truncated. see log file for complete stacktrace
      >
      <Feb 16, 2010 3:29:35 PM MST> <Error> <Deployer> <BEA-149231> <Unable to set the activation state to true for the application '_appsdir_drools-guvnor_war'.
      weblogic.application.ModuleException:
              at weblogic.servlet.internal.WebAppModule.startContexts(WebAppModule.java:975)
              at weblogic.servlet.internal.WebAppModule.start(WebAppModule.java:361)
              at weblogic.application.internal.flow.ModuleStateDriver$3.next(ModuleStateDriver.java:204)
              at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:26)
              at weblogic.application.internal.flow.ModuleStateDriver.start(ModuleStateDriver.java:60)
              Truncated. see log file for complete stacktrace
      java.lang.IllegalArgumentException: null value
              at org.jboss.seam.util.Conversions$FlatPropertyValue.<init>(Conversions.java:291)
              at org.jboss.seam.init.Initialization.getPropertyValue(Initialization.java:622)
              at org.jboss.seam.init.Initialization.installComponentFromXmlElement(Initialization.java:501)
              at org.jboss.seam.init.Initialization.installComponentsFromXmlElements(Initialization.java:266)
              at org.jboss.seam.init.Initialization.initComponentsFromXmlDocument(Initialization.java:217)
              Truncated. see log file for complete stacktrace
        • 1. Re: Can components.properties be outside my war ?
          dan.j.allen

          I've looked into this and was able to prove that it is indeed possible. But there are two things you need to ensure:



          1. components.properties is visible to the current thread's context classloader

          2. components.properties cannot be present inside the WAR or else it will shadow the one outside of the WAR (Seam doesn't merge)



          I would advise you first to enable the DEBUG level for the category org.jboss.seam.util.Resources and verify that the components.properties is being found. If it is being found, Seam may be finding the wrong one. If it is not being found, then it is not available to the context classloader.


          I notice you are using Weblogic. I'll give you the JBoss AS equivalent. JBoss AS makes the following server directory available to the context classloader:


          $JBOSS_HOME/server/$DOMAIN/conf



          So I can put components.properties in that directory and Seam will load it properly.


          Here is the logic that Seam uses to locate the components.properties file:


          Resources.getResourceAsStream("/components.properties", servletContext);
          
          public static InputStream getResourceAsStream(String resource, ServletContext servletContext) {  
             String stripped = resource.startsWith("/") ? resource.substring(1) : resource;
                       
             InputStream stream = null;
             ...
             if (stream==null) {
                stream = getResourceAsStream(resource, stripped);
             }
             return stream;
          }
          
          static InputStream getResourceAsStream(String resource, String stripped) {  
             ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
             InputStream stream = null;
             if (classLoader!=null) {
                stream = classLoader.getResourceAsStream(stripped);
                if (stream !=null) {
                   log.debug("Loaded resource from context classloader: " + stripped);
                }
             }
                
             if (stream == null) {
                stream = Seam.class.getResourceAsStream(resource);
                if (stream !=null) {
                   log.debug("Loaded resource from Seam classloader: " + resource);
                }
             }
          
             if (stream == null) {
                stream = Seam.class.getClassLoader().getResourceAsStream(stripped);
                if (stream!=null) {
                   log.debug("Loaded resource from Seam classloader: " + stripped);
                }
             }
          
             return stream;
          }



          You should be able to take this code and write your own component to debug what is going on. Once you are able to load the components.properties successfully in your own code, then you can turn it back over to Seam.

          • 2. Re: Can components.properties be outside my war ?
            ravindrakumar.ravindra.u.kumar.gmail.com
            Hi Dan,

            Thank you for your response.
            That would have been fairly simple, if I had tried to put the components.properties in
            $domain/config .


            Right now the issue is resolved. What I did was I took the source code for jboss-seam-2.1.0.GA.jar 

            Changed the org.jboss.seam.init.Initialization.java, to point to the resourcebundle from the fileinputstream, and not the servletContext.

            So changed the below line:
            Resources.getResourceAsStream("/components.properties", servletContext);
            to
            new FileInputStream(".//<user_defined_path>//config//components.properties");

            and put the compiled class back in the jboss-seam-2.1.0.GA.jar.

            It works fine now.


            Thank you for your response