users@jersey.java.net

[Jersey] Re: A message body writer for Java type, class com.sun.jersey.multipart.FormDataMultiPart, and MIME media type, multipart/form-data, was not found

From: Jitesh Sinha -X (jisinha - Siliconweb Inc. at Cisco) <"Jitesh>
Date: Tue, 2 Aug 2011 15:48:29 -0700

I have attached the whole client side java file to make things clear.

 

From: Jitesh Sinha -X (jisinha - Siliconweb Inc. at Cisco)
Sent: Tuesday, August 02, 2011 3:39 PM
To: users_at_jersey.java.net
Subject: [Jersey] A message body writer for Java type, class
com.sun.jersey.multipart.FormDataMultiPart, and MIME media type,
multipart/form-data, was not found

 

Hi All,

 

I am writing a java application class that will call a Rest Web
service(written by me).I am able to access it from inside Spring
controller but when I try to access it from inside a Java application(A
class having main method),I get errors.

Here is my client side code -

 

C:\Javatest>public static void main(String args[])

                throws Exception

                {

 

 

                                String
requestUrl="http://alt-plutonium:8080/altcso/service/request";

                                Client client = Client.create();

 

                                WebResource service =
client.resource(requestUrl);//http://alt-plutonim:8080/altcso/service/re
quest

 

 
//sourceLanguage,targetLanguage,inputFormat,tmx,byte array
uploadFile,priority,profile,uploadFileName

 

                                //new File("");

 

                                //byte []array =

 

 

                                FormDataMultiPart formData = new
MyClient().setAndGetFormData("EN","JA","txt",

                                                                "N",new
MyClient().getBytesFromFile(new File("c:/test.txt")),"low","","out");

 

 

                                ClientResponse response =
service.type(MediaType.MULTIPART_FORM_DATA).header("appkey","54686973497
3434e53").post(ClientResponse.class,formData);

 

 

                                String responseString =
response.getEntity(String.class) ;//status if input was accepted.

 

                                //

 

 

 

                }

 

 

 

And the error that I am getting is like this -

 

Exception in thread "main"
com.sun.jersey.api.client.ClientHandlerException:
com.sun.jersey.api.client.ClientHandlerException: A message body writer
for Java type, class com.sun.jersey.multipart.FormDataMultiPart, and
MIME media type, multipart/form-data, was not found

                at
com.sun.jersey.client.urlconnection.URLConnectionClientHandler.handle(UR
LConnectionClientHandler.java:149)

                at
com.sun.jersey.api.client.Client.handle(Client.java:648)

                at
com.sun.jersey.api.client.WebResource.handle(WebResource.java:670)

                at
com.sun.jersey.api.client.WebResource.access$200(WebResource.java:74)

                at
com.sun.jersey.api.client.WebResource$Builder.post(WebResource.java:563)

                at
com.cisco.altcso.service.MyClient.main(MyClient.java:48)

Caused by: com.sun.jersey.api.client.ClientHandlerException: A message
body writer for Java type, class
com.sun.jersey.multipart.FormDataMultiPart, and MIME media type,
multipart/form-data, was not found

                at
com.sun.jersey.api.client.RequestWriter.writeRequestEntity(RequestWriter
.java:288)

                at
com.sun.jersey.client.urlconnection.URLConnectionClientHandler._invoke(U
RLConnectionClientHandler.java:204)

                at
com.sun.jersey.client.urlconnection.URLConnectionClientHandler.handle(UR
LConnectionClientHandler.java:147)

                ... 5 more

 

The error is pointing to this line -

 ClientResponse response =
service.type(MediaType.MULTIPART_FORM_DATA).header("appkey","54686973497
3434e53").post(ClientResponse.class,formData);

 

 

What am I missing?

 

 

Thanks

-Jitesh