4 Replies Latest reply on Mar 22, 2007 7:57 AM by baz

    Integrate user defined Resources (suggestions needed)

    baz

      Hello,
      I am using http://jooreports.sourceforge.net/?q=jooreports with quite a success. (If you have questions about this please ask)
      Now i am searching a (the best) way to integrate the user written template into my app.
      For now, the template is stored at an absolute position and a fixed filename on the server. But this is not recommended.
      What are the best ways to integrate this file more flexibel.
      My thoughts go in this directions:
      1. deploy time property (specifys the filename and uri) and
      1a. loading it via new FileInputStream(templateFile)
      1b. loading it via org.jboss.seam.util.Resources.getResourceAsStream
      or
      2. Using the seam resource servlet

      The first option (1a) yields the possibility to store the file outside of tomcat in any directory on the server. Whereas, for the other options, the file must(?) be stored inside the appcontext in tomcat.

      For (2.) i do have no experience with it. Is it the right approach to use? I have to retrieve an InputStream for a resource on server side for use only on serverside. Where can i find an example, documentation and so on.

      Any comments?

      BTW: For downloading the generated report i use the approach described here:http://www.jboss.com/index.html?module=bb&op=viewtopic&t=103039
      Ciao,
      Carsten

        • 1. Re: Integrate user defined Resources (suggestions needed)
          pmuir

           

          @Name("report")
          public class Report {
          
           private String fileName;
           // getter and setter
          
           @Unwrap
           public InputStream unwrap {
           return Resources.getResourceAsStream(fileName);
           }
          }


          Configure through components.xml/component.properties

          You could easily extend for a list of files.

          • 2. Re: Integrate user defined Resources (suggestions needed)
            baz

            Hello,
            i tried to follow your advise.
            But after starting the app i get this exception:

            11:26:34,437 ERROR org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/baz]: Exception sending context initialized event to listener instance of class org.jboss.seam.servlet.SeamListener
            java.lang.RuntimeException: error while reading /WEB-INF/components.xml
             at org.jboss.seam.init.Initialization.initComponentsFromXmlDocument(Initialization.java:130)
             at org.jboss.seam.init.Initialization.<init>(Initialization.java:81)
             at org.jboss.seam.servlet.SeamListener.contextInitialized(SeamListener.java:33)
             at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3729)
             at org.apache.catalina.core.StandardContext.start(StandardContext.java:4187)
             at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1013)
             at org.apache.catalina.core.StandardHost.start(StandardHost.java:718)
             at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1013)
             at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:442)
             at org.apache.catalina.core.StandardService.start(StandardService.java:450)
             at org.apache.catalina.core.StandardServer.start(StandardServer.java:709)
             at org.apache.catalina.startup.Catalina.start(Catalina.java:551)
             at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
             at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
             at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
             at java.lang.reflect.Method.invoke(Unknown Source)
             at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:294)
             at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:432)
            Caused by: java.lang.NullPointerException
             at org.jboss.seam.init.Initialization.installComponentsFromXmlElements(Initialization.java:211)
             at org.jboss.seam.init.Initialization.initComponentsFromXmlDocument(Initialization.java:126)
             ... 17 more
            22.03.2007 11:26:34 org.apache.catalina.core.StandardContext start
            SCHWERWIEGEND: Error listenerStart

            This is because i have not added the @Install annotation to the bean.
            The corresponding code (the same in current cvs and seam 1.2.0)Patch1 in Initialization.java looks like

            if ( nameAnnotation!=null && nameAnnotation.value().equals(name) )
             {
             Install install = clazz.getAnnotation(Install.class);
             if ( install.value() )
             {
             className = null;
             }
             }
            

            If there is no @Install annotation the value of install is null and hence the npe.
            After adding the @Install annotation i get
            Caused by: org.jboss.seam.RequiredException: In attribute requires non-null value: authorizationBean.protocolTemplate
             at org.jboss.seam.Component.getValueToInject(Component.java:1887)
             at org.jboss.seam.Component.injectAttributes(Component.java:1336)
             at org.jboss.seam.Component.inject(Component.java:1163)
            

            when trying to inject my bean with @In.
            But @AutoCreate is set and i have added auto-create="true" to the definition

            Here is the components.xml fragment
            <baz:protocol-template file-name="meinFile" auto-create="true"/>
            

            What to do next?

            Ciao,
            Carsten



            • 3. Re: Integrate user defined Resources (suggestions needed)
              pmuir

               

              "baz" wrote:
              Caused by: java.lang.NullPointerException
               at org.jboss.seam.init.Initialization.installComponentsFromXmlElements(Initialization.java:211)
               at org.jboss.seam.init.Initialization.initComponentsFromXmlDocument(Initialization.java:126)
               ... 17 more


              This is a bug in Seam. I've fixed it in CVS, please test.

              After adding the @Install annotation i get
              Caused by: org.jboss.seam.RequiredException: In attribute requires non-null value: authorizationBean.protocolTemplate
               at org.jboss.seam.Component.getValueToInject(Component.java:1887)
               at org.jboss.seam.Component.injectAttributes(Component.java:1336)
               at org.jboss.seam.Component.inject(Component.java:1163)
              

              when trying to inject my bean with @In.
              But @AutoCreate is set and i have added auto-create="true" to the definition

              Here is the components.xml fragment
              <baz:protocol-template file-name="meinFile" auto-create="true"/>
              



              Well you are trying to inject a null value. Check that Resources.get... is actually returning an InputStream.


              • 4. Re: Integrate user defined Resources (suggestions needed)
                baz

                Thanks for the pronpt reply.
                Yes you are right with the null value. This was by intention.
                I have not really inhaleted the meaning of unwrap:-(
                I' ll try to test the cvs version on weekend.
                Ciao,
                Carsten