users@jersey.java.net

Re: [Jersey] jersey-multipart throwing NPE

From: Craig McClanahan <Craig.McClanahan_at_Sun.COM>
Date: Thu, 20 Nov 2008 22:45:38 -0800

Gili wrote:
> It turns out this is caused by the fact that "@Context MultiPartConfig
> config" in the constructor returns null. The thing is, the Javadoc doesn't
> explain if I'm supposed to provide some sort of configuration and if so how
> to do it. I could really use your help ;)
>
>
Yep, that is definitely the root cause. I just added an error message
to the constructor of MultiPartReader that will complain (the first time
this class is instantiated) if the config bean cannot be found. (+1 to
maximally helpful exception messages.)

This should *never* happen on the server side unless you have done
something really strange with the Jersey configuration parameters. On
the client side, as we've discusssed, you need to explicitly register
the provider class.

Note that there has been a package rename recently in this as well as
many other areas ... but if you had initialized the client as indicated
in your earlier email:

        config.getClasses().add(MultiPartConfigProvider.class);

you would have gotten a compile error if you didn't update your import
statement. So I suspect that this error is happening on the client
side, and that you haven't registered this particular provider.

Try the latest jersey-multipart code with no other changes, and you
should receive an IllegalArgumentException that discusses the root cause
more clearly.

> BTW, I see "com.sun.jersey.multipart.impl.MultiPartConfigProvider" being
> loaded by Jersey on startup so I am expecting this to work...
>
>
Could you cut-n-paste the system out log that shows this?
> Thanks,
> Gili
>
>
Craig