users@jersey.java.net

Re: [Jersey] POST FormData

From: Saavedra, Gisella <gsaavedra_at_navis.com>
Date: Tue, 23 Jun 2009 09:31:29 -0700

Jochen,

 

thank you. It appears that the setting of the variables in Form at the client side is OK.

 

At the server, I DO GET the string surrounded by "[ ]".

 

I am enclosing another image; this is at the server side where the parameter "fileList" (Java parameter inFileList) is received.

My service fails because of the enclosing [] when I loop through the list.

 

I am using JDK6. But I think the REST code at the server side is not handling the List<T> @FormParam as a List but as a T (String).

 

 

 

===================

 

Date: Tue, 23 Jun 2009 10:14:21 +0200

From: Jochen Schalanda <jochen_at_schalanda.name>

Content-Type: text/plain; charset=UTF-8

Subject: [Jersey] POST FormData

 

Hi Gisella,

 

are you sure you're not just misinterpreting the output of your debugger?

 

As far as I can see from your explanation and the screenshot, it should

be all perfectly fine.

 

Your debugger displays the items of Java collections in square brackets

("[" and "]").

 

So

 

| fromMillis -> [1234567890]

 

means that your HashMap contains an entry with the key "fromMillis" and

the value "1234567890".

 

| fileList -> [[C:\\N4\\sandbox...]]

 

accordingly means that your HashMap contains an entry with the key

"fileList" and that the value is a List which contains the value

"C:\\N4\\sandbox...". Thus the two pairs of square brackets.

 

If your List contained another Collection, you could also get something like

 

| fileList -> [[[foo], [bar]], [[foo2], [bar2]]]

 

 

If you anticipate to only get a flat string value (e.g. comma-separated)

for inFileList, you should not declare it as List<String> but as String.

 

 

HTH,

Jochen

 

Saavedra, Gisella wrote:

> Re: INFO: Initiating Jersey application, version 'Jersey: 1.1.0-ea

>

>

>

>

>

> I have a REST service with a parameter of type List<String>.

>

>

>

> @POST

>

> @Produces("application/octet-stream")

>

> @Consumes("application/x-www-form-urlencoded")

>

> public Response *getLogBundle*(@FormParam("fromMillis") Long

> inFromMillis,

>

> @FormParam("toMillis") Long inToMillis,

>

> @FormParam("fileList") List<String>

> inFileList) {

>

> ...

>

> }

>

>

>

> At the client side, when I am building the FormData, I call

>

> formData.add("fileList", inNamedLogs);

>

> where inNamedLogs is a List<String>

>

>

>

> See the value of my formDataàfileList argument (you can see the source

> and how it has been saved). There are TWO [[ surrounding the value.

>

>

>

>

>

> On the server side, getLogBundle() (code above), when I see the contents

> of fileList, I see each element having ONE [ surrounding the value.

>

> So, when I do inFileList.get(0), I get "*[*C:\\N4\\sandbox...*]*" instead

> of "C:\\N4\\sandbox..."

>

>

>

> Is this a bug? The documentation for the FormParam tag says that

> List<T> is supported; in this case T is String. I believe steps 1 to 4

> of the JavaDoc are satisified.

>

>

>

> Please advise. Thanks.

>

>

>

> *Gisella Saavedra**

> *Sr. Software Engineer

> _gsaavedra_at_zebra.com <mailto:gsaavedra_at_zebra.com>_

>

>

>

> http://www.navis.com/images/spacer.gif

>

> 1000 Broadway, Suite 150, Oakland, CA 94607 | T+1 510 267 5123 T

> Main+1 510 267 5000 F+1 510 267 5100 | _http://www.zebra.com/zes_

>

>

>

>

>

 

 

 

 

 

 

Gisella Saavedra
Sr. Software Engineer
gsaavedra_at_zebra.com <mailto:gsaavedra_at_zebra.com>

        
 

1000 Broadway, Suite 150, Oakland, CA 94607 | T+1 510 267 5123 T Main+1 510 267 5000 F+1 510 267 5100 | http://www.zebra.com/zes <http://www.zebra.com/zes>



        

 

 








image001.gif
(image/gif attachment: image001.gif)

jersey_formdata_list_at_server.png
(image/png attachment: jersey_formdata_list_at_server.png)