Discussion:
@FormDataParam gives Bad Request.
kavita
2011-12-06 07:37:55 UTC
Permalink
Hi,
I have a REST web service to which I am sending multipart form data. Since
Glassfish 3.1 uses jdk7, I had to change the @FormParam to @FormDataParam in
the webservice method signature. Doing this causes all the requests to my
web service ending up as Bad Request errors.
I am using an ajax request to call the web service. This is the call:
var formdata = new FormData();
formdata.append("purpose","new");
formdata.append("filename",workbook);
formdata.append("username","abc");
formdata.append("password","abc");
formdata.append("company","Third");

$.ajax({
url:'http://comp1:8080/RestWSGS/jersey/GetJson',
async: false,
data:formdata,
type: 'POST',
cache: false,
dataType: 'json',
contentType: "multipart/form-data",
processData: false,
success: function(data)
{
myData=data;
alert("myData" + myData);
}
});
Please let me know how can I ask jersey to convert the FormData object to
the ***@FormDataParam.

Thanks for any help you can provide!!
Kavita

--
View this message in context: http://jersey.576304.n2.nabble.com/FormDataParam-gives-Bad-Request-tp7065882p7065882.html
Sent from the Jersey mailing list archive at Nabble.com.
Pavel Bucek
2011-12-07 16:05:33 UTC
Permalink
Post by kavita
Hi,
I have a REST web service to which I am sending multipart form data. Since
the webservice method signature.
eh? Glassfish 3.1 can run on jdk 1.6, not sure about 1.7 but I guess it
should run.. anyway, that sentence doesn't make much sense. @FormParam
is present in JAX-RS 1.x API so you don't need to replace it with
anything, it is just there and it should work.
Post by kavita
Doing this causes all the requests to my
web service ending up as Bad Request errors.
var formdata = new FormData();
formdata.append("purpose","new");
formdata.append("filename",workbook);
formdata.append("username","abc");
formdata.append("password","abc");
formdata.append("company","Third");
$.ajax({
url:'http://comp1:8080/RestWSGS/jersey/GetJson',
async: false,
data:formdata,
type: 'POST',
cache: false,
dataType: 'json',
contentType: "multipart/form-data",
processData: false,
success: function(data)
{
myData=data;
alert("myData" + myData);
}
});
Please let me know how can I ask jersey to convert the FormData object to
can you please look into server log (and let us know what you found
there)? And is it possible for you to share service code as well?

Pavel
Post by kavita
Thanks for any help you can provide!!
Kavita
--
View this message in context: http://jersey.576304.n2.nabble.com/FormDataParam-gives-Bad-Request-tp7065882p7065882.html
Sent from the Jersey mailing list archive at Nabble.com.
kavita
2011-12-08 04:18:05 UTC
Permalink
eh? Glassfish 3.1 can run on jdk 1.6, not sure about 1.7 but I guess it
should run.. anyway, that sentence doesn't make much sense. @FormParam
is present in JAX-RS 1.x API so you don't need to replace it with
anything, it is just there and it should work.
Actually I have upgraded to java 7. I was using 1.6 update 7 which needed
I will download the 22 update and use it with glassfish 3.1. Still I dont
know what must be used for sending the request in case someone uses
@FormDataParam!!!
can you please look into server log (and let us know what you found
there)? And is it possible for you to share service code as well?
@POST
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Exceldatalist getJson(@FormParam("purpose") String purpose,
@FormDataParam("filename") String wbkname,
@FormDataParam("username") String username,
@FormDataParam("password") String pwd,
@FormDataParam("company") String company)
{
System.out.println("Purpose: "+purpose);
System.out.println("wbkname: "+wbkname);
System.out.println("username: "+username);
System.out.println("pwd: "+pwd);
System.out.println("company: "+company);
.
.
.
.
.
}

I've already said that the multipart jars loading which used to come on
server.log whenever deploying such web services, does not come now with
glassfish 3.1. But I can see the jars in the buildpath. jersey multipart 1.4
is on the buildpath.

I am getting a bad request resonse. I have given the log trace already.
Please help me with this...
Kavita


--
View this message in context: http://jersey.576304.n2.nabble.com/FormDataParam-gives-Bad-Request-tp7065882p7073213.html
Sent from the Jersey mailing list archive at Nabble.com.
Pavel Bucek
2011-12-08 12:03:45 UTC
Permalink
Right.

