Search in sources :

Example 11 with ResourceHttpMessageWriter

use of org.springframework.http.codec.ResourceHttpMessageWriter in project spring-security by spring-projects.

the class ServletOAuth2AuthorizedClientExchangeFilterFunctionTests method getBody.

private static String getBody(ClientRequest request) {
    final List<HttpMessageWriter<?>> messageWriters = new ArrayList<>();
    messageWriters.add(new EncoderHttpMessageWriter<>(new ByteBufferEncoder()));
    messageWriters.add(new EncoderHttpMessageWriter<>(CharSequenceEncoder.textPlainOnly()));
    messageWriters.add(new ResourceHttpMessageWriter());
    Jackson2JsonEncoder jsonEncoder = new Jackson2JsonEncoder();
    messageWriters.add(new EncoderHttpMessageWriter<>(jsonEncoder));
    messageWriters.add(new ServerSentEventHttpMessageWriter(jsonEncoder));
    messageWriters.add(new FormHttpMessageWriter());
    messageWriters.add(new EncoderHttpMessageWriter<>(CharSequenceEncoder.allMimeTypes()));
    messageWriters.add(new MultipartHttpMessageWriter(messageWriters));
    BodyInserter.Context context = new BodyInserter.Context() {

        @Override
        public List<HttpMessageWriter<?>> messageWriters() {
            return messageWriters;
        }

        @Override
        public Optional<ServerHttpRequest> serverRequest() {
            return Optional.empty();
        }

        @Override
        public Map<String, Object> hints() {
            return new HashMap<>();
        }
    };
    MockClientHttpRequest body = new MockClientHttpRequest(HttpMethod.GET, "/");
    request.body().insert(body, context).block();
    return body.getBodyAsString().block();
}
Also used : ByteBufferEncoder(org.springframework.core.codec.ByteBufferEncoder) Context(reactor.util.context.Context) OAuth2AuthorizationContext(org.springframework.security.oauth2.client.OAuth2AuthorizationContext) FormHttpMessageWriter(org.springframework.http.codec.FormHttpMessageWriter) HttpMessageWriter(org.springframework.http.codec.HttpMessageWriter) ServerSentEventHttpMessageWriter(org.springframework.http.codec.ServerSentEventHttpMessageWriter) MultipartHttpMessageWriter(org.springframework.http.codec.multipart.MultipartHttpMessageWriter) ResourceHttpMessageWriter(org.springframework.http.codec.ResourceHttpMessageWriter) EncoderHttpMessageWriter(org.springframework.http.codec.EncoderHttpMessageWriter) HashMap(java.util.HashMap) ServerHttpRequest(org.springframework.http.server.reactive.ServerHttpRequest) ArrayList(java.util.ArrayList) ServerSentEventHttpMessageWriter(org.springframework.http.codec.ServerSentEventHttpMessageWriter) MockClientHttpRequest(org.springframework.mock.http.client.reactive.MockClientHttpRequest) BodyInserter(org.springframework.web.reactive.function.BodyInserter) Jackson2JsonEncoder(org.springframework.http.codec.json.Jackson2JsonEncoder) ResourceHttpMessageWriter(org.springframework.http.codec.ResourceHttpMessageWriter) FormHttpMessageWriter(org.springframework.http.codec.FormHttpMessageWriter) MultipartHttpMessageWriter(org.springframework.http.codec.multipart.MultipartHttpMessageWriter)

Aggregations

ResourceHttpMessageWriter (org.springframework.http.codec.ResourceHttpMessageWriter)11 ByteBufferEncoder (org.springframework.core.codec.ByteBufferEncoder)9 EncoderHttpMessageWriter (org.springframework.http.codec.EncoderHttpMessageWriter)8 HttpMessageWriter (org.springframework.http.codec.HttpMessageWriter)8 Jackson2JsonEncoder (org.springframework.http.codec.json.Jackson2JsonEncoder)8 ArrayList (java.util.ArrayList)7 FormHttpMessageWriter (org.springframework.http.codec.FormHttpMessageWriter)6 Jaxb2XmlEncoder (org.springframework.http.codec.xml.Jaxb2XmlEncoder)6 ServerSentEventHttpMessageWriter (org.springframework.http.codec.ServerSentEventHttpMessageWriter)5 MultipartHttpMessageWriter (org.springframework.http.codec.multipart.MultipartHttpMessageWriter)5 HashMap (java.util.HashMap)4 ByteArrayEncoder (org.springframework.core.codec.ByteArrayEncoder)3 RequestedContentTypeResolver (org.springframework.web.reactive.accept.RequestedContentTypeResolver)3 RequestedContentTypeResolverBuilder (org.springframework.web.reactive.accept.RequestedContentTypeResolverBuilder)3 List (java.util.List)2 Map (java.util.Map)2 Optional (java.util.Optional)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 Test (org.junit.jupiter.api.Test)2 CharSequenceEncoder (org.springframework.core.codec.CharSequenceEncoder)2