Can't get all parts of a chunked based web service

(Yarichard) #1

Hi everyone,
we’re calling a web service on an Axis brand camera to get some infos. It serves the response as a plain/text chunked response, and we can’t manage to get all data in a play web service call.

Here is the code we’re using:

public CompletionStage<Result> getAxisDeviceInfosTest(String axisUrl){
    // Make the request
    CompletionStage<WSResponse> futureResponse = ws.url(axisUrl).setMethod("GET").stream();
    CompletionStage<Result> result = futureResponse.thenApply(response -> {
        Source<ByteString, ?> body = response.getBodyAsSource();;
        // Check that the response was successful
        if (response.getStatus() == 200) {
            // Get the content type
            String contentType =
                            .map(contentTypes -> contentTypes.get(0))

            // If there's a content length, send that, otherwise return the body chunked
            Optional<String> contentLength = Optional.ofNullable(response.getHeaders()
                    .map(contentLengths -> contentLengths.get(0));
            if (contentLength.isPresent()) {
                return Results.ok().sendEntity(new HttpEntity.Streamed(
            } else {
                return Results.ok().chunked(body).as(contentType);
        } else {
            return new Result(Http.Status.BAD_GATEWAY);
    return result;

everytime this route returns only the first part of the camera result, not the full content.
Calling the web service directly from a tool that handles chunked responses work.

We also tried the simple way by calling a

public CompletionStage<Result> getAxisDeviceInfos(String axisUrl){
    return ws.url(axisUrl).get().thenApply(r -> {;
        return Results.ok(r.getBody());

Same result. Any idea of what we’re doing wrong ?
Thanks in advance,