org.springframework.http.codec.DecoderHttpMessageReader Java Examples
The following examples show how to use
org.springframework.http.codec.DecoderHttpMessageReader.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DefaultClientResponseTests.java From spring-analysis-note with MIT License | 8 votes |
@Test public void toEntityList() { DefaultDataBufferFactory factory = new DefaultDataBufferFactory(); DefaultDataBuffer dataBuffer = factory.wrap(ByteBuffer.wrap("foo".getBytes(StandardCharsets.UTF_8))); Flux<DataBuffer> body = Flux.just(dataBuffer); mockTextPlainResponse(body); List<HttpMessageReader<?>> messageReaders = Collections .singletonList(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes())); given(mockExchangeStrategies.messageReaders()).willReturn(messageReaders); ResponseEntity<List<String>> result = defaultClientResponse.toEntityList(String.class).block(); assertEquals(Collections.singletonList("foo"), result.getBody()); assertEquals(HttpStatus.OK, result.getStatusCode()); assertEquals(HttpStatus.OK.value(), result.getStatusCodeValue()); assertEquals(MediaType.TEXT_PLAIN, result.getHeaders().getContentType()); }
Example #2
Source File: DefaultClientResponseTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void toEntityListTypeReference() { DefaultDataBufferFactory factory = new DefaultDataBufferFactory(); DefaultDataBuffer dataBuffer = factory.wrap(ByteBuffer.wrap("foo".getBytes(StandardCharsets.UTF_8))); Flux<DataBuffer> body = Flux.just(dataBuffer); mockTextPlainResponse(body); List<HttpMessageReader<?>> messageReaders = Collections .singletonList(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes())); given(mockExchangeStrategies.messageReaders()).willReturn(messageReaders); ResponseEntity<List<String>> result = defaultClientResponse.toEntityList( new ParameterizedTypeReference<String>() { }).block(); assertEquals(Collections.singletonList("foo"), result.getBody()); assertEquals(HttpStatus.OK, result.getStatusCode()); assertEquals(HttpStatus.OK.value(), result.getStatusCodeValue()); assertEquals(MediaType.TEXT_PLAIN, result.getHeaders().getContentType()); }
Example #3
Source File: DefaultClientResponseTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void toEntityTypeReference() { DefaultDataBufferFactory factory = new DefaultDataBufferFactory(); DefaultDataBuffer dataBuffer = factory.wrap(ByteBuffer.wrap("foo".getBytes(StandardCharsets.UTF_8))); Flux<DataBuffer> body = Flux.just(dataBuffer); mockTextPlainResponse(body); List<HttpMessageReader<?>> messageReaders = Collections .singletonList(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes())); when(mockExchangeStrategies.messageReaders()).thenReturn(messageReaders); ResponseEntity<String> result = defaultClientResponse.toEntity( new ParameterizedTypeReference<String>() { }).block(); assertEquals("foo", result.getBody()); assertEquals(HttpStatus.OK, result.getStatusCode()); assertEquals(HttpStatus.OK.value(), result.getStatusCodeValue()); assertEquals(MediaType.TEXT_PLAIN, result.getHeaders().getContentType()); }
Example #4
Source File: DefaultClientResponseTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void toEntityList() { DefaultDataBufferFactory factory = new DefaultDataBufferFactory(); DefaultDataBuffer dataBuffer = factory.wrap(ByteBuffer.wrap("foo".getBytes(StandardCharsets.UTF_8))); Flux<DataBuffer> body = Flux.just(dataBuffer); mockTextPlainResponse(body); List<HttpMessageReader<?>> messageReaders = Collections .singletonList(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes())); when(mockExchangeStrategies.messageReaders()).thenReturn(messageReaders); ResponseEntity<List<String>> result = defaultClientResponse.toEntityList(String.class).block(); assertEquals(Collections.singletonList("foo"), result.getBody()); assertEquals(HttpStatus.OK, result.getStatusCode()); assertEquals(HttpStatus.OK.value(), result.getStatusCodeValue()); assertEquals(MediaType.TEXT_PLAIN, result.getHeaders().getContentType()); }
Example #5
Source File: BaseDefaultCodecs.java From spring-analysis-note with MIT License | 6 votes |
/** * Return Object readers (JSON, XML, SSE). */ final List<HttpMessageReader<?>> getObjectReaders() { if (!this.registerDefaults) { return Collections.emptyList(); } List<HttpMessageReader<?>> readers = new ArrayList<>(); if (jackson2Present) { readers.add(new DecoderHttpMessageReader<>(getJackson2JsonDecoder())); } if (jackson2SmilePresent) { readers.add(new DecoderHttpMessageReader<>(new Jackson2SmileDecoder())); } if (jaxb2Present) { Decoder<?> decoder = this.jaxb2Decoder != null ? this.jaxb2Decoder : new Jaxb2XmlDecoder(); readers.add(new DecoderHttpMessageReader<>(decoder)); } extendObjectReaders(readers); return readers; }
Example #6
Source File: BaseDefaultCodecs.java From spring-analysis-note with MIT License | 6 votes |
/** * Return readers that support specific types. */ final List<HttpMessageReader<?>> getTypedReaders() { if (!this.registerDefaults) { return Collections.emptyList(); } List<HttpMessageReader<?>> readers = new ArrayList<>(); readers.add(new DecoderHttpMessageReader<>(new ByteArrayDecoder())); readers.add(new DecoderHttpMessageReader<>(new ByteBufferDecoder())); readers.add(new DecoderHttpMessageReader<>(new DataBufferDecoder())); readers.add(new ResourceHttpMessageReader()); readers.add(new DecoderHttpMessageReader<>(StringDecoder.textPlainOnly())); if (protobufPresent) { Decoder<?> decoder = this.protobufDecoder != null ? this.protobufDecoder : new ProtobufDecoder(); readers.add(new DecoderHttpMessageReader<>(decoder)); } FormHttpMessageReader formReader = new FormHttpMessageReader(); formReader.setEnableLoggingRequestDetails(this.enableLoggingRequestDetails); readers.add(formReader); extendTypedReaders(readers); return readers; }
Example #7
Source File: DefaultClientResponseTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void toEntityListTypeReference() { DefaultDataBufferFactory factory = new DefaultDataBufferFactory(); DefaultDataBuffer dataBuffer = factory.wrap(ByteBuffer.wrap("foo".getBytes(StandardCharsets.UTF_8))); Flux<DataBuffer> body = Flux.just(dataBuffer); mockTextPlainResponse(body); List<HttpMessageReader<?>> messageReaders = Collections .singletonList(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes())); when(mockExchangeStrategies.messageReaders()).thenReturn(messageReaders); ResponseEntity<List<String>> result = defaultClientResponse.toEntityList( new ParameterizedTypeReference<String>() { }).block(); assertEquals(Collections.singletonList("foo"), result.getBody()); assertEquals(HttpStatus.OK, result.getStatusCode()); assertEquals(HttpStatus.OK.value(), result.getStatusCodeValue()); assertEquals(MediaType.TEXT_PLAIN, result.getHeaders().getContentType()); }
Example #8
Source File: DefaultClientResponseTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void toEntity() { DefaultDataBufferFactory factory = new DefaultDataBufferFactory(); DefaultDataBuffer dataBuffer = factory.wrap(ByteBuffer.wrap("foo".getBytes(StandardCharsets.UTF_8))); Flux<DataBuffer> body = Flux.just(dataBuffer); mockTextPlainResponse(body); List<HttpMessageReader<?>> messageReaders = Collections .singletonList(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes())); when(mockExchangeStrategies.messageReaders()).thenReturn(messageReaders); ResponseEntity<String> result = defaultClientResponse.toEntity(String.class).block(); assertEquals("foo", result.getBody()); assertEquals(HttpStatus.OK, result.getStatusCode()); assertEquals(HttpStatus.OK.value(), result.getStatusCodeValue()); assertEquals(MediaType.TEXT_PLAIN, result.getHeaders().getContentType()); }
Example #9
Source File: DefaultClientResponseTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void bodyToFluxTypeReference() { DefaultDataBufferFactory factory = new DefaultDataBufferFactory(); DefaultDataBuffer dataBuffer = factory.wrap(ByteBuffer.wrap("foo".getBytes(StandardCharsets.UTF_8))); Flux<DataBuffer> body = Flux.just(dataBuffer); mockTextPlainResponse(body); List<HttpMessageReader<?>> messageReaders = Collections .singletonList(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes())); when(mockExchangeStrategies.messageReaders()).thenReturn(messageReaders); Flux<String> resultFlux = defaultClientResponse.bodyToFlux(new ParameterizedTypeReference<String>() { }); Mono<List<String>> result = resultFlux.collectList(); assertEquals(Collections.singletonList("foo"), result.block()); }
Example #10
Source File: BaseDefaultCodecs.java From java-technology-stack with MIT License | 6 votes |
/** * Return readers that support specific types. */ final List<HttpMessageReader<?>> getTypedReaders() { if (!this.registerDefaults) { return Collections.emptyList(); } List<HttpMessageReader<?>> readers = new ArrayList<>(); readers.add(new DecoderHttpMessageReader<>(new ByteArrayDecoder())); readers.add(new DecoderHttpMessageReader<>(new ByteBufferDecoder())); readers.add(new DecoderHttpMessageReader<>(new DataBufferDecoder())); readers.add(new DecoderHttpMessageReader<>(new ResourceDecoder())); readers.add(new DecoderHttpMessageReader<>(StringDecoder.textPlainOnly())); if (protobufPresent) { Decoder<?> decoder = this.protobufDecoder != null ? this.protobufDecoder : new ProtobufDecoder(); readers.add(new DecoderHttpMessageReader<>(decoder)); } FormHttpMessageReader formReader = new FormHttpMessageReader(); formReader.setEnableLoggingRequestDetails(this.enableLoggingRequestDetails); readers.add(formReader); extendTypedReaders(readers); return readers; }
Example #11
Source File: BaseDefaultCodecs.java From java-technology-stack with MIT License | 6 votes |
/** * Return Object readers (JSON, XML, SSE). */ final List<HttpMessageReader<?>> getObjectReaders() { if (!this.registerDefaults) { return Collections.emptyList(); } List<HttpMessageReader<?>> readers = new ArrayList<>(); if (jackson2Present) { readers.add(new DecoderHttpMessageReader<>(getJackson2JsonDecoder())); } if (jackson2SmilePresent) { readers.add(new DecoderHttpMessageReader<>(new Jackson2SmileDecoder())); } if (jaxb2Present) { Decoder<?> decoder = this.jaxb2Decoder != null ? this.jaxb2Decoder : new Jaxb2XmlDecoder(); readers.add(new DecoderHttpMessageReader<>(decoder)); } extendObjectReaders(readers); return readers; }
Example #12
Source File: DefaultClientResponseTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void toEntityTypeReference() { DefaultDataBufferFactory factory = new DefaultDataBufferFactory(); DefaultDataBuffer dataBuffer = factory.wrap(ByteBuffer.wrap("foo".getBytes(StandardCharsets.UTF_8))); Flux<DataBuffer> body = Flux.just(dataBuffer); mockTextPlainResponse(body); List<HttpMessageReader<?>> messageReaders = Collections .singletonList(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes())); given(mockExchangeStrategies.messageReaders()).willReturn(messageReaders); ResponseEntity<String> result = defaultClientResponse.toEntity( new ParameterizedTypeReference<String>() { }).block(); assertEquals("foo", result.getBody()); assertEquals(HttpStatus.OK, result.getStatusCode()); assertEquals(HttpStatus.OK.value(), result.getStatusCodeValue()); assertEquals(MediaType.TEXT_PLAIN, result.getHeaders().getContentType()); }
Example #13
Source File: DefaultClientResponseTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void bodyToFlux() { DefaultDataBufferFactory factory = new DefaultDataBufferFactory(); DefaultDataBuffer dataBuffer = factory.wrap(ByteBuffer.wrap("foo".getBytes(StandardCharsets.UTF_8))); Flux<DataBuffer> body = Flux.just(dataBuffer); mockTextPlainResponse(body); List<HttpMessageReader<?>> messageReaders = Collections .singletonList(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes())); when(mockExchangeStrategies.messageReaders()).thenReturn(messageReaders); Flux<String> resultFlux = defaultClientResponse.bodyToFlux(String.class); Mono<List<String>> result = resultFlux.collectList(); assertEquals(Collections.singletonList("foo"), result.block()); }
Example #14
Source File: DefaultClientResponseTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void toEntity() { DefaultDataBufferFactory factory = new DefaultDataBufferFactory(); DefaultDataBuffer dataBuffer = factory.wrap(ByteBuffer.wrap("foo".getBytes(StandardCharsets.UTF_8))); Flux<DataBuffer> body = Flux.just(dataBuffer); mockTextPlainResponse(body); List<HttpMessageReader<?>> messageReaders = Collections .singletonList(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes())); given(mockExchangeStrategies.messageReaders()).willReturn(messageReaders); ResponseEntity<String> result = defaultClientResponse.toEntity(String.class).block(); assertEquals("foo", result.getBody()); assertEquals(HttpStatus.OK, result.getStatusCode()); assertEquals(HttpStatus.OK.value(), result.getStatusCodeValue()); assertEquals(MediaType.TEXT_PLAIN, result.getHeaders().getContentType()); }
Example #15
Source File: DefaultClientResponseTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void bodyToFluxTypeReference() { DefaultDataBufferFactory factory = new DefaultDataBufferFactory(); DefaultDataBuffer dataBuffer = factory.wrap(ByteBuffer.wrap("foo".getBytes(StandardCharsets.UTF_8))); Flux<DataBuffer> body = Flux.just(dataBuffer); mockTextPlainResponse(body); List<HttpMessageReader<?>> messageReaders = Collections .singletonList(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes())); given(mockExchangeStrategies.messageReaders()).willReturn(messageReaders); Flux<String> resultFlux = defaultClientResponse.bodyToFlux(new ParameterizedTypeReference<String>() { }); Mono<List<String>> result = resultFlux.collectList(); assertEquals(Collections.singletonList("foo"), result.block()); }
Example #16
Source File: DefaultClientResponseTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void bodyToFlux() { DefaultDataBufferFactory factory = new DefaultDataBufferFactory(); DefaultDataBuffer dataBuffer = factory.wrap(ByteBuffer.wrap("foo".getBytes(StandardCharsets.UTF_8))); Flux<DataBuffer> body = Flux.just(dataBuffer); mockTextPlainResponse(body); List<HttpMessageReader<?>> messageReaders = Collections .singletonList(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes())); given(mockExchangeStrategies.messageReaders()).willReturn(messageReaders); Flux<String> resultFlux = defaultClientResponse.bodyToFlux(String.class); Mono<List<String>> result = resultFlux.collectList(); assertEquals(Collections.singletonList("foo"), result.block()); }
Example #17
Source File: DefaultClientResponseTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void bodyToMonoTypeReference() { DefaultDataBufferFactory factory = new DefaultDataBufferFactory(); DefaultDataBuffer dataBuffer = factory.wrap(ByteBuffer.wrap("foo".getBytes(StandardCharsets.UTF_8))); Flux<DataBuffer> body = Flux.just(dataBuffer); mockTextPlainResponse(body); List<HttpMessageReader<?>> messageReaders = Collections .singletonList(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes())); given(mockExchangeStrategies.messageReaders()).willReturn(messageReaders); Mono<String> resultMono = defaultClientResponse.bodyToMono(new ParameterizedTypeReference<String>() { }); assertEquals("foo", resultMono.block()); }
Example #18
Source File: DefaultClientResponseTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void bodyToMonoTypeReference() { DefaultDataBufferFactory factory = new DefaultDataBufferFactory(); DefaultDataBuffer dataBuffer = factory.wrap(ByteBuffer.wrap("foo".getBytes(StandardCharsets.UTF_8))); Flux<DataBuffer> body = Flux.just(dataBuffer); mockTextPlainResponse(body); List<HttpMessageReader<?>> messageReaders = Collections .singletonList(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes())); when(mockExchangeStrategies.messageReaders()).thenReturn(messageReaders); Mono<String> resultMono = defaultClientResponse.bodyToMono(new ParameterizedTypeReference<String>() { }); assertEquals("foo", resultMono.block()); }
Example #19
Source File: MessageReaderArgumentResolverTests.java From java-technology-stack with MIT License | 5 votes |
@SuppressWarnings("Convert2MethodRef") private AbstractMessageReaderArgumentResolver resolver(Decoder<?>... decoders) { List<HttpMessageReader<?>> readers = new ArrayList<>(); Arrays.asList(decoders).forEach(decoder -> readers.add(new DecoderHttpMessageReader<>(decoder))); return new AbstractMessageReaderArgumentResolver(readers) { @Override public boolean supportsParameter(MethodParameter parameter) { return false; } @Override public Mono<Object> resolveArgument(MethodParameter p, BindingContext bc, ServerWebExchange e) { return null; } }; }
Example #20
Source File: DefaultClientResponseTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void toEntityWithUnknownStatusCode() throws Exception { DefaultDataBufferFactory factory = new DefaultDataBufferFactory(); DefaultDataBuffer dataBuffer = factory.wrap(ByteBuffer.wrap("foo".getBytes(StandardCharsets.UTF_8))); Flux<DataBuffer> body = Flux.just(dataBuffer); HttpHeaders httpHeaders = new HttpHeaders(); httpHeaders.setContentType(MediaType.TEXT_PLAIN); when(mockResponse.getHeaders()).thenReturn(httpHeaders); when(mockResponse.getStatusCode()).thenThrow(new IllegalArgumentException("999")); when(mockResponse.getRawStatusCode()).thenReturn(999); when(mockResponse.getBody()).thenReturn(body); List<HttpMessageReader<?>> messageReaders = Collections .singletonList(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes())); when(mockExchangeStrategies.messageReaders()).thenReturn(messageReaders); ResponseEntity<String> result = defaultClientResponse.toEntity(String.class).block(); assertEquals("foo", result.getBody()); try { result.getStatusCode(); fail("Expected IllegalArgumentException"); } catch (IllegalArgumentException ex) { // do nothing } assertEquals(999, result.getStatusCodeValue()); assertEquals(MediaType.TEXT_PLAIN, result.getHeaders().getContentType()); }
Example #21
Source File: DefaultClientResponseTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void toEntityListWithUnknownStatusCode() throws Exception { DefaultDataBufferFactory factory = new DefaultDataBufferFactory(); DefaultDataBuffer dataBuffer = factory.wrap(ByteBuffer.wrap("foo".getBytes(StandardCharsets.UTF_8))); Flux<DataBuffer> body = Flux.just(dataBuffer); HttpHeaders httpHeaders = new HttpHeaders(); httpHeaders.setContentType(MediaType.TEXT_PLAIN); when(mockResponse.getHeaders()).thenReturn(httpHeaders); when(mockResponse.getStatusCode()).thenThrow(new IllegalArgumentException("999")); when(mockResponse.getRawStatusCode()).thenReturn(999); when(mockResponse.getBody()).thenReturn(body); List<HttpMessageReader<?>> messageReaders = Collections .singletonList(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes())); when(mockExchangeStrategies.messageReaders()).thenReturn(messageReaders); ResponseEntity<List<String>> result = defaultClientResponse.toEntityList(String.class).block(); assertEquals(Collections.singletonList("foo"), result.getBody()); try { result.getStatusCode(); fail("Expected IllegalArgumentException"); } catch (IllegalArgumentException ex) { // do nothing } assertEquals(999, result.getStatusCodeValue()); assertEquals(MediaType.TEXT_PLAIN, result.getHeaders().getContentType()); }
Example #22
Source File: RequestPredicateAttributesTests.java From java-technology-stack with MIT License | 5 votes |
@Before public void createRequest() { MockServerHttpRequest request = MockServerHttpRequest.get("http://example.com/path").build(); MockServerWebExchange webExchange = MockServerWebExchange.from(request); webExchange.getAttributes().put("exchange", "bar"); this.request = new DefaultServerRequest(webExchange, Collections.singletonList( new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes()))); }
Example #23
Source File: DefaultClientResponseTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void bodyToMono() { DefaultDataBufferFactory factory = new DefaultDataBufferFactory(); DefaultDataBuffer dataBuffer = factory.wrap(ByteBuffer.wrap("foo".getBytes(StandardCharsets.UTF_8))); Flux<DataBuffer> body = Flux.just(dataBuffer); mockTextPlainResponse(body); List<HttpMessageReader<?>> messageReaders = Collections .singletonList(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes())); given(mockExchangeStrategies.messageReaders()).willReturn(messageReaders); Mono<String> resultMono = defaultClientResponse.bodyToMono(String.class); assertEquals("foo", resultMono.block()); }
Example #24
Source File: BaseDefaultCodecs.java From java-technology-stack with MIT License | 5 votes |
/** * Return readers that need to be at the end, after all others. */ final List<HttpMessageReader<?>> getCatchAllReaders() { if (!this.registerDefaults) { return Collections.emptyList(); } List<HttpMessageReader<?>> result = new ArrayList<>(); result.add(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes())); return result; }
Example #25
Source File: CodecConfigurerTests.java From java-technology-stack with MIT License | 5 votes |
private void assertDecoderInstance(Decoder<?> decoder) { assertSame(decoder, this.configurer.getReaders().stream() .filter(writer -> writer instanceof DecoderHttpMessageReader) .map(writer -> ((DecoderHttpMessageReader<?>) writer).getDecoder()) .filter(e -> decoder.getClass().equals(e.getClass())) .findFirst() .filter(e -> e == decoder).orElse(null)); }
Example #26
Source File: BodyExtractorsTests.java From java-technology-stack with MIT License | 5 votes |
@Before public void createContext() { final List<HttpMessageReader<?>> messageReaders = new ArrayList<>(); messageReaders.add(new DecoderHttpMessageReader<>(new ByteBufferDecoder())); messageReaders.add(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes())); messageReaders.add(new DecoderHttpMessageReader<>(new Jaxb2XmlDecoder())); messageReaders.add(new DecoderHttpMessageReader<>(new Jackson2JsonDecoder())); messageReaders.add(new FormHttpMessageReader()); SynchronossPartHttpMessageReader partReader = new SynchronossPartHttpMessageReader(); messageReaders.add(partReader); messageReaders.add(new MultipartHttpMessageReader(partReader)); messageReaders.add(new FormHttpMessageReader()); this.context = new BodyExtractor.Context() { @Override public List<HttpMessageReader<?>> messageReaders() { return messageReaders; } @Override public Optional<ServerHttpResponse> serverResponse() { return serverResponse; } @Override public Map<String, Object> hints() { return hints; } }; this.hints = new HashMap<String, Object>(); }
Example #27
Source File: BodyExtractorsTests.java From spring-analysis-note with MIT License | 5 votes |
@Before public void createContext() { final List<HttpMessageReader<?>> messageReaders = new ArrayList<>(); messageReaders.add(new DecoderHttpMessageReader<>(new ByteBufferDecoder())); messageReaders.add(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes())); messageReaders.add(new DecoderHttpMessageReader<>(new Jaxb2XmlDecoder())); messageReaders.add(new DecoderHttpMessageReader<>(new Jackson2JsonDecoder())); messageReaders.add(new FormHttpMessageReader()); SynchronossPartHttpMessageReader partReader = new SynchronossPartHttpMessageReader(); messageReaders.add(partReader); messageReaders.add(new MultipartHttpMessageReader(partReader)); messageReaders.add(new FormHttpMessageReader()); this.context = new BodyExtractor.Context() { @Override public List<HttpMessageReader<?>> messageReaders() { return messageReaders; } @Override public Optional<ServerHttpResponse> serverResponse() { return serverResponse; } @Override public Map<String, Object> hints() { return hints; } }; this.hints = new HashMap<String, Object>(); }
Example #28
Source File: DefaultClientResponseTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void toEntityWithUnknownStatusCode() throws Exception { DefaultDataBufferFactory factory = new DefaultDataBufferFactory(); DefaultDataBuffer dataBuffer = factory.wrap(ByteBuffer.wrap("foo".getBytes(StandardCharsets.UTF_8))); Flux<DataBuffer> body = Flux.just(dataBuffer); HttpHeaders httpHeaders = new HttpHeaders(); httpHeaders.setContentType(MediaType.TEXT_PLAIN); given(mockResponse.getHeaders()).willReturn(httpHeaders); given(mockResponse.getStatusCode()).willThrow(new IllegalArgumentException("999")); given(mockResponse.getRawStatusCode()).willReturn(999); given(mockResponse.getBody()).willReturn(body); List<HttpMessageReader<?>> messageReaders = Collections .singletonList(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes())); given(mockExchangeStrategies.messageReaders()).willReturn(messageReaders); ResponseEntity<String> result = defaultClientResponse.toEntity(String.class).block(); assertEquals("foo", result.getBody()); try { result.getStatusCode(); fail("Expected IllegalArgumentException"); } catch (IllegalArgumentException ex) { // do nothing } assertEquals(999, result.getStatusCodeValue()); assertEquals(MediaType.TEXT_PLAIN, result.getHeaders().getContentType()); }
Example #29
Source File: DefaultClientResponseTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void toEntityListWithUnknownStatusCode() throws Exception { DefaultDataBufferFactory factory = new DefaultDataBufferFactory(); DefaultDataBuffer dataBuffer = factory.wrap(ByteBuffer.wrap("foo".getBytes(StandardCharsets.UTF_8))); Flux<DataBuffer> body = Flux.just(dataBuffer); HttpHeaders httpHeaders = new HttpHeaders(); httpHeaders.setContentType(MediaType.TEXT_PLAIN); given(mockResponse.getHeaders()).willReturn(httpHeaders); given(mockResponse.getStatusCode()).willThrow(new IllegalArgumentException("999")); given(mockResponse.getRawStatusCode()).willReturn(999); given(mockResponse.getBody()).willReturn(body); List<HttpMessageReader<?>> messageReaders = Collections .singletonList(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes())); given(mockExchangeStrategies.messageReaders()).willReturn(messageReaders); ResponseEntity<List<String>> result = defaultClientResponse.toEntityList(String.class).block(); assertEquals(Collections.singletonList("foo"), result.getBody()); try { result.getStatusCode(); fail("Expected IllegalArgumentException"); } catch (IllegalArgumentException ex) { // do nothing } assertEquals(999, result.getStatusCodeValue()); assertEquals(MediaType.TEXT_PLAIN, result.getHeaders().getContentType()); }
Example #30
Source File: RequestPredicateAttributesTests.java From spring-analysis-note with MIT License | 5 votes |
@Before public void createRequest() { MockServerHttpRequest request = MockServerHttpRequest.get("https://example.com/path").build(); MockServerWebExchange webExchange = MockServerWebExchange.from(request); webExchange.getAttributes().put("exchange", "bar"); this.request = new DefaultServerRequest(webExchange, Collections.singletonList( new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes()))); }