我正在努力使用JAX-RS编写的REST服务。
我想使用以下代码创建和绑定客户端:
final String DEFAULT_RESOURCE_URL = "http://someURL:8180/";
try {
ResteasyClient client = new ResteasyClientBuilder().build().register(ClientResponseLoggingFilter.class);
ResteasyWebTarget target = client.target(DEFAULT_RESOURCE_URL).path(
"service/document/getdrawingbrowser/{documentId}/{documentType}/{partDocumentId}/{documentVersion}/{userName}");
HashMap<String, Object> keyValuesMap = new HashMap<String, Object>();
keyValuesMap.put("documentId", "xxxx");
keyValuesMap.put("documentType", "yyy");
keyValuesMap.put("partDocumentId", "000");
keyValuesMap.put("documentVersion", "000");
keyValuesMap.put("userName", "user");
Builder responseBuilder = target.resolveTemplates(keyValuesMap).request();
Response response = responseBuilder.get();
if (response.getStatus() == 200) {
byte[][] documents = response.readEntity(byte[][].class);
for (int i = 0; i < documents.length; i++) {
displayProperties(documents[i]);
}
} else {
Object entity = response.getEntity();
System.out.println(entity);
}
} catch (Throwable e) {
e.printStackTrace();
}
}
REST-Service正确响应我想:
status: 200
date: Mon Sep 14 10:53:02 CEST 2015
last-modified: null
location: null
headers:
Connection :keep-alive,
Content-Disposition :attachment; filename=someFile.pdf,
Content-Type :application/octet-stream,
Date :Mon, 14 Sep 2015 08:53:02 GMT,
Server :WildFly/8,
Transfer-Encoding :chunked,
X-Powered-By :Undertow/1,
media-type: application
但是在第102行byte[][] documents = response.readEntity(byte[][].class);
我得到的javax.ws.rs.ProcessingException
说:
javax.ws.rs.ProcessingException: Unable to find a MessageBodyReader of content-type application/octet-stream and type class [[B
at org.jboss.resteasy.core.interception.ClientReaderInterceptorContext.throwReaderNotFound(ClientReaderInterceptorContext.java:39)
at org.jboss.resteasy.core.interception.AbstractReaderInterceptorContext.getReader(AbstractReaderInterceptorContext.java:73)
at org.jboss.resteasy.core.interception.AbstractReaderInterceptorContext.proceed(AbstractReaderInterceptorContext.java:50)
at org.jboss.resteasy.plugins.interceptors.encoding.GZIPDecodingInterceptor.aroundReadFrom(GZIPDecodingInterceptor.java:59)
at org.jboss.resteasy.core.interception.AbstractReaderInterceptorContext.proceed(AbstractReaderInterceptorContext.java:53)
at org.jboss.resteasy.client.jaxrs.internal.ClientResponse.readFrom(ClientResponse.java:248)
at org.jboss.resteasy.client.jaxrs.internal.ClientResponse.readEntity(ClientResponse.java:181)
at org.jboss.resteasy.specimpl.BuiltResponse.readEntity(BuiltResponse.java:217)
at DocumentTest.main(DocumentTest.java:102)
我已经尝试了几个.jar文件以及here和here的一些方法,但遗憾的是,它们都没有成功...
有什么想法吗?