admin管理员组

文章数量:1317898

I have this function for POST http calls:

public static String post(ActorSystem system, String uri, String json) throws Exception {
    try {
        HttpRequest post = HttpRequest.POST(uri).withEntity(HttpEntities.create(ContentTypes.APPLICATION_JSON, json));
        return Http.get(system).singleRequest(post).thenCompose(response -> {
            if (response.status().isFailure()) {
                response.discardEntityBytes(system);
                return CompletableFuturepletedFuture(null);
            }
            else{
                return Unmarshaller.entityToString().unmarshal(response.entity(), system);
            }
        }).toCompletableFuture().get();
    } catch (Exception e) {
        throw e;
    }
}

Sometimes receive this error:

java.util.concurrent.TimeoutException: Response entity was not subscribed after 5 seconds. Make sure to read the response entity body or call entity.discardBytes() on it -- in case you deal with HttpResponse, use the shortcut response.discardEntityBytes(). POST /some/path/service Strict(38450 bytes) -> 200 OK Chunked

I have see the warning note in .html

How to I can fix/solve this in "else" case?

Tnx

ps: increment timeout is a weak solution :(

本文标签: javaAkka entitydiscardBytes with Unmarshaller functionStack Overflow