Ho scritto una classe semplice per testare il metodo dell'entità di lettura risposta (se funziona come previsto). Ma non ha funzionato bene.IllegalStateException all'interno del metodo con parametro di risposta
Quando lancio la mia classe vengo seguente errore al 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)
Ed ecco il codice che ho scritto
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));
}
Che cosa sto facendo di sbagliato?