I am trying to make Rest client call by using jersey :

here is my code :

java code :

Client client =  ClientBuilder.newClient();
           FormDataMultiPart formData = new FormDataMultiPart();
           formData.field("options", "docUpload");
           formData.bodyPart(new FileDataBodyPart("file", file));
            Response response =  client.target(TARGET_END_POINT + SUBMIT_DOCUMENT)
                    .request(MediaType.MULTIPART_FORM_DATA)
                    .post(Entity.entity(formData, formData.getMediaType()));

following are my dependency :

<dependency>
    <groupId>com.sun.jersey</groupId>
    <artifactId>jersey-core</artifactId>
    <version>1.19.4</version>
    <exclusions>
        <exclusion>
            <groupId>javax.ws.rs</groupId>
            <artifactId>jsr311-api</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>org.jvnet.mimepull</groupId>
    <artifactId>mimepull</artifactId>
    <version>1.9.13</version>
</dependency>
<dependency>
    <groupId>org.glassfish.jersey.core</groupId>
    <artifactId>jersey-client</artifactId>
    <version>2.34</version>
</dependency>
<dependency>
    <groupId>org.glassfish.jersey.core</groupId>
    <artifactId>jersey-common</artifactId>
    <version>2.34</version>
</dependency>
<dependency>
    <groupId>org.glassfish.jersey.containers</groupId>
    <artifactId>jersey-container-servlet</artifactId>
    <version>2.34</version>
</dependency>
<dependency>
    <groupId>org.glassfish.jersey.containers</groupId>
    <artifactId>jersey-container-servlet-core</artifactId>
    <version>2.34</version>
</dependency>
<dependency>
    <groupId>org.glassfish.jersey.media</groupId>
    <artifactId>jersey-media-jaxb</artifactId>
    <version>2.34</version>
</dependency>
<dependency>
    <groupId>org.glassfish.jersey.media</groupId>
    <artifactId>jersey-media-multipart</artifactId>
    <version>2.34</version>
    <exclusions>
        <exclusion>
            <groupId>org.jvnet.mimepull</groupId>
            <artifactId>mimepull</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>org.glassfish.jersey.core</groupId>
    <artifactId>jersey-server</artifactId>
    <version>2.34</version>
</dependency>

but on invoking post call in above method I am getting following stacktrace :

javax.ws.rs.ProcessingException: No message body writer has been found for class org.glassfish.jersey.media.multipart.FormDataMultiPart, ContentType: multipart/form-data         at org.apache.cxf.jaxrs.client.AbstractClient.reportMessageHandlerProblem(AbstractClient.java:853)         at org.apache.cxf.jaxrs.client.AbstractClient.writeBody(AbstractClient.java:539)         at org.apache.cxf.jaxrs.client.WebClient$BodyWriter.doWriteBody(WebClient.java:1223)         at org.apache.cxf.jaxrs.client.AbstractClient$AbstractBodyWriter.handleMessage(AbstractClient.java:1223)         at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:307)         at org.apache.cxf.jaxrs.client.AbstractClient.doRunInterceptorChain(AbstractClient.java:710)         at org.apache.cxf.jaxrs.client.WebClient.doChainedInvocation(WebClient.java:1086)         at org.apache.cxf.jaxrs.client.WebClient.doInvoke(WebClient.java:932)         at org.apache.cxf.jaxrs.client.WebClient.doInvoke(WebClient.java:901)         at org.apache.cxf.jaxrs.client.WebClient.invoke(WebClient.java:461)         at org.apache.cxf.jaxrs.client.SyncInvokerImpl.method(SyncInvokerImpl.java:150)         at org.apache.cxf.jaxrs.client.SyncInvokerImpl.method(SyncInvokerImpl.java:145)         at org.apache.cxf.jaxrs.client.SyncInvokerImpl.post(SyncInvokerImpl.java:85)         at org.apache.cxf.jaxrs.client.spec.InvocationBuilderImpl.post(InvocationBuilderImpl.java:153)

Can someone guide me what exactly is going wrong in this case.

I tried to register multipartfeature as part of client in above code but that also did not work

0

There are 0 best solutions below