我正在尝试使用 InMemoryClientExecutor 调用本地 JVM 上的服务,这些服务返回 javax.ws.rs.core.Response 对象。我可以让它工作,但只能通过像这样指定 String 类型:
String response = new ClientRequest("/myService", executor)
.get(String.class)
.getEntity();
由于服务的签名是这样的:
@GET
@Path("/myService")
public Response getSomeData(@Form MyFormBean bean) {
//...blah...
}
但是,我想取回实际的 Response 对象,以便我可以取出实体并在我的新“聚合”响应中返回这些对象。当我只返回字符串时,Jackson Parser 不会将其视为 JSON,而只是一个常规字符串,因此它会执行诸如将换行符编码为 \n 等操作。
每当我做类似的事情时:
String response = new ClientRequest("/myService",executor)
.get(Response.class)
.getEntity();
甚至这只是为了获取普通的请求对象:
String response = new ClientRequest("/myService", executor).get().getEntity();
我得到以下异常:
Exception Occured: org.jboss.resteasy.client.ClientResponseFailure: Unable to find a MessageBodyReader of content-type application/json and type null
at org.jboss.resteasy.client.core.BaseClientResponse.createResponseFailure(BaseClientResponse.java:523)
at org.jboss.resteasy.client.core.BaseClientResponse.createResponseFailure(BaseClientResponse.java:514)
at org.jboss.resteasy.client.core.BaseClientResponse.readFrom(BaseClientResponse.java:415)
at org.jboss.resteasy.client.core.BaseClientResponse.getEntity(BaseClientResponse.java:377)
at org.jboss.resteasy.client.core.BaseClientResponse.getEntity(BaseClientResponse.java:338)
再往下还有:
Servlet.service() for servlet Resteasy threw exception: org.jboss.resteasy.spi.LoggableFailure: Unable to find contextual data of type: javax.servlet.http.HttpServletRequest
at org.jboss.resteasy.core.ContextParameterInjector$GenericDelegatingProxy.invoke(ContextParameterInjector.java:56)
at $Proxy210.getScheme(Unknown Source)
我哪里错了?