1 2 Previous Next 16 Replies Latest reply on May 21, 2009 6:54 AM by jeff.yuchang

    can't read resource from the classpath??

    jeff.yuchang

      Hi all,

      I've created a deployer for jboss identity, which is listening on the -jboss-idm.xml file.

      It has two deployer classes, one is the deployer that IDMVFSParsingDeployer, which extends AbstractVFSParsingDeployer, the other is IDMSimpleVFSRealDeployer that extends AbstractSimpleVFSRealDeployer.

      The work that deployer need to be done is simple.

      1. IDMVFSParsingDeployer just need to listening on the -jboss-idm.xml, and then turn this xml file into javabean object(Metadata).

      2. IDMSimpleVFSRealDeployer will get the config file from the javabean object(metadata), and then use the jboss identity API to start its service.

      So in the jboss5.0.1.GA/server/default/deployer, it will have a idm-deployer.
      in its deploy folder, it has idm folder that only contains three files.

      default-jboss-idm.xml
      jboss.idm.cfg.xml
      jboss.idm.hibernate.cfg.xml
      


      In the IDMVFSParsingDeployer, I am using the vsfile.openStream to read the default-jboss-idm.xml, it works great..

      the default-jboss-idm.xml is following
      <?xml version="1.0" encoding="UTF-8"?>
      <jboss-idm-deployer xmlns="urn:jboss:identity:idm:deployer:v1_0_alpha"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="urn:jboss:identity:idm:deployer:v1_0_alpha identity-deployer.xsd">
       <JNDIName>java:/identitySessionFactory</JNDIName>
       <idmConfigFile>jboss.idm.cfg.xml</idmConfigFile>
       <initializers>
       <hibernateInitializerType>
       <doChecking>true</doChecking>
       </hibernateInitializerType>
       </initializers>
      </jboss-idm-deployer>


      so I can read the idmConfigFile property from here, but the question is, now I invoke the

      JAXB2IdentityConfiguration.createConfigurationMetaData("jboss.idm.cfg.xml")


      It will tell me it can't find the jboss.idm.cfg.xml resource.

      the code for the JAXB2IdentityConfiguration.createConfigurationMetaData is:

       ClassLoader classLoader = SecurityActions.getContextClassLoader();
       InputStream inputStream = classLoader.getResourceAsStream(configResource);
       if (inputStream == null)
       {
       throw new IllegalArgumentException("Resource "+configResource+" does not exist");
       }
       return createConfigurationMetaData(inputStream);
      


      So I am wondering whether because the lib was in the deployer/idm-deployer folder, and then can't access the resources in the deploy/idm/ directory?

      Or I did something wrong in other places?

      Thoughts?


      Thanks
      Jeff

        • 1. Re: can't read resource from the classpath??
          alesj

           

          "jeff.yuchang" wrote:

          So I am wondering whether because the lib was in the deployer/idm-deployer folder, and then can't access the resources in the deploy/idm/ directory?

          If you look at the DeployerWrapper,
          we do set the TCCL to a cl that deployed the deployer.
          And I guess that one doesn't see your deployment's resources;
          which is normal, as it should be usually the other way around.

          What about if you use DeploymentUnit's cl when checking for your resource?


          • 2. Re: can't read resource from the classpath??
            jeff.yuchang

            No luck with the DeploymentUnit's cl either.

            • 3. Re: can't read resource from the classpath??
              alesj

              What about if you put the default config files in deployers/idm.
              Or rename you stuff in deploy to have .jar suffix --> idm.jar,
              where default-jboss-idm.xml is in this jar's META-INF dir.

              • 4. Re: can't read resource from the classpath??
                jeff.yuchang

                pack the stuff into .jar suffix approach doesn't work, the same resource was not found exception.

                By putting the default config files in the deployers/idm doesn't work either. Nothing happened this way, seems it can't listen the -jboss-idm.xml suffix file in the deployer folder.

                • 5. Re: can't read resource from the classpath??
                  jaikiran

                  Can you please post the entire exception stacktrace when you try to access that resource?

                  • 6. Re: can't read resource from the classpath??
                    alesj

                     

                    "jeff.yuchang" wrote:
                    pack the stuff into .jar suffix approach doesn't work, the same resource was not found exception.

                    If you use this approach, then you have to use DU::getClassLoader,
                    when trying to load resources.

                    "jeff.yuchang" wrote:

                    By putting the default config files in the deployers/idm doesn't work either. Nothing happened this way, seems it can't listen the -jboss-idm.xml suffix file in the deployer folder.

                    Sure, you cannot expect it to find a match you're just about to instruct it how to find. ;-)

                    And I only meant that you move the .hbm files to deployers/idm.

                    • 7. Re: can't read resource from the classpath??
                      jeff.yuchang

                      Thanks, below it is the exception:

                      14:34:36,635 ERROR [AbstractKernelController] Error installing to Real: name=vfszip:/local/deploy/jboss-5.0.1.GA/server/default/deploy/idm.jar/ state=PreReal mode=Manual requiredState=Real
                      org.jboss.deployers.spi.DeploymentException: java.lang.IllegalArgumentException: Resource idm/jboss.idm.cfg.xml does not exist
                       at org.jboss.identity.idm.integration.jboss5.IDMDeployer.deploy(IDMDeployer.java:119)
                       at org.jboss.identity.idm.integration.jboss5.IDMDeployer.deploy(IDMDeployer.java:41)
                       at org.jboss.deployers.vfs.spi.deployer.AbstractSimpleVFSRealDeployer.deploy(AbstractSimpleVFSRealDeployer.java:56)
                       at org.jboss.deployers.spi.deployer.helpers.AbstractSimpleRealDeployer.internalDeploy(AbstractSimpleRealDeployer.java:62)
                       at org.jboss.deployers.spi.deployer.helpers.AbstractRealDeployer.deploy(AbstractRealDeployer.java:50)
                       at org.jboss.deployers.plugins.deployers.DeployerWrapper.deploy(DeployerWrapper.java:171)
                       at org.jboss.deployers.plugins.deployers.DeployersImpl.doDeploy(DeployersImpl.java:1439)
                       at org.jboss.deployers.plugins.deployers.DeployersImpl.doInstallParentFirst(DeployersImpl.java:1157)
                       at org.jboss.deployers.plugins.deployers.DeployersImpl.install(DeployersImpl.java:1098)
                       at org.jboss.dependency.plugins.AbstractControllerContext.install(AbstractControllerContext.java:348)
                       at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:1598)
                       at org.jboss.dependency.plugins.AbstractController.incrementState(AbstractController.java:934)
                       at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:1062)
                       at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:984)
                       at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:822)
                       at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:553)
                       at org.jboss.deployers.plugins.deployers.DeployersImpl.process(DeployersImpl.java:781)
                       at org.jboss.deployers.plugins.main.MainDeployerImpl.process(MainDeployerImpl.java:698)
                       at org.jboss.system.server.profileservice.ProfileServiceBootstrap.loadProfile(ProfileServiceBootstrap.java:304)
                       at org.jboss.system.server.profileservice.ProfileServiceBootstrap.start(ProfileServiceBootstrap.java:205)
                       at org.jboss.bootstrap.AbstractServerImpl.start(AbstractServerImpl.java:405)
                       at org.jboss.Main.boot(Main.java:209)
                       at org.jboss.Main$1.run(Main.java:547)
                       at java.lang.Thread.run(Thread.java:595)
                      Caused by: java.lang.IllegalArgumentException: Resource idm/jboss.idm.cfg.xml does not exist
                       at org.jboss.identity.idm.impl.configuration.jaxb2.JAXB2IdentityConfiguration.createConfigurationMetaData(JAXB2IdentityConfiguration.java:112)
                       at org.jboss.identity.idm.integration.jboss5.IDMDeployer.deploy(IDMDeployer.java:71)
                       ... 23 more
                      
                      




                      • 8. Re: can't read resource from the classpath??
                        jeff.yuchang

                         

                        "alesj" wrote:
                        "jeff.yuchang" wrote:
                        pack the stuff into .jar suffix approach doesn't work, the same resource was not found exception.

                        If you use this approach, then you have to use DU::getClassLoader,
                        when trying to load resources.



                        I was using the DU::getResourceClassLoader && getResourceLoader do the test, it didn't find it, I will try to use the DU::getClassLoader do the test, whats the difference between these?

                        • 9. Re: can't read resource from the classpath??
                          alesj

                           

                          "jeff.yuchang" wrote:

                          14:34:36,635 ERROR [AbstractKernelController] Error installing to Real: name=vfszip:/local/deploy/jboss-5.0.1.GA/server/default/deploy/idm.jar/ state=PreReal mode=Manual requiredState=Real
                          org.jboss.deployers.spi.DeploymentException: java.lang.IllegalArgumentException: Resource idm/jboss.idm.cfg.xml does not exist
                          


                          Why is there a idm/ at the begining?

                          • 10. Re: can't read resource from the classpath??
                            jeff.yuchang

                            Just finished the test, same result, the whole stack tree is as following:

                            17:34:07,272 ERROR [AbstractKernelController] Error installing to Real: name=vfszip:/local/deploy/jboss-5.0.1.GA/server/default/deploy/idm.jar/ state=PreReal mode=Manual requiredState=Real
                            org.jboss.deployers.spi.DeploymentException: java.lang.IllegalArgumentException: no config resource
                             at org.jboss.identity.idm.integration.jboss5.IDMDeployer.deploy(IDMDeployer.java:123)
                             at org.jboss.identity.idm.integration.jboss5.IDMDeployer.deploy(IDMDeployer.java:42)
                             at org.jboss.deployers.vfs.spi.deployer.AbstractSimpleVFSRealDeployer.deploy(AbstractSimpleVFSRealDeployer.java:56)
                             at org.jboss.deployers.spi.deployer.helpers.AbstractSimpleRealDeployer.internalDeploy(AbstractSimpleRealDeployer.java:62)
                             at org.jboss.deployers.spi.deployer.helpers.AbstractRealDeployer.deploy(AbstractRealDeployer.java:50)
                             at org.jboss.deployers.plugins.deployers.DeployerWrapper.deploy(DeployerWrapper.java:171)
                             at org.jboss.deployers.plugins.deployers.DeployersImpl.doDeploy(DeployersImpl.java:1439)
                             at org.jboss.deployers.plugins.deployers.DeployersImpl.doInstallParentFirst(DeployersImpl.java:1157)
                             at org.jboss.deployers.plugins.deployers.DeployersImpl.install(DeployersImpl.java:1098)
                             at org.jboss.dependency.plugins.AbstractControllerContext.install(AbstractControllerContext.java:348)
                             at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:1598)
                             at org.jboss.dependency.plugins.AbstractController.incrementState(AbstractController.java:934)
                             at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:1062)
                             at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:984)
                             at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:822)
                             at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:553)
                             at org.jboss.deployers.plugins.deployers.DeployersImpl.process(DeployersImpl.java:781)
                             at org.jboss.deployers.plugins.main.MainDeployerImpl.process(MainDeployerImpl.java:698)
                             at org.jboss.system.server.profileservice.ProfileServiceBootstrap.loadProfile(ProfileServiceBootstrap.java:304)
                             at org.jboss.system.server.profileservice.ProfileServiceBootstrap.start(ProfileServiceBootstrap.java:205)
                             at org.jboss.bootstrap.AbstractServerImpl.start(AbstractServerImpl.java:405)
                             at org.jboss.Main.boot(Main.java:209)
                             at org.jboss.Main$1.run(Main.java:547)
                             at java.lang.Thread.run(Thread.java:595)
                            Caused by: java.lang.IllegalArgumentException: no config resource
                             at org.jboss.identity.idm.impl.configuration.jaxb2.JAXB2IdentityConfiguration.createConfigurationMetaData(JAXB2IdentityConfiguration.java:121)
                             at org.jboss.identity.idm.integration.jboss5.IDMDeployer.deploy(IDMDeployer.java:75)
                             ... 23 more
                            
                            


                            • 11. Re: can't read resource from the classpath??
                              jeff.yuchang

                              Also, in this test, I ran the DU::getClasspath, I showed the idm.jar, but couldn't find the idm.cfg.xml file, I was putting it in the idm.jar/META-INF/.

                              • 12. Re: can't read resource from the classpath??
                                jeff.yuchang

                                 

                                "alesj" wrote:
                                "jeff.yuchang" wrote:

                                14:34:36,635 ERROR [AbstractKernelController] Error installing to Real: name=vfszip:/local/deploy/jboss-5.0.1.GA/server/default/deploy/idm.jar/ state=PreReal mode=Manual requiredState=Real
                                org.jboss.deployers.spi.DeploymentException: java.lang.IllegalArgumentException: Resource idm/jboss.idm.cfg.xml does not exist
                                


                                Why is there a idm/ at the begining?


                                I was doing another test, trying to add the idm prefix.. After I remove the idm, it was still the same, I just copied the another stacktree, apart from the file name, it is the same.

                                • 13. Re: can't read resource from the classpath??
                                  alesj

                                   

                                  "jeff.yuchang" wrote:
                                  Also, in this test, I ran the DU::getClasspath, I showed the idm.jar, but couldn't find the idm.cfg.xml file, I was putting it in the idm.jar/META-INF/.

                                  Only metadata files should be in META-INF.
                                  Configuration should be in the root.

                                  Or you need to add META-INF infront if you wanna look for that resource via CL.

                                  • 14. Re: can't read resource from the classpath??
                                    jeff.yuchang

                                     

                                    "alesj" wrote:
                                    "jeff.yuchang" wrote:
                                    Also, in this test, I ran the DU::getClasspath, I showed the idm.jar, but couldn't find the idm.cfg.xml file, I was putting it in the idm.jar/META-INF/.

                                    Only metadata files should be in META-INF.
                                    Configuration should be in the root.

                                    Or you need to add META-INF infront if you wanna look for that resource via CL.


                                    My bad.. ;-(.. OK, using the DU::getClassloader can get this resource.. Thanks for your help.

                                    Is the jar package the only way to get this kind of resource?? I mean, do we have other approaches, or can we use a custom package suffix?

                                    1 2 Previous Next