org.springframework.core.ReactiveAdapterRegistry Java Examples
The following examples show how to use
org.springframework.core.ReactiveAdapterRegistry.
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: ModelAttributeMethodArgumentResolverTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void supports() throws Exception { ModelAttributeMethodArgumentResolver resolver = new ModelAttributeMethodArgumentResolver(ReactiveAdapterRegistry.getSharedInstance(), false); MethodParameter param = this.testMethod.annotPresent(ModelAttribute.class).arg(Foo.class); assertTrue(resolver.supportsParameter(param)); param = this.testMethod.annotPresent(ModelAttribute.class).arg(Mono.class, Foo.class); assertTrue(resolver.supportsParameter(param)); param = this.testMethod.annotNotPresent(ModelAttribute.class).arg(Foo.class); assertFalse(resolver.supportsParameter(param)); param = this.testMethod.annotNotPresent(ModelAttribute.class).arg(Mono.class, Foo.class); assertFalse(resolver.supportsParameter(param)); }
Example #2
Source File: WebFluxConfigurationSupport.java From spring-analysis-note with MIT License | 6 votes |
@Bean public RequestMappingHandlerAdapter requestMappingHandlerAdapter( ReactiveAdapterRegistry webFluxAdapterRegistry, ServerCodecConfigurer serverCodecConfigurer, FormattingConversionService webFluxConversionService, Validator webfluxValidator) { RequestMappingHandlerAdapter adapter = createRequestMappingHandlerAdapter(); adapter.setMessageReaders(serverCodecConfigurer.getReaders()); adapter.setWebBindingInitializer(getConfigurableWebBindingInitializer(webFluxConversionService, webfluxValidator)); adapter.setReactiveAdapterRegistry(webFluxAdapterRegistry); ArgumentResolverConfigurer configurer = new ArgumentResolverConfigurer(); configureArgumentResolvers(configurer); adapter.setArgumentResolverConfigurer(configurer); return adapter; }
Example #3
Source File: CookieValueMethodArgumentResolverTests.java From spring-analysis-note with MIT License | 6 votes |
@Before @SuppressWarnings("resource") public void setup() throws Exception { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); context.refresh(); ReactiveAdapterRegistry adapterRegistry = ReactiveAdapterRegistry.getSharedInstance(); this.resolver = new CookieValueMethodArgumentResolver(context.getBeanFactory(), adapterRegistry); this.bindingContext = new BindingContext(); Method method = ReflectionUtils.findMethod(getClass(), "params", (Class<?>[]) null); this.cookieParameter = new SynthesizingMethodParameter(method, 0); this.cookieStringParameter = new SynthesizingMethodParameter(method, 1); this.stringParameter = new SynthesizingMethodParameter(method, 2); this.cookieMonoParameter = new SynthesizingMethodParameter(method, 3); }
Example #4
Source File: CookieValueMethodArgumentResolverTests.java From java-technology-stack with MIT License | 6 votes |
@Before @SuppressWarnings("resource") public void setup() throws Exception { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); context.refresh(); ReactiveAdapterRegistry adapterRegistry = ReactiveAdapterRegistry.getSharedInstance(); this.resolver = new CookieValueMethodArgumentResolver(context.getBeanFactory(), adapterRegistry); this.bindingContext = new BindingContext(); Method method = ReflectionUtils.findMethod(getClass(), "params", (Class<?>[]) null); this.cookieParameter = new SynthesizingMethodParameter(method, 0); this.cookieStringParameter = new SynthesizingMethodParameter(method, 1); this.stringParameter = new SynthesizingMethodParameter(method, 2); this.cookieMonoParameter = new SynthesizingMethodParameter(method, 3); }
Example #5
Source File: ControllerMethodResolver.java From java-technology-stack with MIT License | 6 votes |
ControllerMethodResolver(ArgumentResolverConfigurer customResolvers, ReactiveAdapterRegistry reactiveRegistry, ConfigurableApplicationContext context, List<HttpMessageReader<?>> readers) { Assert.notNull(customResolvers, "ArgumentResolverConfigurer is required"); Assert.notNull(readers, "'messageReaders' is required"); Assert.notNull(reactiveRegistry, "ReactiveAdapterRegistry is required"); Assert.notNull(context, "ApplicationContext is required"); this.initBinderResolvers = initBinderResolvers(customResolvers, reactiveRegistry, context); this.modelAttributeResolvers = modelMethodResolvers(customResolvers, reactiveRegistry, context); this.requestMappingResolvers = requestMappingResolvers(customResolvers, reactiveRegistry, context, readers); this.exceptionHandlerResolvers = exceptionHandlerResolvers(customResolvers, reactiveRegistry, context); this.reactiveAdapterRegistry = reactiveRegistry; initControllerAdviceCaches(context); }
Example #6
Source File: RequestMappingHandlerAdapter.java From spring-analysis-note with MIT License | 6 votes |
@Override public void afterPropertiesSet() throws Exception { Assert.notNull(this.applicationContext, "ApplicationContext is required"); if (CollectionUtils.isEmpty(this.messageReaders)) { ServerCodecConfigurer codecConfigurer = ServerCodecConfigurer.create(); this.messageReaders = codecConfigurer.getReaders(); } if (this.argumentResolverConfigurer == null) { this.argumentResolverConfigurer = new ArgumentResolverConfigurer(); } if (this.reactiveAdapterRegistry == null) { this.reactiveAdapterRegistry = ReactiveAdapterRegistry.getSharedInstance(); } this.methodResolver = new ControllerMethodResolver(this.argumentResolverConfigurer, this.reactiveAdapterRegistry, this.applicationContext, this.messageReaders); this.modelInitializer = new ModelInitializer(this.methodResolver, this.reactiveAdapterRegistry); }
Example #7
Source File: ModelAttributeMethodArgumentResolverTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void supportsWithDefaultResolution() throws Exception { ModelAttributeMethodArgumentResolver resolver = new ModelAttributeMethodArgumentResolver(ReactiveAdapterRegistry.getSharedInstance(), true); MethodParameter param = this.testMethod.annotNotPresent(ModelAttribute.class).arg(Foo.class); assertTrue(resolver.supportsParameter(param)); param = this.testMethod.annotNotPresent(ModelAttribute.class).arg(Mono.class, Foo.class); assertTrue(resolver.supportsParameter(param)); param = this.testMethod.annotNotPresent(ModelAttribute.class).arg(String.class); assertFalse(resolver.supportsParameter(param)); param = this.testMethod.annotNotPresent(ModelAttribute.class).arg(Mono.class, String.class); assertFalse(resolver.supportsParameter(param)); }
Example #8
Source File: RequestMappingHandlerAdapter.java From java-technology-stack with MIT License | 6 votes |
@Override public void afterPropertiesSet() throws Exception { Assert.notNull(this.applicationContext, "ApplicationContext is required"); if (CollectionUtils.isEmpty(this.messageReaders)) { ServerCodecConfigurer codecConfigurer = ServerCodecConfigurer.create(); this.messageReaders = codecConfigurer.getReaders(); } if (this.argumentResolverConfigurer == null) { this.argumentResolverConfigurer = new ArgumentResolverConfigurer(); } if (this.reactiveAdapterRegistry == null) { this.reactiveAdapterRegistry = ReactiveAdapterRegistry.getSharedInstance(); } this.methodResolver = new ControllerMethodResolver(this.argumentResolverConfigurer, this.reactiveAdapterRegistry, this.applicationContext, this.messageReaders); this.modelInitializer = new ModelInitializer(this.methodResolver, this.reactiveAdapterRegistry); }
Example #9
Source File: ReactiveTypeHandler.java From spring-analysis-note with MIT License | 5 votes |
ReactiveTypeHandler(ReactiveAdapterRegistry registry, TaskExecutor executor, ContentNegotiationManager manager) { Assert.notNull(registry, "ReactiveAdapterRegistry is required"); Assert.notNull(executor, "TaskExecutor is required"); Assert.notNull(manager, "ContentNegotiationManager is required"); this.adapterRegistry = registry; this.taskExecutor = executor; this.contentNegotiationManager = manager; this.taskExecutorWarning = (executor instanceof SimpleAsyncTaskExecutor || executor instanceof SyncTaskExecutor); }
Example #10
Source File: HandlerResultHandlerSupport.java From java-technology-stack with MIT License | 5 votes |
protected HandlerResultHandlerSupport(RequestedContentTypeResolver contentTypeResolver, ReactiveAdapterRegistry adapterRegistry) { Assert.notNull(contentTypeResolver, "RequestedContentTypeResolver is required"); Assert.notNull(adapterRegistry, "ReactiveAdapterRegistry is required"); this.contentTypeResolver = contentTypeResolver; this.adapterRegistry = adapterRegistry; }
Example #11
Source File: RxJava3Registrar.java From alibaba-rsocket-broker with Apache License 2.0 | 5 votes |
public void registerAdapters(ReactiveAdapterRegistry registry) { registry.registerReactiveType( ReactiveTypeDescriptor.multiValue(Flowable.class, Flowable::empty), source -> (Flowable<?>) source, Flowable::fromPublisher ); registry.registerReactiveType( ReactiveTypeDescriptor.multiValue(Observable.class, Observable::empty), source -> ((Observable<?>) source).toFlowable(BackpressureStrategy.BUFFER), source -> Flowable.fromPublisher(source).toObservable() ); registry.registerReactiveType( ReactiveTypeDescriptor.singleRequiredValue(Single.class), source -> ((Single<?>) source).toFlowable(), source -> Flowable.fromPublisher(source).toObservable().singleElement().toSingle() ); registry.registerReactiveType( ReactiveTypeDescriptor.singleOptionalValue(Maybe.class, Maybe::empty), source -> ((Maybe<?>) source).toFlowable(), source -> Flowable.fromPublisher(source).toObservable().singleElement() ); registry.registerReactiveType( ReactiveTypeDescriptor.noValue(Completable.class, Completable::complete), source -> ((Completable) source).toFlowable(), source -> Flowable.fromPublisher(source).toObservable().ignoreElements() ); }
Example #12
Source File: ExpressionValueMethodArgumentResolverTests.java From java-technology-stack with MIT License | 5 votes |
@Before @SuppressWarnings("resource") public void setup() throws Exception { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); context.refresh(); ReactiveAdapterRegistry adapterRegistry = ReactiveAdapterRegistry.getSharedInstance(); this.resolver = new ExpressionValueMethodArgumentResolver(context.getBeanFactory(), adapterRegistry); Method method = ReflectionUtils.findMethod(getClass(), "params", (Class<?>[]) null); this.paramSystemProperty = new MethodParameter(method, 0); this.paramNotSupported = new MethodParameter(method, 1); this.paramAlsoNotSupported = new MethodParameter(method, 2); }
Example #13
Source File: RequestPartMethodArgumentResolverTests.java From java-technology-stack with MIT License | 5 votes |
@Before public void setup() throws Exception { List<HttpMessageReader<?>> readers = ServerCodecConfigurer.create().getReaders(); ReactiveAdapterRegistry registry = ReactiveAdapterRegistry.getSharedInstance(); this.resolver = new RequestPartMethodArgumentResolver(readers, registry); List<HttpMessageWriter<?>> writers = ClientCodecConfigurer.create().getWriters(); this.writer = new MultipartHttpMessageWriter(writers); }
Example #14
Source File: WebFluxConfigurationSupport.java From spring-analysis-note with MIT License | 5 votes |
@Bean public ResponseBodyResultHandler responseBodyResultHandler( ReactiveAdapterRegistry webFluxAdapterRegistry, ServerCodecConfigurer serverCodecConfigurer, RequestedContentTypeResolver webFluxContentTypeResolver) { return new ResponseBodyResultHandler(serverCodecConfigurer.getWriters(), webFluxContentTypeResolver, webFluxAdapterRegistry); }
Example #15
Source File: AbstractNamedValueArgumentResolver.java From spring-analysis-note with MIT License | 5 votes |
/** * Create a new {@link AbstractNamedValueArgumentResolver} instance. * @param factory a bean factory to use for resolving {@code ${...}} placeholder * and {@code #{...}} SpEL expressions in default values, or {@code null} if default * values are not expected to contain expressions * @param registry for checking reactive type wrappers */ public AbstractNamedValueArgumentResolver(@Nullable ConfigurableBeanFactory factory, ReactiveAdapterRegistry registry) { super(registry); this.configurableBeanFactory = factory; this.expressionContext = (factory != null ? new BeanExpressionContext(factory, null) : null); }
Example #16
Source File: ReactiveTypeHandlerTests.java From spring-analysis-note with MIT License | 5 votes |
@Before public void setup() throws Exception { ContentNegotiationManagerFactoryBean factoryBean = new ContentNegotiationManagerFactoryBean(); factoryBean.afterPropertiesSet(); ContentNegotiationManager manager = factoryBean.getObject(); ReactiveAdapterRegistry adapterRegistry = ReactiveAdapterRegistry.getSharedInstance(); this.handler = new ReactiveTypeHandler(adapterRegistry, new SyncTaskExecutor(), manager); resetRequest(); }
Example #17
Source File: PathVariableMapMethodArgumentResolverTests.java From spring-analysis-note with MIT License | 5 votes |
@Before public void setup() throws Exception { this.resolver = new PathVariableMapMethodArgumentResolver(ReactiveAdapterRegistry.getSharedInstance()); Method method = ReflectionUtils.findMethod(getClass(), "handle", (Class<?>[]) null); this.paramMap = new MethodParameter(method, 0); this.paramNamedMap = new MethodParameter(method, 1); this.paramMapNoAnnot = new MethodParameter(method, 2); this.paramMonoMap = new MethodParameter(method, 3); }
Example #18
Source File: InitBinderBindingContextTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void createBinderTypeConversion() throws Exception { MockServerHttpRequest request = MockServerHttpRequest.get("/path?requestParam=22").build(); MockServerWebExchange exchange = MockServerWebExchange.from(request); ReactiveAdapterRegistry adapterRegistry = ReactiveAdapterRegistry.getSharedInstance(); this.argumentResolvers.add(new RequestParamMethodArgumentResolver(null, adapterRegistry, false)); BindingContext context = createBindingContext("initBinderTypeConversion", WebDataBinder.class, int.class); WebDataBinder dataBinder = context.createDataBinder(exchange, null, "foo"); assertNotNull(dataBinder.getDisallowedFields()); assertEquals("requestParam-22", dataBinder.getDisallowedFields()[0]); }
Example #19
Source File: RequestPartMethodArgumentResolverTests.java From spring-analysis-note with MIT License | 5 votes |
@Before public void setup() throws Exception { List<HttpMessageReader<?>> readers = ServerCodecConfigurer.create().getReaders(); ReactiveAdapterRegistry registry = ReactiveAdapterRegistry.getSharedInstance(); this.resolver = new RequestPartMethodArgumentResolver(readers, registry); List<HttpMessageWriter<?>> writers = ClientCodecConfigurer.create().getWriters(); this.writer = new MultipartHttpMessageWriter(writers); }
Example #20
Source File: AbstractMessageReaderArgumentResolver.java From spring-analysis-note with MIT License | 5 votes |
/** * Constructor that also accepts a {@link ReactiveAdapterRegistry}. * @param messageReaders readers to convert from the request body * @param adapterRegistry for adapting to other reactive types from Flux and Mono */ protected AbstractMessageReaderArgumentResolver( List<HttpMessageReader<?>> messageReaders, ReactiveAdapterRegistry adapterRegistry) { super(adapterRegistry); Assert.notEmpty(messageReaders, "At least one HttpMessageReader is required"); Assert.notNull(adapterRegistry, "ReactiveAdapterRegistry is required"); this.messageReaders = messageReaders; this.supportedMediaTypes = messageReaders.stream() .flatMap(converter -> converter.getReadableMediaTypes().stream()) .collect(Collectors.toList()); }
Example #21
Source File: PathVariableMapMethodArgumentResolverTests.java From java-technology-stack with MIT License | 5 votes |
@Before public void setup() throws Exception { this.resolver = new PathVariableMapMethodArgumentResolver(ReactiveAdapterRegistry.getSharedInstance()); Method method = ReflectionUtils.findMethod(getClass(), "handle", (Class<?>[]) null); this.paramMap = new MethodParameter(method, 0); this.paramNamedMap = new MethodParameter(method, 1); this.paramMapNoAnnot = new MethodParameter(method, 2); this.paramMonoMap = new MethodParameter(method, 3); }
Example #22
Source File: ResponseEntityResultHandler.java From spring-analysis-note with MIT License | 5 votes |
/** * Constructor with an {@link ReactiveAdapterRegistry} instance. * @param writers writers for serializing to the response body * @param resolver to determine the requested content type * @param registry for adaptation to reactive types */ public ResponseEntityResultHandler(List<HttpMessageWriter<?>> writers, RequestedContentTypeResolver resolver, ReactiveAdapterRegistry registry) { super(writers, resolver, registry); setOrder(0); }
Example #23
Source File: TransactionAspectSupport.java From spring-analysis-note with MIT License | 5 votes |
protected TransactionAspectSupport() { if (reactiveStreamsPresent) { this.reactiveAdapterRegistry = ReactiveAdapterRegistry.getSharedInstance(); } else { this.reactiveAdapterRegistry = null; } }
Example #24
Source File: AbstractMessageWriterResultHandler.java From spring-analysis-note with MIT License | 5 votes |
/** * Constructor with an additional {@link ReactiveAdapterRegistry}. * @param messageWriters for serializing Objects to the response body stream * @param contentTypeResolver for resolving the requested content type * @param adapterRegistry for adapting other reactive types (e.g. rx.Observable, * rx.Single, etc.) to Flux or Mono */ protected AbstractMessageWriterResultHandler(List<HttpMessageWriter<?>> messageWriters, RequestedContentTypeResolver contentTypeResolver, ReactiveAdapterRegistry adapterRegistry) { super(contentTypeResolver, adapterRegistry); Assert.notEmpty(messageWriters, "At least one message writer is required"); this.messageWriters = messageWriters; }
Example #25
Source File: ControllerMethodResolver.java From java-technology-stack with MIT License | 5 votes |
private List<SyncHandlerMethodArgumentResolver> initBinderResolvers( ArgumentResolverConfigurer customResolvers, ReactiveAdapterRegistry reactiveRegistry, ConfigurableApplicationContext context) { return initResolvers(customResolvers, reactiveRegistry, context, false, Collections.emptyList()).stream() .filter(resolver -> resolver instanceof SyncHandlerMethodArgumentResolver) .map(resolver -> (SyncHandlerMethodArgumentResolver) resolver) .collect(Collectors.toList()); }
Example #26
Source File: ResponseBodyResultHandler.java From spring-analysis-note with MIT License | 5 votes |
/** * Constructor with an {@link ReactiveAdapterRegistry} instance. * @param writers writers for serializing to the response body * @param resolver to determine the requested content type * @param registry for adaptation to reactive types */ public ResponseBodyResultHandler(List<HttpMessageWriter<?>> writers, RequestedContentTypeResolver resolver, ReactiveAdapterRegistry registry) { super(writers, resolver, registry); setOrder(100); }
Example #27
Source File: RequestParamMethodArgumentResolverTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void doesNotSupportParameterWithDefaultResolutionTurnedOff() { ReactiveAdapterRegistry adapterRegistry = ReactiveAdapterRegistry.getSharedInstance(); this.resolver = new RequestParamMethodArgumentResolver(null, adapterRegistry, false); MethodParameter param = this.testMethod.annotNotPresent(RequestParam.class).arg(String.class); assertFalse(this.resolver.supportsParameter(param)); }
Example #28
Source File: AbstractMessageReaderArgumentResolver.java From java-technology-stack with MIT License | 5 votes |
/** * Constructor that also accepts a {@link ReactiveAdapterRegistry}. * @param messageReaders readers to convert from the request body * @param adapterRegistry for adapting to other reactive types from Flux and Mono */ protected AbstractMessageReaderArgumentResolver( List<HttpMessageReader<?>> messageReaders, ReactiveAdapterRegistry adapterRegistry) { super(adapterRegistry); Assert.notEmpty(messageReaders, "At least one HttpMessageReader is required"); Assert.notNull(adapterRegistry, "ReactiveAdapterRegistry is required"); this.messageReaders = messageReaders; this.supportedMediaTypes = messageReaders.stream() .flatMap(converter -> converter.getReadableMediaTypes().stream()) .collect(Collectors.toList()); }
Example #29
Source File: PathVariableMethodArgumentResolverTests.java From java-technology-stack with MIT License | 5 votes |
@Before public void setup() throws Exception { this.resolver = new PathVariableMethodArgumentResolver(null, ReactiveAdapterRegistry.getSharedInstance()); Method method = ReflectionUtils.findMethod(getClass(), "handle", (Class<?>[]) null); paramNamedString = new SynthesizingMethodParameter(method, 0); paramString = new SynthesizingMethodParameter(method, 1); paramNotRequired = new SynthesizingMethodParameter(method, 2); paramOptional = new SynthesizingMethodParameter(method, 3); paramMono = new SynthesizingMethodParameter(method, 4); }
Example #30
Source File: ModelInitializerTests.java From spring-analysis-note with MIT License | 5 votes |
@Before public void setup() { ReactiveAdapterRegistry adapterRegistry = ReactiveAdapterRegistry.getSharedInstance(); ArgumentResolverConfigurer resolverConfigurer = new ArgumentResolverConfigurer(); resolverConfigurer.addCustomResolver(new ModelMethodArgumentResolver(adapterRegistry)); ControllerMethodResolver methodResolver = new ControllerMethodResolver( resolverConfigurer, adapterRegistry, new StaticApplicationContext(), Collections.emptyList()); this.modelInitializer = new ModelInitializer(methodResolver, adapterRegistry); }