Search in sources :

Example 1 with ByteBufferDecoder

use of org.springframework.core.codec.ByteBufferDecoder in project spring-framework by spring-projects.

the class WebFluxConfigurationSupport method addDefaultHttpMessageReaders.

/**
	 * Adds default converters that sub-classes can call from
	 * {@link #configureMessageReaders(List)} for {@code byte[]},
	 * {@code ByteBuffer}, {@code String}, {@code Resource}, JAXB2, and Jackson
	 * (if present on the classpath).
	 */
protected final void addDefaultHttpMessageReaders(List<HttpMessageReader<?>> readers) {
    readers.add(new DecoderHttpMessageReader<>(new ByteArrayDecoder()));
    readers.add(new DecoderHttpMessageReader<>(new ByteBufferDecoder()));
    readers.add(new DecoderHttpMessageReader<>(new DataBufferDecoder()));
    readers.add(new DecoderHttpMessageReader<>(new StringDecoder()));
    readers.add(new DecoderHttpMessageReader<>(new ResourceDecoder()));
    if (jaxb2Present) {
        readers.add(new DecoderHttpMessageReader<>(new Jaxb2XmlDecoder()));
    }
    if (jackson2Present) {
        readers.add(new Jackson2ServerHttpMessageReader(new DecoderHttpMessageReader<>(new Jackson2JsonDecoder())));
    }
}
Also used : DecoderHttpMessageReader(org.springframework.http.codec.DecoderHttpMessageReader) Jackson2JsonDecoder(org.springframework.http.codec.json.Jackson2JsonDecoder) DataBufferDecoder(org.springframework.core.codec.DataBufferDecoder) Jaxb2XmlDecoder(org.springframework.http.codec.xml.Jaxb2XmlDecoder) StringDecoder(org.springframework.core.codec.StringDecoder) ResourceDecoder(org.springframework.core.codec.ResourceDecoder) ByteBufferDecoder(org.springframework.core.codec.ByteBufferDecoder) ByteArrayDecoder(org.springframework.core.codec.ByteArrayDecoder) Jackson2ServerHttpMessageReader(org.springframework.http.codec.Jackson2ServerHttpMessageReader)

Example 2 with ByteBufferDecoder

use of org.springframework.core.codec.ByteBufferDecoder in project spring-framework by spring-projects.

the class DefaultExchangeStrategiesBuilder method defaultReaders.

private void defaultReaders() {
    messageReader(new DecoderHttpMessageReader<>(new ByteArrayDecoder()));
    messageReader(new DecoderHttpMessageReader<>(new ByteBufferDecoder()));
    messageReader(new ServerSentEventHttpMessageReader(sseDecoders()));
    messageReader(new DecoderHttpMessageReader<>(new StringDecoder(false)));
    if (jaxb2Present) {
        messageReader(new DecoderHttpMessageReader<>(new Jaxb2XmlDecoder()));
    }
    if (jackson2Present) {
        messageReader(new DecoderHttpMessageReader<>(new Jackson2JsonDecoder()));
    }
}
Also used : ServerSentEventHttpMessageReader(org.springframework.http.codec.ServerSentEventHttpMessageReader) Jackson2JsonDecoder(org.springframework.http.codec.json.Jackson2JsonDecoder) Jaxb2XmlDecoder(org.springframework.http.codec.xml.Jaxb2XmlDecoder) StringDecoder(org.springframework.core.codec.StringDecoder) ByteBufferDecoder(org.springframework.core.codec.ByteBufferDecoder) ByteArrayDecoder(org.springframework.core.codec.ByteArrayDecoder)

Example 3 with ByteBufferDecoder

use of org.springframework.core.codec.ByteBufferDecoder in project spring-security by spring-projects.

the class OAuth2BodyExtractorsTests method createContext.

@BeforeEach
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 Jackson2JsonDecoder()));
    messageReaders.add(new FormHttpMessageReader());
    this.hints = new HashMap<>();
    this.context = new BodyExtractor.Context() {

        @Override
        public List<HttpMessageReader<?>> messageReaders() {
            return messageReaders;
        }

        @Override
        public Optional<ServerHttpResponse> serverResponse() {
            return Optional.empty();
        }

        @Override
        public Map<String, Object> hints() {
            return OAuth2BodyExtractorsTests.this.hints;
        }
    };
}
Also used : Optional(java.util.Optional) Jackson2JsonDecoder(org.springframework.http.codec.json.Jackson2JsonDecoder) ArrayList(java.util.ArrayList) ByteBufferDecoder(org.springframework.core.codec.ByteBufferDecoder) FormHttpMessageReader(org.springframework.http.codec.FormHttpMessageReader) HttpMessageReader(org.springframework.http.codec.HttpMessageReader) DecoderHttpMessageReader(org.springframework.http.codec.DecoderHttpMessageReader) FormHttpMessageReader(org.springframework.http.codec.FormHttpMessageReader) BodyExtractor(org.springframework.web.reactive.function.BodyExtractor) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 4 with ByteBufferDecoder

