Reputation: 1645
I am working on a project in which server side I have used REST Service for my APIs.These API are working fine from RESTClient plugin. Now I am invoking these REST API from a servlet code.After exploration I came to know REST Easy will be best choice when you have to make your call to REST API.So I used REST Easy to call my server REST API. Now on server side there is an API to upload a file.For upload a file from REST Easy I have to use multipartFormData to send stream to server.
String id = request.getParameter("id");
String serverUrl = request.getParameter("serverHostUrl");
ClientRequestFactory crf = new ClientRequestFactory();
IFileUpload client = crf.createProxy(IFileUpload.class, serverUrl);
MultipartFormDataOutput mdo = new MultipartFormDataOutput();
mdo.addFormData("fileName", fileBufferReader, MediaType.MULTIPART_FORM_DATA_TYPE);
client.uploadContactsInCCExclusionLead("unique-key", new Integer(id`enter code here`), mdo);
If I try to run this code from a main of class it is working fine.But when I am calling it from a servlet which is extending UploadServlet which is in gwt-upload.jar it is throwing exception :
could not find writer for content-type multipart/form-data type
Upvotes: 1
Views: 1136