Search in sources :

Example 1 with ReadStreamPart

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

the class TestDownloadSchema method testDownloadFileAndDeleted.

private void testDownloadFileAndDeleted() throws Exception {
    RestTemplate restTemplate = RestTemplateBuilder.create();
    ReadStreamPart readStreamPart = restTemplate.getForObject("servicecomb://springmvc/download/deleteAfterFinished?content=hello", ReadStreamPart.class);
    String hello = readStreamPart.saveAsString().get();
    TestMgr.check(hello, "hello");
    boolean exists = restTemplate.getForObject("servicecomb://springmvc/download/assertLastFileDeleted", boolean.class);
    TestMgr.check(exists, false);
}
Also used : ReadStreamPart(org.apache.servicecomb.foundation.vertx.http.ReadStreamPart) RestTemplate(org.springframework.web.client.RestTemplate)

Example 2 with ReadStreamPart

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

the class TestDownloadSchema method testDownloadFileNotDeleted.

private void testDownloadFileNotDeleted() throws Exception {
    RestTemplate restTemplate = RestTemplateBuilder.create();
    ReadStreamPart readStreamPart = restTemplate.getForObject("servicecomb://springmvc/download/notDeleteAfterFinished?content=hello", ReadStreamPart.class);
    String hello = readStreamPart.saveAsString().get();
    TestMgr.check(hello, "hello");
    boolean exists = restTemplate.getForObject("servicecomb://springmvc/download/assertLastFileDeleted", boolean.class);
    TestMgr.check(exists, true);
}
Also used : ReadStreamPart(org.apache.servicecomb.foundation.vertx.http.ReadStreamPart) RestTemplate(org.springframework.web.client.RestTemplate)

Example 3 with ReadStreamPart

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

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)

Example 4 with ReadStreamPart

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

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 5 with ReadStreamPart

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

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)

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