users@jersey.java.net

Re: [Jersey] jersey-multipart throwing NPE

From: Gili <cowwoc_at_bbs.darktech.org>
Date: Thu, 20 Nov 2008 23:39:27 -0800 (PST)

Craig McClanahan wrote:
>
> For *all* HTTP headers, it is legal to have multiple values for the same
> header, so a general purpose API has to support that option. For the
> simple case where you know there is only one value (or for where you
> don't care about anything other than the first value), try this:
>
> bodyPart.getParameterizedHeaders().getFirst("Content-Disposition").get("name");
>

Yeah, I just remembered this when reading an older post you made about
ParameterizedHeaders. <shudder> HTTP headers sure are complex.

Okay, so I'll get cracking using this new API but I would like to humbly
suggest you need to explain a lot of these details in the Javadoc. It should
be easier for end-users to pick up on these concepts without reading through
the HTTP specification. I suspect that even developers who are quite
familiar with HTTP will drop the ball on the HTTP header complexity.

I would suggest you write something along the following lines:

[...]
Here is a sample HTTP header:
Content-Disposition: attachment; filename=bear.jpeg;
                            inline; filename=panda.jpeg;

The above header means: ("Content-Disposition=attachment" and
"filename=bear.jpeg") or ("Content-Disposition=inline" or
"filename="panda.jpeg")

Here is some sample code for parsing the header:
-
bodyPart.getParameterizedHeaders().getFirst("Content-Disposition").getParameters().get("filename")
returns "bear.jpeg"
-
bodyPart.getParameterizedHeaders().get("Content-Disposition").get(1).getParameters().get("filename")
returns "panda.jpeg"
[...]

BTW: Please note how long this API is turning out to be. Instead of
getFirst("Content-Disposition").getParameters().get("filename") why don't
you remove getParameters() and place get() directly on the
ParameterizedHeader?

Gili
-- 
View this message in context: http://n2.nabble.com/jersey-multipart-throwing-NPE-tp1560622p1560741.html
Sent from the Jersey mailing list archive at Nabble.com.