Jetty
  1. Jetty
  2. JETTY-51

NullPointerException when WebAppContext files are in a jar

    Details

    • Type: Bug Bug
    • Status: Resolved Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 6.0.0beta14
    • Fix Version/s: None
    • Component/s: Maven
    • Labels:
      None
    • Environment:
      Maven 2
      WinXP
      JDK 1.4.2
    • Number of attachments :
      1

      Description

      My project is composed of different maven modules.
      The module "test-commons" contains JUnit test cases and Html files.

      The module "htmlunit-plugin" uses the first module to run its tests and uses embedded Jetty.

      When I run "mvn test" in the parent directory, it works. But when I run "mvn test" in the htmlunit-plugin module directory, or when I run "mvn site" (that launch tests), it fails :
      [surefire] Running net.sourceforge.jwebunit.htmlunit.JWebUnitTest
      :INFO: Logging to STDERR via org.mortbay.log.StdErrLog
      :INFO: Extract jar:file:/C:/Documents and Settings/jhenry/.m2/repository/net/sourceforge/jwebunit/commons-tests/1.3-SNAPSHOT/commons-tests-1.3-SNAPSHOT.jar!/testcases to C:\DOCUME~1\jhenry\LOCALS~1\Temp\Jetty__jwebunit\webapp
      :WARN: failed ContextHandler@430b6

      {/jwebunit,null}

      :INFO: Started SocketConnector @ 0.0.0.0:8082
      :WARN: failed Server@18f7386
      java.lang.NullPointerException: in is null
      at java.util.zip.ZipInputStream.<init>(ZipInputStream.java:55)
      at java.util.jar.JarInputStream.<init>(JarInputStream.java:57)
      at java.util.jar.JarInputStream.<init>(JarInputStream.java:43)
      at org.mortbay.resource.JarResource.extract(JarResource.java:108)
      at org.mortbay.jetty.webapp.WebAppContext.resolveWebApp(WebAppContext.java:722)
      at org.mortbay.jetty.webapp.WebAppContext.getWebInf(WebAppContext.java:611)
      at org.mortbay.jetty.webapp.WebInfConfiguration.configureClassLoader(WebInfConfiguration.java:62)
      at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:364)
      at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:37)
      at org.mortbay.jetty.handler.HandlerCollection.doStart(HandlerCollection.java:133)
      at org.mortbay.jetty.Server.doStart(Server.java:256)
      at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:37)
      ...

      I don't know if this bug is due to Jetty or Maven, but I hope you can solve it.

      Here is how I run Jetty :
      jettyServer = new Server();
      SocketConnector connector = new SocketConnector();
      connector.setPort(JWebUnitAPITestCase.JETTY_PORT);
      jettyServer.setConnectors (new Connector[]

      {connector}

      );
      WebAppContext wah = new WebAppContext();
      wah.setServer(jettyServer);
      wah.setContextPath(JWebUnitAPITestCase.JETTY_URL);
      URL url = this.getClass().getResource("/testcases");
      wah.setWar(url.toString());
      jettyServer.addHandler(wah);
      jettyServer.start();

        Activity

        Hide
        Jan Bartel added a comment -

        Julien, what is the structure of the commons-tests-1.3.SNAPSHOT.jar file? Is the directory "testcases" a directory structure of a webapp? Can you post the jar file?

        Show
        Jan Bartel added a comment - Julien, what is the structure of the commons-tests-1.3.SNAPSHOT.jar file? Is the directory "testcases" a directory structure of a webapp? Can you post the jar file?
        Hide
        Julien HENRY added a comment -

        Yes, testcases is a directory structure of a webapp, and contains a WEB-INF/web.xml file.

        commons-tests-1.3.SNAPSHOT.jar contains :

        • META-INF
        • net/sourceforge/jwebunit/tests/...
        • testcases

        I join the jar.

        Show
        Julien HENRY added a comment - Yes, testcases is a directory structure of a webapp, and contains a WEB-INF/web.xml file. commons-tests-1.3.SNAPSHOT.jar contains : META-INF net/sourceforge/jwebunit/tests/... testcases I join the jar.
        Hide
        Jan Bartel added a comment -

        Julien,

        the problem is that your URL must end in a "/" to denote a directory, so it should be:

        URL url = this.getClass().getResource("/testcases")+"/";

        Show
        Jan Bartel added a comment - Julien, the problem is that your URL must end in a "/" to denote a directory, so it should be: URL url = this.getClass().getResource("/testcases")+"/";
        Hide
        Julien HENRY added a comment -

        Thanks for your tips, it changes some things, but not all :

        I have now :
        URL url = this.getClass().getResource("/testcases/"); //url = jar:file:/C:/Documents%20and%20Settings/jhenry/.m2/repository/net/sourceforge/jwebunit/commons-tests/1.3-SNAPSHOT/commons-tests-1.3-SNAPSHOT.jar!/testcases/
        wah.setWar(url.toString());
        jettyServer.addHandler(wah);

        And Jetty is running fine. But the web app is empty, so I get 404 error for each test.
        Here is what I see on http://localhost:8082/ :
        Contexts known to this server are:

        • /jwebunit ---> ContextHandler@3dc0bb {/jwebunit,file:/C:/Documents%20and%20Settings/jhenry/Local%20Settings/Temp/Jetty__jwebunit/webapp/}

        But C:/Documents%20and%20Settings/jhenry/Local%20Settings/Temp/Jetty__jwebunit/webapp is empty.

        I think the temporary extraction of the Jar failed, but I don't know why...

        Show
        Julien HENRY added a comment - Thanks for your tips, it changes some things, but not all : I have now : URL url = this.getClass().getResource("/testcases/"); //url = jar: file:/C:/Documents%20and%20Settings/jhenry/.m2/repository/net/sourceforge/jwebunit/commons-tests/1.3-SNAPSHOT/commons-tests-1.3-SNAPSHOT.jar!/testcases/ wah.setWar(url.toString()); jettyServer.addHandler(wah); And Jetty is running fine. But the web app is empty, so I get 404 error for each test. Here is what I see on http://localhost:8082/ : Contexts known to this server are: /jwebunit ---> ContextHandler@3dc0bb {/jwebunit,file:/C:/Documents%20and%20Settings/jhenry/Local%20Settings/Temp/Jetty__jwebunit/webapp/} But C:/Documents%20and%20Settings/jhenry/Local%20Settings/Temp/Jetty__jwebunit/webapp is empty. I think the temporary extraction of the Jar failed, but I don't know why...
        Hide
        Jan Bartel added a comment -

        Julien.

        I've checked in a fix for extracting partial contents of a jar:file url. Try doing a build from Jetty svn trunk.

        Show
        Jan Bartel added a comment - Julien. I've checked in a fix for extracting partial contents of a jar:file url. Try doing a build from Jetty svn trunk.
        Hide
        Julien HENRY added a comment -

        Thanks Jan,

        It works very well now.

        Good work !

        Show
        Julien HENRY added a comment - Thanks Jan, It works very well now. Good work !
        Hide
        Jan Bartel added a comment -

        I'm glad it works now.

        Show
        Jan Bartel added a comment - I'm glad it works now.

          People

          • Assignee:
            Jan Bartel
            Reporter:
            Julien HENRY
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: