3 Replies Latest reply on Jan 4, 2013 3:38 AM by Nicklas Karlsson

    Spring 3, OpenJPA 2 and Commons-fileupload.

    Sudhi SDK Newbie

      Hi All,

       

       

      i am using Spring 3.1, with OpenJPA 2.1 in JBOSS 7 . As per discussions and few articles, i have created new module for OpenJPA 2.1and used in application. Application worked fine until a functional requirement came for uploading files wherein we were supposed to use commons-fileupload.

       

      Firstly while creating module for OpenJPA, server failed to start until i added Commons-fileupload jar. Below shows the module.xml that i used for OpenJPA 2, So question is not sure why OpenJPA is refering to fileupload.

       

      <module xmlns="urn:jboss:module:1.1" name="org.apache.openjpa">

          <resources>

              <resource-root path="openjpa-all-2.2.0.jar"/>

              <resource-root path="serp-1.13.1.jar"/>

              <resource-root path="commons-fileupload-1.2.2.jar"/>

          </resources>

       

              <dependencies>

                  <module name="javax.persistence.api"/>

                  <module name="javax.transaction.api"/>

                  <module name="javax.validation.api"/>

                  <module name="org.apache.log4j"/>

                 

              </dependencies>

      </module>

       

       

      Secondly, after above conf, when i wanted to implement upload functionality, i created a controller in Spring and multipart request was sent.

      But runtime i get NoClassDefFound excpetion for HttpServletRequest

       

      java.lang.NoClassDefFoundError: javax/servlet/http/HttpServletRequest

      org.apache.commons.fileupload.servlet.ServletFileUpload.isMultipartContent(ServletFileUpload.java:68)

      org.springframework.web.multipart.commons.CommonsMultipartResolver.isMultipart(CommonsMultipartResolver.java:122)

      org.springframework.web.servlet.DispatcherServlet.checkMultipart(DispatcherServlet.java:991)

      org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:860)

      org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:827)

      org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)

      org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:789)

      javax.servlet.http.HttpServlet.service(HttpServlet.java:754)

      javax.servlet.http.HttpServlet.service(HttpServlet.java:847)

       

      Can anyone please tell me where i am going wrong or guide me for right class loading approach that needs to be followed in Jboss 7

       

      Thanks

      Sudhi

       


        • 1. Re: Spring 3, OpenJPA 2 and Commons-fileupload.
          Nicklas Karlsson Master

          Hmm, the server should be giving you the HttpServletRequest automatically. Can you do a jar -tf of your jar to make sure you don't package any extra javax.* (e.g. the servlet api jar) that might confuse the classloader?

          • 2. Re: Spring 3, OpenJPA 2 and Commons-fileupload.
            Sudhi SDK Newbie

            Nicklas,

             

            i verified that no servlet-api.jars are available in application lib,

             

            Just to test, i removed spring multipart configuration then i wont get above exception but i wont be able to use common-fileupload.

            Does adding Commons-fileupload in OpenJPA module make difference ?

             

            <!-- Multipart conf -->

            <bean id="multipartResolver" 

                    class="org.springframework.web.multipart.commons.CommonsMultipartResolver"> 

                    <property name="maxUploadSize"> 

                        <value>104857600</value> 

                    </property> 

                    <property name="maxInMemorySize"> 

                        <value>4096</value> 

                    </property>     

                </bean>

             

             

            Thanks

            Sudhi

            • 3. Re: Spring 3, OpenJPA 2 and Commons-fileupload.
              Nicklas Karlsson Master

              I don't think OpenJPA has anything to do with commons-fileupload. I think Spring uses commons-fileupload and commons-fileupload uses the HttpServletRequest. If you package Spring with your application, you should also package commons-fileupload with the app (and take away it from the OpenJPA module). What is the stacktrace then?