0
我需要使用上传文件API。我使用Jersy创建了客户端,它给了我适当的回应。这里是示例代码:Jersy Rest客户端到Apache CXF客户端转换
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()));
但在我的项目中,我本来应该使用CXF,我试图用CXF实现同样的事情。这是我尝试过的。
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);
但在这里我没有得到任何回应。它继续加载。即使在我的日志中也没有得到任何错误。
我错过了什么?请帮助我得到适当的回应。
你是怎么创建'webClient'的?似乎网址不正确 – pedrofb
没有网址是正确的。我没有在该代码片段中添加该代码的详细信息。 – Ramesh
什么是响应代码?服务器是否响应? – pedrofb