use of org.springframework.core.codec.ByteBufferDecoder in project spring-framework by spring-projects.

the class ControllerMethodResolverTests method setup.

@BeforeEach
public void setup() {
    ArgumentResolverConfigurer resolvers = new ArgumentResolverConfigurer();
    resolvers.addCustomResolver(new CustomArgumentResolver());
    resolvers.addCustomResolver(new CustomSyncArgumentResolver());
    ServerCodecConfigurer codecs = ServerCodecConfigurer.create();
    codecs.customCodecs().register(new ByteArrayDecoder());
    codecs.customCodecs().register(new ByteBufferDecoder());
    AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
    applicationContext.registerBean(TestControllerAdvice.class);
    applicationContext.refresh();
    this.methodResolver = new ControllerMethodResolver(resolvers, ReactiveAdapterRegistry.getSharedInstance(), applicationContext, codecs.getReaders());
    Method method = ResolvableMethod.on(TestController.class).mockCall(TestController::handle).method();
    this.handlerMethod = new HandlerMethod(new TestController(), method);
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) ServerCodecConfigurer(org.springframework.http.codec.ServerCodecConfigurer) InvocableHandlerMethod(org.springframework.web.reactive.result.method.InvocableHandlerMethod) HandlerMethod(org.springframework.web.method.HandlerMethod) Method(java.lang.reflect.Method) ResolvableMethod(org.springframework.web.testfixture.method.ResolvableMethod) SyncInvocableHandlerMethod(org.springframework.web.reactive.result.method.SyncInvocableHandlerMethod) ByteBufferDecoder(org.springframework.core.codec.ByteBufferDecoder) InvocableHandlerMethod(org.springframework.web.reactive.result.method.InvocableHandlerMethod) HandlerMethod(org.springframework.web.method.HandlerMethod) SyncInvocableHandlerMethod(org.springframework.web.reactive.result.method.SyncInvocableHandlerMethod) ByteArrayDecoder(org.springframework.core.codec.ByteArrayDecoder) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 5 with ByteBufferDecoder

use of org.springframework.core.codec.ByteBufferDecoder in project spring-framework by spring-projects.

the class RSocketMessageHandlerTests method metadataExtractorWithExplicitlySetDecoders.

@Test
public void metadataExtractorWithExplicitlySetDecoders() {
    DefaultMetadataExtractor extractor = new DefaultMetadataExtractor(StringDecoder.allMimeTypes());
    RSocketMessageHandler handler = new RSocketMessageHandler();
    handler.setDecoders(Arrays.asList(new ByteArrayDecoder(), new ByteBufferDecoder()));
    handler.setEncoders(Collections.singletonList(new ByteBufferEncoder()));
    handler.setMetadataExtractor(extractor);
    handler.afterPropertiesSet();
    assertThat(((DefaultMetadataExtractor) handler.getMetadataExtractor()).getDecoders()).hasSize(1);
}
Also used : ByteBufferEncoder(org.springframework.core.codec.ByteBufferEncoder) DefaultMetadataExtractor(org.springframework.messaging.rsocket.DefaultMetadataExtractor) ByteBufferDecoder(org.springframework.core.codec.ByteBufferDecoder) ByteArrayDecoder(org.springframework.core.codec.ByteArrayDecoder) Test(org.junit.jupiter.api.Test)

Aggregations

ByteBufferDecoder (org.springframework.core.codec.ByteBufferDecoder)9 ByteArrayDecoder (org.springframework.core.codec.ByteArrayDecoder)7 Jackson2JsonDecoder (org.springframework.http.codec.json.Jackson2JsonDecoder)6 DecoderHttpMessageReader (org.springframework.http.codec.DecoderHttpMessageReader)5 FormHttpMessageReader (org.springframework.http.codec.FormHttpMessageReader)5 Jaxb2XmlDecoder (org.springframework.http.codec.xml.Jaxb2XmlDecoder)5 DataBufferDecoder (org.springframework.core.codec.DataBufferDecoder)4 ResourceDecoder (org.springframework.core.codec.ResourceDecoder)4 StringDecoder (org.springframework.core.codec.StringDecoder)4 HttpMessageReader (org.springframework.http.codec.HttpMessageReader)4 BeforeEach (org.junit.jupiter.api.BeforeEach)3 Test (org.junit.jupiter.api.Test)3 NettyByteBufDecoder (org.springframework.core.codec.NettyByteBufDecoder)3 ResourceHttpMessageReader (org.springframework.http.codec.ResourceHttpMessageReader)3 ProtobufDecoder (org.springframework.http.codec.protobuf.ProtobufDecoder)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 Optional (java.util.Optional)2