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