I need to consume upload file API. I have created client using Jersy and it gives me proper response. Here is that sample code:
final Client client = ClientBuilder.newBuilder().register(MultiPartFeature.class).build();
FileDataBodyPart filePart = new FileDataBodyPart("file", new File("somePath/fileName.txt"));
FormDataMultiPart formDataMultiPart = new FormDataMultiPart();
FormDataMultiPart multipart = (FormDataMultiPart) formDataMultiPart.field("someField", "001").bodyPart(filePart);
final WebTarget target = client.target("http://serverUrl.com:8000/cq5/uploadApi");
final Response response = target.request().post(Entity.entity(multipart, multipart.getMediaType()));
But in my project I was supposed to use CXF, I tried to achieve the same thing with CXF. This is what I have tried.
String path = "/uploadApi";
WebClient topicWebClient = WebClient.fromClient(webClient, true)
.type(MediaType.MULTIPART_FORM_DATA).path(path);
ContentDisposition cd = new ContentDisposition("attachment;filename=fileName.txt");
Attachment att = new Attachment("file", new ByteArrayInputStream("testContent".getBytes()), cd);
final Response response = topicWebClient.post(att);
But here I am not getting any response. Its keep on loading. Not getting any error even in my logs also.
Anything am I missing? Please help me to get proper response.