java - No message body writer has been found for MultipartBody, multipart/form-data -
i'm calling rest url through cxf client upload xml file :
webclient webclient = webclient.create("some base uri") .header("authorization",createauthorizationheader); webclient.encoding("utf-8"); webclient.type(mediatype.multipart_form_data); contentdisposition cd = new contentdisposition("attachment;filename=abc.xml"); attachment att = new attachment("root", stream, cd); response response = webclient.post(new multipartbody(att));
but i'm getting following exception while post call
javax.ws.rs.processingexception: no message body writer has been found class org.apache.cxf.jaxrs.ext.multipart.multipartbody, contenttype: multipart/form-data
i tried adding providers :
list providers = new arraylist(); providers.add(new org.codehaus.jackson.jaxrs.jacksonjsonprovider()); providers.add(new org.apache.cxf.jaxrs.provider.multipartprovider()); webclient webclient = webclient.create(constant.getuploaduri(),providers) .header("authorization",createauthorizationheader);
still i'm getting same exception
i tested configuration works here entire test file
import java.io.fileinputstream; import javax.ws.rs.core.mediatype; import javax.ws.rs.core.response; import org.apache.cxf.jaxrs.client.webclient; import org.apache.cxf.jaxrs.ext.multipart.attachment; import org.apache.cxf.jaxrs.ext.multipart.contentdisposition; import org.apache.cxf.jaxrs.ext.multipart.multipartbody; import org.junit.test; public class kpuploadtest { @test public void testupload() { try (fileinputstream stream = new fileinputstream("d:\\uploadtest.txt");) { webclient webclient = webclient .create("http://localhost:8080/api/kp/rest/upload"); webclient.encoding("utf-8"); webclient.type(mediatype.multipart_form_data); contentdisposition cd = new contentdisposition( "attachment;filename=abc.xml"); attachment att = new attachment("root", stream, cd); response response = webclient.post(new multipartbody(att)); system.out.println(response.readentity(string.class)); } catch (exception ex) { ex.printstacktrace(); } } }
please share failing, server side or client side? further pinpoint error. , cxf jaxrs version using
Comments
Post a Comment