users@jersey.java.net

Re: null pointer in resources scan

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Tue, 29 Jan 2008 15:44:56 +0100

Hi Guilhem,

I don't think it is a JER 5/6 version issue. An exception is being
thrown because a URL with a 'file' protocol (scheme) is assumed to be a
directory and it is not in this case. Jersey converts this file-based
URL to a file then does File.listFiles() which returns null. Definitely
a bug.

I managed to reproduce the same exception but i am not sure if that is
the same problem you are having. What i did was create a file, say
called 'junk', in a package, say 'mypackage', then set the package name
to search for in the web.xml as follows:

<init-param>
<param-name>com.sun.ws.rest.config.property.packages</param-name>
      <param-value>mypackage.junk</param-value>
</init-param>


For the the package name you used:

    net.seagis.coverage.wms

is 'wms' a file in the package "net.seagis.coverage" ?

If not i am not sure what is going on. Would it be possible to execute
the following code somewhere in your web app by including an additional
a basic servlet:

     public static void printPackageUrls(String... packages) throws
Exception {
         ClassLoader cl = Thread.currentThread().getContextClassLoader();
         for (String p : packages) {
             String fileP = p.replace('.', '/');
             Enumeration<URL> urls = cl.getResources(fileP);
             while (urls.hasMoreElements()) {
                 System.out.println(" URI: " + urls.nextElement());
                 System.out.println("file p: " + fileP);
                 System.out.println(new File(fileP).isDirectory());
             }
         }
     }

where you pass the packages you configure in the web.xml ?

Thanks,
Paul.

guilhem legal wrote:
> hi!
>
> I have a little issue with the maven plugin of netbeans, when i build my
> project with maven command line all work fine.
> But when i build my jersey WS with the netbeans maven plugin and try to
> deploy it with NB i get the folowing error :
>
> javax.servlet.ServletException: java.lang.reflect.InvocationTargetException
> com.sun.ws.rest.spi.container.servlet.ServletContainer.createResourceConfig(ServletContainer.java:172)
>
> com.sun.ws.rest.spi.container.servlet.ServletContainer.init(ServletContainer.java:104)
>
> org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
>
> org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:263)
>
> org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
>
> org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:584)
>
> org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
> java.lang.Thread.run(Thread.java:595)
>
> java.lang.reflect.InvocationTargetException
> sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
> sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
>
> sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
>
> java.lang.reflect.Constructor.newInstance(Constructor.java:494)
> com.sun.ws.rest.spi.container.servlet.ServletContainer.createResourceConfig(ServletContainer.java:168)
>
> com.sun.ws.rest.spi.container.servlet.ServletContainer.init(ServletContainer.java:104)
>
> org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
>
> org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:263)
>
> org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
>
> org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:584)
>
> org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
> java.lang.Thread.run(Thread.java:595)
>
> java.lang.NullPointerException
> com.sun.ws.rest.impl.container.config.ResourceClassScanner.indexDir(ResourceClassScanner.java:149)
>
> com.sun.ws.rest.impl.container.config.ResourceClassScanner.index(ResourceClassScanner.java:135)
>
> com.sun.ws.rest.impl.container.config.ResourceClassScanner.scan(ResourceClassScanner.java:97)
>
> com.sun.ws.rest.api.core.PackagesResourceConfig.init(PackagesResourceConfig.java:88)
>
> com.sun.ws.rest.api.core.PackagesResourceConfig.<init>(PackagesResourceConfig.java:64)
>
> com.sun.ws.rest.api.core.PackagesResourceConfig.<init>(PackagesResourceConfig.java:72)
>
> sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
> sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
>
> sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
>
> java.lang.reflect.Constructor.newInstance(Constructor.java:494)
> com.sun.ws.rest.spi.container.servlet.ServletContainer.createResourceConfig(ServletContainer.java:168)
>
> com.sun.ws.rest.spi.container.servlet.ServletContainer.init(ServletContainer.java:104)
>
> org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
>
> org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:263)
>
> org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
>
> org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:584)
>
> org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
> java.lang.Thread.run(Thread.java:595)
>
> I see in the log the scan starting :
>
> INFO: Scanning for root resource classes in the packages:
> net.seagis.coverage.wms
>
> but it never find the resources.
>
> any idea what this happen? (i'm using tomcat 6 with JDK5, I have maybe a
> problem with JDK6/5 compilation)
>
> Guilhem Legal
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>

-- 
| ? + ? = To question
----------------\
    Paul Sandoz
         x38109
+33-4-76188109