1
在我的項目中,我打電話給一個休息服務,它返回MediaType.APPLICATION_OCTET_STREAM
。 我已經爲此寫了一個球衣客戶端。但我沒有得到500
錯誤。 在日誌中我看到的錯誤:jax-rs客戶端下載文件
SEVERE: MessageBodyWriter not found for media type=application/octet-stream, type=class java.io.ByteArrayOutputStream, genericType=class java.io.ByteArrayOutputStream.
編寫的代碼如下,
ClientConfig clientConfig = null;
Client client = null;
WebTarget webTarget = null;
Invocation.Builder invocationBuilder = null;
Response response = null;
InputStream inputStream = null;
OutputStream outputStream = null;
int responseCode;
String responseMessageFromServer = null;
String responseString = null;
String qualifiedDownloadFilePath = null;
try{
// invoke service after setting necessary parameters
clientConfig = new ClientConfig();
// clientConfig.register(MultiPartWriter.class);
//clientConfig.register(MessageBodyWriter.class);
clientConfig.register(MultiPartFeature.class);
client = ClientBuilder.newClient(clientConfig);
client.property("accept", "application/octet-stream");
webTarget = client.target("http://localhost:8080/EarchivePOC/archive/1");
// invoke service
invocationBuilder = webTarget.request();
// invocationBuilder.header("Authorization", "Basic " + authorization);
response = invocationBuilder.get();
// get response code
responseCode = response.getStatus();
System.out.println("Response code: " + responseCode);
可能有人請幫助,如果我失去了一些東西。
由於提前, 小鷹