1) are you sure you are sending "multipart/form-data"? Can you dump your
request (with wireshark / something similar) and share it?

2) see @FormParam javadoc:
http://jersey.java.net/nonav/apidocs/latest/jersey/javax/ws/rs/FormParam.html.
I've found simple sample using this funcionality:
http://www.mkyong.com/webservices/jax-rs/jax-rs-formparam-example/

3) @FormDataParam is used for handling multipart queries, see mutlipart
spec: http://www.ietf.org/rfc/rfc2388.txt. You'll need to have
jersey-multipart module present on your classpath (you most likely do if
you are using glassfish). You can check our sample - multipart-webapp
[1] (linking version 1.4; it should be present in
jersey-docs-and-samples glassfish IPS package, so you might already have
that installed), please note test classes, they show how to call these
REST resources from java (using jersey client).

I asked for server log, because there should be logged some exception /
explanation declaring *why* was that request considered bad. I would
start there..

Pavel

[1]
http://search.maven.org/#artifactdetails%7Ccom.sun.jersey.samples%7Cmultipart-webapp%7C1.4%7Cwar
Post by Pavel Bucek
eh? Glassfish 3.1 can run on jdk 1.6, not sure about 1.7 but I guess it
is present in JAX-RS 1.x API so you don't need to replace it with
anything, it is just there and it should work.
Actually I have upgraded to java 7. I was using 1.6 update 7 which needed
I will download the 22 update and use it with glassfish 3.1. Still I dont
know what must be used for sending the request in case someone uses
@FormDataParam!!!
can you please look into server log (and let us know what you found
there)? And is it possible for you to share service code as well?
@POST
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
@Consumes(MediaType.MULTIPART_FORM_DATA)
@FormDataParam("filename") String wbkname,
@FormDataParam("username") String username,
@FormDataParam("password") String pwd,
@FormDataParam("company") String company)
{
System.out.println("Purpose: "+purpose);
System.out.println("wbkname: "+wbkname);
System.out.println("username: "+username);
System.out.println("pwd: "+pwd);
System.out.println("company: "+company);
.
.
.
.
.
}
I've already said that the multipart jars loading which used to come on
server.log whenever deploying such web services, does not come now with
glassfish 3.1. But I can see the jars in the buildpath. jersey multipart 1.4
is on the buildpath.
I am getting a bad request resonse. I have given the log trace already.
Please help me with this...
Kavita
--
View this message in context: http://jersey.576304.n2.nabble.com/FormDataParam-gives-Bad-Request-tp7065882p7073213.html
Sent from the Jersey mailing list archive at Nabble.com.
kavita
2011-12-15 06:50:16 UTC
Permalink
Post by Pavel Bucek
Right.
1) are you sure you are sending "multipart/form-data"? Can you dump your
request (with wireshark / something similar) and share it?
Post by Pavel Bucek
I am sending multipart/form-data. Using Firebug I can see the following
Request headers -
Host localhost:8080
User-Agent Mozilla/5.0 (Windows NT 5.1; rv:8.0) Gecko/20100101 Firefox/8.0
Accept */*
Accept-Language en-us
Accept-Encoding gzip, deflate
Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7
Connection keep-alive
Content-Type multipart/form-data
Referer http://comp1:8080/GUIForGS/gridsense/fileSelection.html
Content-Length 290
Origin http://comp1:8080
post -
-----------------------------23281168279961
Content-Disposition: form-data; name="username"
abcd#15 11 2011 12 3 10
-----------------------------23281168279961
Content-Disposition: form-data; name="wbk"
Direct mapping CCD to XLS.xls
-----------------------------23281168279961--
http://jersey.java.net/nonav/apidocs/latest/jersey/javax/ws/rs/FormParam.html.
http://www.mkyong.com/webservices/jax-rs/jax-rs-formparam-example/
Post by Pavel Bucek
@FormParam works fine with glassfish 3.0. As I have already posted
spec: http://www.ietf.org/rfc/rfc2388.txt. You'll need to have
jersey-multipart module present on your classpath (you most likely do if
you are using glassfish). You can check our sample - multipart-webapp
[1] (linking version 1.4; it should be present in
jersey-docs-and-samples glassfish IPS package, so you might already have
that installed), please note test classes, they show how to call these
REST resources from java (using jersey client).
I asked for server log, because there should be logged some exception /
explanation declaring *why* was that request considered bad. I would
start there..
Post by Pavel Bucek
I have gone through the example stated here. I was missing the second
FormDataContentDisposition. I tried adding that as well so that If I
have 3 sent values I am accepting 6 parameters in the Rest WS. This
did not work...
I am using ajax calls from html page not a java client. I have already
posted the creation of the formData object and setting in the ajax()
method of jquery.
Pavel
[1]
http://search.maven.org/#artifactdetails%7Ccom.sun.jersey.samples%7Cmultipart-webapp%7C1.4%7Cwar
Post by Pavel Bucek
eh? Glassfish 3.1 can run on jdk 1.6, not sure about 1.7 but I guess it
is present in JAX-RS 1.x API so you don't need to replace it with
anything, it is just there and it should work.
Actually I have upgraded to java 7. I was using 1.6 update 7 which needed
I will download the 22 update and use it with glassfish 3.1. Still I dont
know what must be used for sending the request in case someone uses
@FormDataParam!!!
can you please look into server log (and let us know what you found
there)? And is it possible for you to share service code as well?
@POST
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
@Consumes(MediaType.MULTIPART_FORM_DATA)
@FormDataParam("filename") String wbkname,
@FormDataParam("username") String username,
@FormDataParam("password") String pwd,
@FormDataParam("company") String company)
{
System.out.println("Purpose: "+purpose);
System.out.println("wbkname: "+wbkname);
System.out.println("username: "+username);
System.out.println("pwd: "+pwd);
System.out.println("company: "+company);
.
.
.
.
.
}
I've already said that the multipart jars loading which used to come on
server.log whenever deploying such web services, does not come now with
glassfish 3.1. But I can see the jars in the buildpath. jersey multipart 1.4
is on the buildpath.
I am getting a bad request resonse. I have given the log trace already.
Please help me with this...
Kavita
--
http://jersey.576304.n2.nabble.com/FormDataParam-gives-Bad-Request-tp7065882p7073213.html
Sent from the Jersey mailing list archive at Nabble.com.
--
View this message in context: http://jersey.576304.n2.nabble.com/FormDataParam-gives-Bad-Request-tp7065882p7096271.html
Sent from the Jersey mailing list archive at Nabble.com.
kavita
2011-12-28 03:44:22 UTC
Permalink
Hi,
Anyone who can help me resolve this????

--
View this message in context: http://jersey.576304.n2.nabble.com/FormDataParam-gives-Bad-Request-tp7065882p7131695.html
Sent from the Jersey mailing list archive at Nabble.com.
Ronak Patel
2011-12-29 14:15:24 UTC
Permalink
Hi Pavel,

I'm seeing a similar exception with Multipart sending code (from iOS) that used to work fine with Jersey < 1.5. Upgrading to Glassfish 3.1.1 (Jersey 1.9.1) has broken this and resulted in my receiving HTTP 400.

How can I turn on Hersey logs so I can see more detail of the problem?

Ronak


________________________________
From: Pavel Bucek <pavel.bucek-QHcLZuEGTsvQT0dZR+***@public.gmane.org>
To: users-ywjJWXFEILO43ww/***@public.gmane.org
Sent: Thursday, December 8, 2011 7:03 AM
Subject: [Jersey] Re: @FormDataParam gives Bad Request.

Right.

1) are you sure you are sending "multipart/form-data"? Can you dump your request (with wireshark / something similar) and share it?

2) see @FormParam javadoc: http://jersey.java.net/nonav/apidocs/latest/jersey/javax/ws/rs/FormParam.html. I've found simple sample using this funcionality: http://www.mkyong.com/webservices/jax-rs/jax-rs-formparam-example/

3) @FormDataParam is used for handling multipart queries, see mutlipart spec: http://www.ietf.org/rfc/rfc2388.txt. You'll need to have jersey-multipart module present on your classpath (you most likely do if you are using glassfish). You can check our sample - multipart-webapp [1] (linking version 1.4; it should be present in jersey-docs-and-samples glassfish IPS package, so you might already have that installed), please note test classes, they show how to call these REST resources from java (using jersey client).

I asked for server log, because there should be logged some exception / explanation declaring *why* was that request considered bad. I would start there..

Pavel

[1] http://search.maven.org/#artifactdetails%7Ccom.sun.jersey.samples%7Cmultipart-webapp%7C1.4%7Cwar
Post by Pavel Bucek
eh? Glassfish 3.1 can run on jdk 1.6, not sure about 1.7 but I guess it
is present in JAX-RS 1.x API so you don't need to replace it with
anything, it is just there and it should work.
Actually I have upgraded to java 7. I was using 1.6 update 7 which needed
I will download the 22 update and use it with glassfish 3.1. Still I dont
know what must be used for sending the request in case someone uses
@FormDataParam!!!
    can you please look into server log (and let us know what you found
there)? And is it possible for you to share service code as well?
@POST
    {
        System.out.println("Purpose: "+purpose);
        System.out.println("wbkname: "+wbkname);
        System.out.println("username: "+username);
        System.out.println("pwd: "+pwd);
        System.out.println("company: "+company);
.
.
.
.
.
          }
I've already said that the multipart jars loading which used to come on
server.log whenever deploying such web services, does not come now with
glassfish 3.1. But I can see the jars in the buildpath. jersey multipart 1.4
is on the buildpath.
I am getting a bad request resonse. I have given the log trace already.
Please help me with this...
Kavita
--
View this message in context: http://jersey.576304.n2.nabble.com/FormDataParam-gives-Bad-Request-tp7065882p7073213.html
Sent from the Jersey mailing list archive at Nabble.com.
Ronak Patel
2011-12-29 14:43:05 UTC
Permalink
Would upgrading Jersey running inside Glassfish to 1.11 fix this by chance?


________________________________
From: Ronak Patel <***@yahoo.com>
To: "users-ywjJWXFEILO43ww/***@public.gmane.org" <users-ywjJWXFEILO43ww/***@public.gmane.org>
Sent: Thursday, December 29, 2011 9:15 AM
Subject: [Jersey] Re: @FormDataParam gives Bad Request.


Hi Pavel,

I'm seeing a similar exception with Multipart sending code (from iOS) that used to work fine with Jersey < 1.5. Upgrading to Glassfish 3.1.1 (Jersey 1.9.1) has broken this and resulted in my receiving HTTP 400.

How can I turn on Hersey logs so I can see more detail of the problem?

Ronak


________________________________
From: Pavel Bucek <pavel.bucek-QHcLZuEGTsvQT0dZR+***@public.gmane.org>
To: users-***@public.gmane.orgnet
Sent: Thursday, December 8, 2011 7:03 AM
Subject: [Jersey] Re: @FormDataParam gives Bad Request.

Right.

1) are you sure you are sending "multipart/form-data"? Can you dump your request (with wireshark / something similar) and share it?

2) see @FormParam javadoc: http://jersey.java.net/nonav/apidocs/latest/jersey/javax/ws/rs/FormParam.html. I've found simple sample using this funcionality: http://www.mkyong.com/webservices/jax-rs/jax-rs-formparam-example/

3) @FormDataParam is used for handling multipart queries, see mutlipart spec: http://www.ietf.org/rfc/rfc2388.txt. You'll need to have jersey-multipart module present on your classpath (you most likely do if you are using glassfish). You can check our sample - multipart-webapp [1] (linking version 1.4; it should be present in jersey-docs-and-samples glassfish IPS package, so you might already have that installed), please note test classes, they show how to call these REST resources from java (using jersey client).

I asked for server log, because there should be logged
some exception / explanation declaring *why* was that request considered bad. I would start there..

Pavel

[1] http://search.maven.org/#artifactdetails%7Ccom.sun.jersey.samples%7Cmultipart-webapp%7C1.4%7Cwar
Post by Pavel Bucek
eh? Glassfish 3.1 can run on jdk 1.6, not sure about 1.7 but I guess it
is present in JAX-RS 1.x API so you don't need to replace it with
anything, it is just there and it should work.
Actually I have upgraded to java 7. I was using 1.6 update 7 which needed
I will download the 22 update and use it with glassfish 3.1. Still I dont
know what must be used for sending the
request in case someone uses
Post by Pavel Bucek
@FormDataParam!!!
    can you please look into server log (and let us know what you found
there)? And is it possible for you to share service code as well?
@POST
                               
    {
        System.out.println("Purpose: "+purpose);
        System.out.println("wbkname: "+wbkname);
        System.out.println("username: "+username);
        System.out.println("pwd: "+pwd);
   
    System.out.println("company: "+company);
Post by Pavel Bucek
.
.
.
.
.
          }
I've already said that the multipart jars loading which used to come on
server.log whenever deploying such web services, does not come now with
glassfish 3.1. But I can see the jars in the buildpath. jersey multipart 1.4
is on the buildpath.
I am getting a bad request resonse. I have given the log trace already.
Please help me with this...
Kavita
--
View this message in context: http://jersey.576304.n2.nabble.com/FormDataParam-gives-Bad-Request-tp7065882p7073213.html
Sent from the Jersey mailing list archive at Nabble.com.
Ronak Patel
2012-01-03 20:39:48 UTC
Permalink
Hello,

Is anyone else seeing errors similar to what I am seeing here?
I tried to check out the logging on the Jersey side using the LoggingFilters but I'm unable to see the body of the multipart request.

Is there anything else I can do to debug this?


________________________________
From: Ronak Patel <ronak2121-/***@public.gmane.org>
To: Ronak Patel <***@yahoo.com>; "users-ywjJWXFEILO43ww/***@public.gmane.org" <users-ywjJWXFEILO43ww/***@public.gmane.org>
Sent: Thursday, December 29, 2011 9:43 AM
Subject: [Jersey] Re: @FormDataParam gives Bad Request.


Would upgrading Jersey running inside Glassfish to 1.11 fix this by chance?


________________________________
From: Ronak Patel <ronak2121-/***@public.gmane.org>
To: "users-ywjJWXFEILO43ww/***@public.gmane.org" <***@jersey.java.net>
Sent: Thursday, December 29, 2011 9:15 AM
Subject: [Jersey] Re: @FormDataParam gives Bad Request.


Hi Pavel,

I'm seeing a similar exception with Multipart sending code (from iOS) that used to work fine with Jersey < 1.5. Upgrading to Glassfish 3.1.1 (Jersey 1.9.1) has broken this and resulted in my receiving HTTP 400.

How can I turn on Hersey logs so I can see more detail of the problem?

Ronak


________________________________
From: Pavel Bucek <pavel.bucek-QHcLZuEGTsvQT0dZR+***@public.gmane.org>
To: users-ywjJWXFEILO43ww/***@public.gmane.org
Sent: Thursday, December 8, 2011 7:03 AM
Subject: [Jersey] Re: @FormDataParam gives Bad Request.

Right.

1) are you sure you are sending "multipart/form-data"? Can you dump your request (with wireshark / something similar) and share it?

2) see @FormParam javadoc: http://jersey.java.net/nonav/apidocs/latest/jersey/javax/ws/rs/FormParam.html. I've found simple sample using this funcionality: http://www.mkyong.com/webservices/jax-rs/jax-rs-formparam-example/

3) @FormDataParam is used for handling multipart queries, see mutlipart spec: http://www.ietf.org/rfc/rfc2388.txt. You'll need to have jersey-multipart module present on your classpath (you most likely do if you are using glassfish). You can check our sample - multipart-webapp [1] (linking version 1.4; it should be present in jersey-docs-and-samples glassfish IPS package, so you might already have that installed), please note test classes, they show how to call these REST resources from java (using jersey client).

I asked for server log, because there should be logged
some exception / explanation declaring *why* was that request considered bad. I would start there..

Pavel

[1] http://search.maven.org/#artifactdetails%7Ccom.sun.jersey.samples%7Cmultipart-webapp%7C1.4%7Cwar
Post by Pavel Bucek
eh? Glassfish 3.1 can run on jdk 1.6, not sure about 1.7 but I guess it
is present in JAX-RS 1.x API so you don't need to replace it with
anything, it is just there and it should work.
Actually I have upgraded to java 7. I was using 1.6 update 7 which needed
I will download the 22 update and use it with glassfish 3.1. Still I dont
know what must be used for sending the
request in case someone uses
Post by Pavel Bucek
@FormDataParam!!!
    can you please look into server log (and let us know what you found
there)? And is it possible for you to share service code as well?
@POST
                               
    {
        System.out.println("Purpose: "+purpose);
        System.out.println("wbkname: "+wbkname);
        System.out.println("username: "+username);
        System.out.println("pwd: "+pwd);
   
    System.out.println("company: "+company);
Post by Pavel Bucek
.
.
.
.
.
          }
I've already said that the multipart jars loading which used to come on
server.log whenever deploying such web services, does not come now with
glassfish 3.1. But I can see the jars in the buildpath. jersey multipart 1.4
is on the buildpath.
I am getting a bad request resonse. I have given the log trace already.
Please help me with this...
Kavita
--
View this message in context: http://jersey.576304.n2.nabble.com/FormDataParam-gives-Bad-Request-tp7065882p7073213.html
Sent from the Jersey mailing list archive at Nabble.com.
Loading...