Search in sources :

Example 6 with FormHttpMessageWriter

use of org.springframework.http.codec.FormHttpMessageWriter 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

FormHttpMessageWriter (org.springframework.http.codec.FormHttpMessageWriter)6 ResourceHttpMessageWriter (org.springframework.http.codec.ResourceHttpMessageWriter)5 ByteBufferEncoder (org.springframework.core.codec.ByteBufferEncoder)4 EncoderHttpMessageWriter (org.springframework.http.codec.EncoderHttpMessageWriter)4 HttpMessageWriter (org.springframework.http.codec.HttpMessageWriter)4 Jackson2JsonEncoder (org.springframework.http.codec.json.Jackson2JsonEncoder)4 MultipartHttpMessageWriter (org.springframework.http.codec.multipart.MultipartHttpMessageWriter)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 ServerSentEventHttpMessageWriter (org.springframework.http.codec.ServerSentEventHttpMessageWriter)3 Jaxb2XmlEncoder (org.springframework.http.codec.xml.Jaxb2XmlEncoder)2 ServerHttpRequest (org.springframework.http.server.reactive.ServerHttpRequest)2 MockClientHttpRequest (org.springframework.mock.http.client.reactive.MockClientHttpRequest)2 OAuth2AuthorizationContext (org.springframework.security.oauth2.client.OAuth2AuthorizationContext)2 BodyInserter (org.springframework.web.reactive.function.BodyInserter)2 Context (reactor.util.context.Context)2 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1