Search in sources :

Example 11 with ReadStreamPart

use of org.apache.servicecomb.foundation.vertx.http.ReadStreamPart in project incubator-servicecomb-java-chassis by apache.

the class TestCodeFirstJaxrs method testDeleteAfterFinished.

private void testDeleteAfterFinished() throws Exception {
    ReadStreamPart part = downloadInf.testDeleteAfterFinished("hello", "hello content");
    TestMgr.check(part.saveAsString().get(), "hello content");
    File systemTempFile = new File(System.getProperty("java.io.tmpdir"));
    File file = new File(systemTempFile, "hello");
    TestMgr.check(file.exists(), false);
}
Also used : ReadStreamPart(org.apache.servicecomb.foundation.vertx.http.ReadStreamPart) File(java.io.File)

Example 12 with ReadStreamPart

use of org.apache.servicecomb.foundation.vertx.http.ReadStreamPart in project incubator-servicecomb-java-chassis by apache.

the class TestDownload method templateExchange.

private ReadStreamPart templateExchange(String methodPath, String type) {
    HttpHeaders headers = new HttpHeaders();
    headers.add("accept", type);
    HttpEntity<?> entity = new HttpEntity<>(headers);
    ResponseEntity<ReadStreamPart> response = consumers.getSCBRestTemplate().exchange("/" + methodPath + "?content={content}", HttpMethod.GET, entity, ReadStreamPart.class, content);
    return response.getBody();
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ReadStreamPart(org.apache.servicecomb.foundation.vertx.http.ReadStreamPart) HttpEntity(org.springframework.http.HttpEntity)

Example 13 with ReadStreamPart

use of org.apache.servicecomb.foundation.vertx.http.ReadStreamPart in project incubator-servicecomb-java-chassis by apache.

the class RestClientSender method processResponse.

protected Future<Buffer> processResponse(HttpClientResponse httpClientResponse) {
    transportContext.setHttpClientResponse(httpClientResponse);
    if (HttpStatus.isSuccess(httpClientResponse.statusCode()) && transportContext.isDownloadFile()) {
        ReadStreamPart streamPart = new ReadStreamPart(transportContext.getVertxContext(), httpClientResponse);
        future.complete(createResponse(httpClientResponse, streamPart));
    }
    return httpClientResponse.body();
}
Also used : ReadStreamPart(org.apache.servicecomb.foundation.vertx.http.ReadStreamPart)

Example 14 with ReadStreamPart

use of org.apache.servicecomb.foundation.vertx.http.ReadStreamPart in project incubator-servicecomb-java-chassis by apache.

the class RestClientInvocation method handleResponse.

protected void handleResponse(HttpClientResponse httpClientResponse) {
    this.clientResponse = httpClientResponse;
    if (HttpStatus.isSuccess(clientResponse.statusCode()) && restOperationMeta.isDownloadFile()) {
        ReadStreamPart part = new ReadStreamPart(httpClientWithContext.context(), httpClientResponse);
        invocation.getHandlerContext().put(RestConst.READ_STREAM_PART, part);
        processResponseBody(null);
        return;
    }
    httpClientResponse.exceptionHandler(e -> {
        invocation.getTraceIdLogger().error(LOGGER, "Failed to receive response, local:{}, remote:{}, message={}.", getLocalAddress(), httpClientResponse.netSocket().remoteAddress(), ExceptionUtils.getExceptionMessageWithoutTrace(e));
        fail(e);
    });
    clientResponse.bodyHandler(this::processResponseBody);
}
Also used : ReadStreamPart(org.apache.servicecomb.foundation.vertx.http.ReadStreamPart)

Aggregations

ReadStreamPart (org.apache.servicecomb.foundation.vertx.http.ReadStreamPart)14 RestTemplate (org.springframework.web.client.RestTemplate)6 File (java.io.File)2 HttpEntity (org.springframework.http.HttpEntity)2 HttpHeaders (org.springframework.http.HttpHeaders)2