Search in sources :

Example 6 with HttpStatus

use of cn.taketoday.http.HttpStatus in project today-infrastructure by TAKETODAY.

the class ErrorHandlerIntegrationTests method emptyPathSegments.

@ParameterizedHttpServerTest
// SPR-15560
void emptyPathSegments(HttpServer httpServer) throws Exception {
    startServer(httpServer);
    RestTemplate restTemplate = new RestTemplate();
    restTemplate.setErrorHandler(NO_OP_ERROR_HANDLER);
    URI url = new URI("http://localhost:" + port + "//");
    ResponseEntity<String> response = restTemplate.getForEntity(url, String.class);
    // Jetty 10+ rejects empty path segments, see https://github.com/eclipse/jetty.project/issues/6302,
    // but an application can apply CompactPathRule via RewriteHandler:
    // https://www.eclipse.org/jetty/documentation/jetty-11/programming_guide.php
    HttpStatus expectedStatus = (httpServer instanceof JettyHttpServer ? HttpStatus.BAD_REQUEST : HttpStatus.OK);
    assertThat(response.getStatusCode()).isEqualTo(expectedStatus);
}
Also used : HttpStatus(cn.taketoday.http.HttpStatus) RestTemplate(cn.taketoday.web.client.RestTemplate) URI(java.net.URI) JettyHttpServer(cn.taketoday.web.testfixture.http.server.reactive.bootstrap.JettyHttpServer)

Example 7 with HttpStatus

use of cn.taketoday.http.HttpStatus in project today-framework by TAKETODAY.

the class ErrorResponseException method getMessage.

@Override
public String getMessage() {
    HttpStatus httpStatus = HttpStatus.resolve(this.status);
    String message = (httpStatus != null ? httpStatus : String.valueOf(this.status)) + (!this.headers.isEmpty() ? ", headers=" + this.headers : "") + ", " + this.body;
    return ExceptionUtils.buildMessage(message, getCause());
}
Also used : HttpStatus(cn.taketoday.http.HttpStatus)

Example 8 with HttpStatus

use of cn.taketoday.http.HttpStatus in project today-framework by TAKETODAY.

the class DefaultClientResponseTests method statusCode.

@Test
public void statusCode() {
    HttpStatus status = HttpStatus.CONTINUE;
    given(mockResponse.getStatusCode()).willReturn(status);
    assertThat(defaultClientResponse.statusCode()).isEqualTo(status);
}
Also used : HttpStatus(cn.taketoday.http.HttpStatus) Test(org.junit.jupiter.api.Test)

Example 9 with HttpStatus

use of cn.taketoday.http.HttpStatus in project today-framework by TAKETODAY.

the class ClientResponseWrapperTests method statusCode.

@Test
public void statusCode() {
    HttpStatus status = HttpStatus.BAD_REQUEST;
    given(mockResponse.statusCode()).willReturn(status);
    assertThat(wrapper.statusCode()).isSameAs(status);
}
Also used : HttpStatus(cn.taketoday.http.HttpStatus) Test(org.junit.jupiter.api.Test)

Example 10 with HttpStatus

use of cn.taketoday.http.HttpStatus in project today-framework by TAKETODAY.

the class ErrorHandlerIntegrationTests method emptyPathSegments.

@ParameterizedHttpServerTest
// SPR-15560
void emptyPathSegments(HttpServer httpServer) throws Exception {
    startServer(httpServer);
    RestTemplate restTemplate = new RestTemplate();
    restTemplate.setErrorHandler(NO_OP_ERROR_HANDLER);
    URI url = new URI("http://localhost:" + port + "//");
    ResponseEntity<String> response = restTemplate.getForEntity(url, String.class);
    // Jetty 10+ rejects empty path segments, see https://github.com/eclipse/jetty.project/issues/6302,
    // but an application can apply CompactPathRule via RewriteHandler:
    // https://www.eclipse.org/jetty/documentation/jetty-11/programming_guide.php
    HttpStatus expectedStatus = (httpServer instanceof JettyHttpServer ? HttpStatus.BAD_REQUEST : HttpStatus.OK);
    assertThat(response.getStatusCode()).isEqualTo(expectedStatus);
}
Also used : HttpStatus(cn.taketoday.http.HttpStatus) RestTemplate(cn.taketoday.web.client.RestTemplate) URI(java.net.URI) JettyHttpServer(cn.taketoday.web.testfixture.http.server.reactive.bootstrap.JettyHttpServer)

Aggregations

HttpStatus (cn.taketoday.http.HttpStatus)17 Test (org.junit.jupiter.api.Test)8 Mono (reactor.core.publisher.Mono)5 ClientResponse (cn.taketoday.web.reactive.function.client.ClientResponse)4 URI (java.net.URI)4 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)4 TypeReference (cn.taketoday.core.TypeReference)3 DataBuffer (cn.taketoday.core.io.buffer.DataBuffer)3 DataBufferUtils (cn.taketoday.core.io.buffer.DataBufferUtils)3 HttpHeaders (cn.taketoday.http.HttpHeaders)3 MediaType (cn.taketoday.http.MediaType)3 ResponseEntity (cn.taketoday.http.ResponseEntity)3 BodyExtractors (cn.taketoday.web.reactive.function.BodyExtractors)3 Collections (java.util.Collections)3 Map (java.util.Map)3 StepVerifier (reactor.test.StepVerifier)3 DataBufferFactory (cn.taketoday.core.io.buffer.DataBufferFactory)2 DefaultDataBufferFactory (cn.taketoday.core.io.buffer.DefaultDataBufferFactory)2 NettyDataBufferFactory (cn.taketoday.core.io.buffer.NettyDataBufferFactory)2 AbstractDataBufferAllocatingTests (cn.taketoday.core.testfixture.io.buffer.AbstractDataBufferAllocatingTests)2