3 Replies Latest reply on Oct 28, 2008 10:54 AM by Enrico Drusiani

    Loading configuration files via JNDI

    Enrico Drusiani Newbie

      Hi

      I'm trying to load configuration files (both xml and properties) via JNDI, cause i can't rely, for this application, on paths and filesystems.

      this is the java code

      Context initCtx = new InitialContext();
      Context envCtx = (Context) initCtx.lookup("java:comp/env");
      
      Properties prop = (Properties) envCtx.lookup("file/clientconfig");
      File f = (File) envCtx.lookup("file/xmlconfig");
      



      jboss-web.xml
      <?xml version="1.0" encoding="UTF-8"?>
      <jboss-web>
      <resource-ref>
      <res-ref-name>file/clientconfig</res-ref-name>
      <res-type>java.util.Properties</res-type>
      <jndi-name>java:comp/env/file/clientconfig</jndi-name>
      </resource-ref>
      
      <resource-ref>
      <res-ref-name>file/xmlconfig</res-ref-name>
      <res-type>java.io.File</res-type>
      <jndi-name>java:comp/env/file/xmlconfig</jndi-name>
      </resource-ref>
      </jboss-web>
      


      web.xml
      <resource-ref>
      <description>
      file di property
      </description>
      <res-ref-name>file/clientconfig</res-ref-name>
      <res-type>java.util.Properties</res-type>
      <res-auth>Container</res-auth>
      </resource-ref>
      
      <resource-ref>
      <description>
      file di property
      </description>
      <res-ref-name>file/xmlconfig</res-ref-name>
      <res-type>java.io.File</res-type>
      <res-auth>Container</res-auth>
      </resource-ref>
      


      context.xml
      <?xml version="1.0" encoding="UTF-8"?>
      <!-- The contents of this file will be loaded for each web application -->
      <Context>
      <Resource name="file/xmlconfig" auth="Container"
      type="java.io.File"
      />
      
      <Resource name="file/clientconfig" auth="Container"
      type="java.util.Properties"
      />
      
      </Context>
      


      and this is the error i get...

      16:27:46,078 ERROR [ExceptionFilter] uncaught exception
      javax.servlet.ServletException: java.lang.StackOverflowError
      at javax.faces.webapp.FacesServlet.service(FacesServlet.java:158)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      at org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:147)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      at org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:63)
      at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
      at org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:49)
      at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:57)
      at org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:49)
      at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:79)
      at org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:49)
      at org.jboss.seam.web.SeamFilter.doFilter(SeamFilter.java:84)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
      at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
      at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:432)
      at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
      at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
      at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
      at java.lang.Thread.run(Thread.java:595)
      Caused by: java.lang.StackOverflowError
      at java.security.AccessController.doPrivileged(Native Method)
      at com.sun.naming.internal.VersionHelper12.getContextClassLoader(VersionHelper12.java:158)
      at com.sun.naming.internal.ResourceManager.getFactory(ResourceManager.java:339)
      at javax.naming.spi.NamingManager.getURLObject(NamingManager.java:575)
      at javax.naming.spi.NamingManager.getURLContext(NamingManager.java:533)
      at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:279)
      at javax.naming.InitialContext.lookup(InitialContext.java:351)
      at org.jboss.ejb3.naming.SimpleMultiplexer.getObjectInstance(SimpleMultiplexer.java:85)
      at javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:304)
      at javax.naming.spi.NamingManager.getContext(NamingManager.java:422)
      at javax.naming.spi.ContinuationContext.getTargetContext(ContinuationContext.java:38)
      at javax.naming.spi.NamingManager.getContinuationContext(NamingManager.java:770)
      at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:773)
      at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:627)
      at javax.naming.InitialContext.lookup(InitialContext.java:351)
      at org.jnp.interfaces.NamingContext.resolveLink(NamingContext.java:1209)
      at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:758)
      at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:774)
      at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:627)
      at javax.naming.InitialContext.lookup(InitialContext.java:351)
      at org.jnp.interfaces.NamingContext.resolveLink(NamingContext.java:1209)
      at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:758)
      at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:774)
      at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:627)
      at javax.naming.InitialContext.lookup(InitialContext.java:351)


      Any suggestion?

      if i try to load them using getResourceAsStream("filename") i'm able to get them, but just while i remain on the webapp context, cause i can't load them from inside an EJB3.0

      Thanks for your time