3 Replies Latest reply on Nov 4, 2009 11:16 AM by philip andrew

    How to get javax.servlet.GenericServlet from Seam Bean?

    philip andrew Newbie

      Hi,


      I am trying to use Apache Jackrabbit from within my SEAM Application.


      What it wants, is a reference the to object which inherits from GenericServlet. So I am supposed to pass in a object here.


      public class ServletRepository extends org.apache.jackrabbit.commons.repository.ProxyRepository {
        public ServletRepository(javax.servlet.GenericServlet genericServlet) { / compiled code / }


      Now what I thought, I can find the servlet which implements this abstract class GenericServlet.


      I tried ServletContexts.instance().getRequest() ... but that wasn't the right thing. I also tried, ServletLifecycle.getCurrentServletContext() ... nope, Any ideas?


      Thanks, Philip

        • 1. Re: How to get javax.servlet.GenericServlet from Seam Bean?
          Shervin Asgari Master

          Hmm I am not sure about this but have you tried:


          ServletContext ctx = (ServletContext) facesContext.getExternalContext().getContext(); 



          If you get Jackrabbit to work with seam post here. I would like to know.

          • 2. Re: How to get javax.servlet.GenericServlet from Seam Bean?
            philip andrew Newbie

            Hi Shervin,


            I am not using faces, my client program is a FLEX application which calls my servlet through GraniteDS. So there is no HTML, so there is no faces.


            I can share what I have done so far. I use maven to build, this is what works for me to get Jackrabbit with Maven.


                    <!-- Jackrabbit embedded http://cwiki.apache.org/confluence/display/JCR/Embedded+Repository -->
                    <dependency>
                        <groupId>javax.jcr</groupId>
                        <artifactId>jcr</artifactId>
                        <version>1.0</version>
                    </dependency>
                    <dependency>
                        <groupId>org.apache.jackrabbit</groupId>
                        <artifactId>jackrabbit-core</artifactId>
                        <version>1.5.6</version>
                        <exclusions>
                            <exclusion>
                                <groupId>commons-logging</groupId>
                                <artifactId>commons-logging</artifactId>
                            </exclusion>
                        </exclusions>
                    </dependency>
                    <dependency>
                      <groupId>org.apache.jackrabbit</groupId>
                      <artifactId>jackrabbit-jcr-servlet</artifactId>
                      <version>1.5.2</version>
                    </dependency>
            



            In my web.xml I use:


            <servlet>
                  <servlet-name>ContentRepository</servlet-name>
                  <servlet-class>org.apache.jackrabbit.servlet.jackrabbit.JackrabbitRepositoryServlet</servlet-class>
                  <load-on-startup>1</load-on-startup>
                </servlet>
            




            ... Do you think I could access this servlet by name?


            However I have been following the instructions which said:


            You can then access the repository in your own servlet classes using the following piece of code without worrying about the repository lifecycle.


            import javax.jcr.Repository;
            import org.apache.jackrabbit.servlet.ServletRepository;
            Repository repository = new ServletRepository(this);
            


            The problem is, my SEAM bean is not a servlet, so I cannot pass (this).


            Philip



            • 3. Re: How to get javax.servlet.GenericServlet from Seam Bean?
              philip andrew Newbie

              Hi,


              Ok I got a servlet working. Then I access the resource from my SEAM component.


              public class JackrabbitServlet extends HttpServlet {
              
                  private static org.apache.jackrabbit.servlet.ServletRepository repository = null;
              
                  public static org.apache.jackrabbit.servlet.ServletRepository getRepository() {
                    return JackrabbitServlet.repository;
                  }
              
                  @Override
                  public void init(javax.servlet.ServletConfig servletConfig) throws javax.servlet.ServletException
                  {
                    super.init(servletConfig);
                    repository = new ServletRepository(this);
                  }
              }
              



              In web.xml


                  <servlet>
                    <servlet-name>ContentRepository</servlet-name>
                    <servlet-class>org.apache.jackrabbit.servlet.jackrabbit.JackrabbitRepositoryServlet</servlet-class>
                    <load-on-startup>1</load-on-startup>
                  </servlet>
              
                  <servlet>
                    <servlet-name>JackrabbitServlet</servlet-name>
                    <servlet-class>com.orsa.seam.JackrabbitServlet</servlet-class>
                    <load-on-startup>2</load-on-startup>
                  </servlet>
              



              My seam component gets the repository by calling the static method on JackrabbitServlet.


              ServletRepository repository = JackrabbitServlet.getRepository();



              Actually my SEAM component is in Scala.


              val repository:ServletRepository = JackrabbitServlet.getRepository



              Any comments? Suggest a better way?


              Philip