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