非法状态方法中的异常与响应参数
2022-09-02 19:25:03
我写了一个简单的类来测试响应读取实体方法(如果它像我预期的那样工作)。但它效果不佳。
当我启动我的类时,我在以下错误:response.readEntity()
Exception in thread "main" java.lang.IllegalStateException: Method not supported on an outbound message. at org.glassfish.jersey.message.internal.OutboundJaxrsResponse.readEntity(OutboundJaxrsResponse.java:150)
这是我写的代码
public static void main(String[] args) {
List<Entity> representations = new ArrayList<>();
representations.add(new Entity("foo", "baz", false));
representations.add(new Entity("foo1", "baz1", true));
representations.add(new Entity("foo2", "baz2", false));
Response build = Response.ok(representations).build();
printEntitesFromResponse(build);
}
public static void printEntitesFromResponse(Response response) {
response
.readEntity(new GenericType<List<Entity>>() {})
.stream()
.forEach(entity -> System.out.println(entity));
}
我做错了什么?