Search in sources :

Example 51 with HttpHeaders

use of org.springframework.http.HttpHeaders in project spring-framework by spring-projects.

the class DefaultClientResponseTests method bodyToMonoError.

@Test
public void bodyToMonoError() throws Exception {
    HttpHeaders httpHeaders = new HttpHeaders();
    httpHeaders.setContentType(MediaType.TEXT_PLAIN);
    when(mockResponse.getHeaders()).thenReturn(httpHeaders);
    when(mockResponse.getStatusCode()).thenReturn(HttpStatus.NOT_FOUND);
    Set<HttpMessageReader<?>> messageReaders = Collections.singleton(new DecoderHttpMessageReader<String>(new StringDecoder()));
    when(mockExchangeStrategies.messageReaders()).thenReturn(messageReaders::stream);
    Mono<String> resultMono = defaultClientResponse.bodyToMono(String.class);
    StepVerifier.create(resultMono).expectError(WebClientException.class).verify();
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) HttpMessageReader(org.springframework.http.codec.HttpMessageReader) DecoderHttpMessageReader(org.springframework.http.codec.DecoderHttpMessageReader) StringDecoder(org.springframework.core.codec.StringDecoder) Test(org.junit.Test)

Example 52 with HttpHeaders

use of org.springframework.http.HttpHeaders in project spring-framework by spring-projects.

the class CrossOriginAnnotationIntegrationTests method setup.

@Before
public void setup() throws Exception {
    super.setup();
    this.headers = new HttpHeaders();
    this.headers.setOrigin("http://site1.com");
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) Before(org.junit.Before)

Example 53 with HttpHeaders

use of org.springframework.http.HttpHeaders in project spring-framework by spring-projects.

the class CrossOriginAnnotationIntegrationTests method actualRequestWithDefaultAnnotationAndNoOrigin.

@Test
public void actualRequestWithDefaultAnnotationAndNoOrigin() throws Exception {
    HttpHeaders headers = new HttpHeaders();
    ResponseEntity<String> entity = performGet("/default", headers, String.class);
    assertEquals(HttpStatus.OK, entity.getStatusCode());
    assertNull(entity.getHeaders().getAccessControlAllowOrigin());
    assertEquals("default", entity.getBody());
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) Test(org.junit.Test)

Example 54 with HttpHeaders

use of org.springframework.http.HttpHeaders in project spring-framework by spring-projects.

the class GlobalCorsConfigIntegrationTests method setup.

@Before
public void setup() throws Exception {
    super.setup();
    this.headers = new HttpHeaders();
    this.headers.setOrigin("http://localhost:9000");
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) Before(org.junit.Before)

Example 55 with HttpHeaders

use of org.springframework.http.HttpHeaders in project spring-framework by spring-projects.

the class WebSocketIntegrationTests method customHeader.

@Test
public void customHeader() throws Exception {
    HttpHeaders headers = new HttpHeaders();
    headers.add("my-header", "my-value");
    MonoProcessor<Object> output = MonoProcessor.create();
    client.execute(getUrl("/custom-header"), headers, session -> session.receive().map(WebSocketMessage::getPayloadAsText).subscribeWith(output).then()).block(Duration.ofMillis(5000));
    assertEquals("my-header:my-value", output.block(Duration.ofMillis(5000)));
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) Publisher(org.reactivestreams.Publisher) MonoProcessor(reactor.core.publisher.MonoProcessor) Matchers(org.hamcrest.Matchers) HashMap(java.util.HashMap) Test(org.junit.Test) Mono(reactor.core.publisher.Mono) AtomicReference(java.util.concurrent.atomic.AtomicReference) ReplayProcessor(reactor.core.publisher.ReplayProcessor) Configuration(org.springframework.context.annotation.Configuration) Assert.assertThat(org.junit.Assert.assertThat) Flux(reactor.core.publisher.Flux) Duration(java.time.Duration) Map(java.util.Map) Bean(org.springframework.context.annotation.Bean) HandlerMapping(org.springframework.web.reactive.HandlerMapping) Assert.assertEquals(org.junit.Assert.assertEquals) SimpleUrlHandlerMapping(org.springframework.web.reactive.handler.SimpleUrlHandlerMapping) HttpHeaders(org.springframework.http.HttpHeaders) Test(org.junit.Test)

Aggregations

HttpHeaders (org.springframework.http.HttpHeaders)1676 Test (org.junit.Test)426 ResponseEntity (org.springframework.http.ResponseEntity)383 HttpEntity (org.springframework.http.HttpEntity)345 Test (org.junit.jupiter.api.Test)273 HashMap (java.util.HashMap)184 LinkedMultiValueMap (org.springframework.util.LinkedMultiValueMap)154 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)127 MediaType (org.springframework.http.MediaType)121 URI (java.net.URI)111 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)102 Map (java.util.Map)97 IOException (java.io.IOException)83 RestTemplate (org.springframework.web.client.RestTemplate)78 ArrayList (java.util.ArrayList)75 MessageHeaders (org.springframework.messaging.MessageHeaders)74 MultiValueMap (org.springframework.util.MultiValueMap)74 HttpStatus (org.springframework.http.HttpStatus)71 List (java.util.List)65 Timed (com.codahale.metrics.annotation.Timed)54