org.springframework.web.reactive.accept.RequestedContentTypeResolver Java Examples
The following examples show how to use
org.springframework.web.reactive.accept.RequestedContentTypeResolver.
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: WebFluxConfigurationSupport.java From spring-analysis-note with MIT License | 6 votes |
@Bean public RequestMappingHandlerMapping requestMappingHandlerMapping( RequestedContentTypeResolver webFluxContentTypeResolver) { RequestMappingHandlerMapping mapping = createRequestMappingHandlerMapping(); mapping.setOrder(0); mapping.setContentTypeResolver(webFluxContentTypeResolver); mapping.setCorsConfigurations(getCorsConfigurations()); PathMatchConfigurer configurer = getPathMatchConfigurer(); Boolean useTrailingSlashMatch = configurer.isUseTrailingSlashMatch(); if (useTrailingSlashMatch != null) { mapping.setUseTrailingSlashMatch(useTrailingSlashMatch); } Boolean useCaseSensitiveMatch = configurer.isUseCaseSensitiveMatch(); if (useCaseSensitiveMatch != null) { mapping.setUseCaseSensitiveMatch(useCaseSensitiveMatch); } Map<String, Predicate<Class<?>>> pathPrefixes = configurer.getPathPrefixes(); if (pathPrefixes != null) { mapping.setPathPrefixes(pathPrefixes); } return mapping; }
Example #2
Source File: ProducesRequestConditionTests.java From spring-analysis-note with MIT License | 6 votes |
@Test // gh-22853 public void matchAndCompare() { RequestedContentTypeResolverBuilder builder = new RequestedContentTypeResolverBuilder(); builder.headerResolver(); builder.fixedResolver(MediaType.TEXT_HTML); RequestedContentTypeResolver resolver = builder.build(); ProducesRequestCondition none = new ProducesRequestCondition(new String[0], null, resolver); ProducesRequestCondition html = new ProducesRequestCondition(new String[] {"text/html"}, null, resolver); MockServerWebExchange exchange = MockServerWebExchange.from(get("/").header("Accept", "*/*")); ProducesRequestCondition noneMatch = none.getMatchingCondition(exchange); ProducesRequestCondition htmlMatch = html.getMatchingCondition(exchange); assertEquals(1, noneMatch.compareTo(htmlMatch, exchange)); }
Example #3
Source File: ResponseEntityResultHandlerTests.java From spring-analysis-note with MIT License | 6 votes |
private ResponseEntityResultHandler createHandler(HttpMessageWriter<?>... writers) { List<HttpMessageWriter<?>> writerList; if (ObjectUtils.isEmpty(writers)) { writerList = new ArrayList<>(); writerList.add(new EncoderHttpMessageWriter<>(new ByteBufferEncoder())); writerList.add(new EncoderHttpMessageWriter<>(CharSequenceEncoder.textPlainOnly())); writerList.add(new ResourceHttpMessageWriter()); writerList.add(new EncoderHttpMessageWriter<>(new Jaxb2XmlEncoder())); writerList.add(new EncoderHttpMessageWriter<>(new Jackson2JsonEncoder())); writerList.add(new EncoderHttpMessageWriter<>(CharSequenceEncoder.allMimeTypes())); } else { writerList = Arrays.asList(writers); } RequestedContentTypeResolver resolver = new RequestedContentTypeResolverBuilder().build(); return new ResponseEntityResultHandler(writerList, resolver); }
Example #4
Source File: WebFluxConfigurationSupportTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void requestMappingHandlerMapping() throws Exception { ApplicationContext context = loadConfig(WebFluxConfig.class); final Field field = ReflectionUtils.findField(PathPatternParser.class, "matchOptionalTrailingSeparator"); ReflectionUtils.makeAccessible(field); String name = "requestMappingHandlerMapping"; RequestMappingHandlerMapping mapping = context.getBean(name, RequestMappingHandlerMapping.class); assertNotNull(mapping); assertEquals(0, mapping.getOrder()); PathPatternParser patternParser = mapping.getPathPatternParser(); assertNotNull(patternParser); boolean matchOptionalTrailingSlash = (boolean) ReflectionUtils.getField(field, patternParser); assertTrue(matchOptionalTrailingSlash); name = "webFluxContentTypeResolver"; RequestedContentTypeResolver resolver = context.getBean(name, RequestedContentTypeResolver.class); assertSame(resolver, mapping.getContentTypeResolver()); ServerWebExchange exchange = MockServerWebExchange.from(get("/path").accept(MediaType.APPLICATION_JSON)); assertEquals(Collections.singletonList(MediaType.APPLICATION_JSON), resolver.resolveMediaTypes(exchange)); }
Example #5
Source File: MessageWriterResultHandlerTests.java From spring-analysis-note with MIT License | 6 votes |
private AbstractMessageWriterResultHandler initResultHandler(HttpMessageWriter<?>... writers) { List<HttpMessageWriter<?>> writerList; if (ObjectUtils.isEmpty(writers)) { writerList = new ArrayList<>(); writerList.add(new EncoderHttpMessageWriter<>(new ByteBufferEncoder())); writerList.add(new EncoderHttpMessageWriter<>(CharSequenceEncoder.allMimeTypes())); writerList.add(new ResourceHttpMessageWriter()); writerList.add(new EncoderHttpMessageWriter<>(new Jaxb2XmlEncoder())); writerList.add(new EncoderHttpMessageWriter<>(new Jackson2JsonEncoder())); } else { writerList = Arrays.asList(writers); } RequestedContentTypeResolver resolver = new RequestedContentTypeResolverBuilder().build(); return new AbstractMessageWriterResultHandler(writerList, resolver) {}; }
Example #6
Source File: RequestMappingInfo.java From spring-analysis-note with MIT License | 6 votes |
@Override public RequestMappingInfo build() { RequestedContentTypeResolver contentTypeResolver = this.options.getContentTypeResolver(); PathPatternParser parser = (this.options.getPatternParser() != null ? this.options.getPatternParser() : new PathPatternParser()); PatternsRequestCondition patternsCondition = new PatternsRequestCondition(parse(this.paths, parser)); return new RequestMappingInfo(this.mappingName, patternsCondition, new RequestMethodsRequestCondition(this.methods), new ParamsRequestCondition(this.params), new HeadersRequestCondition(this.headers), new ConsumesRequestCondition(this.consumes, this.headers), new ProducesRequestCondition(this.produces, this.headers, contentTypeResolver), this.customCondition); }
Example #7
Source File: RequestMappingInfo.java From java-technology-stack with MIT License | 6 votes |
@Override public RequestMappingInfo build() { RequestedContentTypeResolver contentTypeResolver = this.options.getContentTypeResolver(); PathPatternParser parser = (this.options.getPatternParser() != null ? this.options.getPatternParser() : new PathPatternParser()); PatternsRequestCondition patternsCondition = new PatternsRequestCondition(parse(this.paths, parser)); return new RequestMappingInfo(this.mappingName, patternsCondition, new RequestMethodsRequestCondition(this.methods), new ParamsRequestCondition(this.params), new HeadersRequestCondition(this.headers), new ConsumesRequestCondition(this.consumes, this.headers), new ProducesRequestCondition(this.produces, this.headers, contentTypeResolver), this.customCondition); }
Example #8
Source File: WebFluxConfigurationSupportTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void requestMappingHandlerMapping() throws Exception { ApplicationContext context = loadConfig(WebFluxConfig.class); final Field field = ReflectionUtils.findField(PathPatternParser.class, "matchOptionalTrailingSeparator"); ReflectionUtils.makeAccessible(field); String name = "requestMappingHandlerMapping"; RequestMappingHandlerMapping mapping = context.getBean(name, RequestMappingHandlerMapping.class); assertNotNull(mapping); assertEquals(0, mapping.getOrder()); PathPatternParser patternParser = mapping.getPathPatternParser(); assertNotNull(patternParser); boolean matchOptionalTrailingSlash = (boolean) ReflectionUtils.getField(field, patternParser); assertTrue(matchOptionalTrailingSlash); name = "webFluxContentTypeResolver"; RequestedContentTypeResolver resolver = context.getBean(name, RequestedContentTypeResolver.class); assertSame(resolver, mapping.getContentTypeResolver()); ServerWebExchange exchange = MockServerWebExchange.from(get("/path").accept(MediaType.APPLICATION_JSON)); assertEquals(Collections.singletonList(MediaType.APPLICATION_JSON), resolver.resolveMediaTypes(exchange)); }
Example #9
Source File: ResponseEntityResultHandlerTests.java From java-technology-stack with MIT License | 6 votes |
private ResponseEntityResultHandler createHandler(HttpMessageWriter<?>... writers) { List<HttpMessageWriter<?>> writerList; if (ObjectUtils.isEmpty(writers)) { writerList = new ArrayList<>(); writerList.add(new EncoderHttpMessageWriter<>(new ByteBufferEncoder())); writerList.add(new EncoderHttpMessageWriter<>(CharSequenceEncoder.textPlainOnly())); writerList.add(new ResourceHttpMessageWriter()); writerList.add(new EncoderHttpMessageWriter<>(new Jaxb2XmlEncoder())); writerList.add(new EncoderHttpMessageWriter<>(new Jackson2JsonEncoder())); writerList.add(new EncoderHttpMessageWriter<>(CharSequenceEncoder.allMimeTypes())); } else { writerList = Arrays.asList(writers); } RequestedContentTypeResolver resolver = new RequestedContentTypeResolverBuilder().build(); return new ResponseEntityResultHandler(writerList, resolver); }
Example #10
Source File: MessageWriterResultHandlerTests.java From java-technology-stack with MIT License | 6 votes |
private AbstractMessageWriterResultHandler initResultHandler(HttpMessageWriter<?>... writers) { List<HttpMessageWriter<?>> writerList; if (ObjectUtils.isEmpty(writers)) { writerList = new ArrayList<>(); writerList.add(new EncoderHttpMessageWriter<>(new ByteBufferEncoder())); writerList.add(new EncoderHttpMessageWriter<>(CharSequenceEncoder.allMimeTypes())); writerList.add(new ResourceHttpMessageWriter()); writerList.add(new EncoderHttpMessageWriter<>(new Jaxb2XmlEncoder())); writerList.add(new EncoderHttpMessageWriter<>(new Jackson2JsonEncoder())); } else { writerList = Arrays.asList(writers); } RequestedContentTypeResolver resolver = new RequestedContentTypeResolverBuilder().build(); return new AbstractMessageWriterResultHandler(writerList, resolver) {}; }
Example #11
Source File: WebFluxConfigurationSupportTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void responseEntityResultHandler() throws Exception { ApplicationContext context = loadConfig(WebFluxConfig.class); String name = "responseEntityResultHandler"; ResponseEntityResultHandler handler = context.getBean(name, ResponseEntityResultHandler.class); assertNotNull(handler); assertEquals(0, handler.getOrder()); List<HttpMessageWriter<?>> writers = handler.getMessageWriters(); assertEquals(11, writers.size()); assertHasMessageWriter(writers, forClass(byte[].class), APPLICATION_OCTET_STREAM); assertHasMessageWriter(writers, forClass(ByteBuffer.class), APPLICATION_OCTET_STREAM); assertHasMessageWriter(writers, forClass(String.class), TEXT_PLAIN); assertHasMessageWriter(writers, forClass(Resource.class), IMAGE_PNG); assertHasMessageWriter(writers, forClass(Message.class), new MediaType("application", "x-protobuf")); assertHasMessageWriter(writers, forClass(TestBean.class), APPLICATION_XML); assertHasMessageWriter(writers, forClass(TestBean.class), APPLICATION_JSON); assertHasMessageWriter(writers, forClass(TestBean.class), new MediaType("application", "x-jackson-smile")); assertHasMessageWriter(writers, forClass(TestBean.class), MediaType.parseMediaType("text/event-stream")); name = "webFluxContentTypeResolver"; RequestedContentTypeResolver resolver = context.getBean(name, RequestedContentTypeResolver.class); assertSame(resolver, handler.getContentTypeResolver()); }
Example #12
Source File: WebFluxConfigurationSupportTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void responseBodyResultHandler() throws Exception { ApplicationContext context = loadConfig(WebFluxConfig.class); String name = "responseBodyResultHandler"; ResponseBodyResultHandler handler = context.getBean(name, ResponseBodyResultHandler.class); assertNotNull(handler); assertEquals(100, handler.getOrder()); List<HttpMessageWriter<?>> writers = handler.getMessageWriters(); assertEquals(11, writers.size()); assertHasMessageWriter(writers, forClass(byte[].class), APPLICATION_OCTET_STREAM); assertHasMessageWriter(writers, forClass(ByteBuffer.class), APPLICATION_OCTET_STREAM); assertHasMessageWriter(writers, forClass(String.class), TEXT_PLAIN); assertHasMessageWriter(writers, forClass(Resource.class), IMAGE_PNG); assertHasMessageWriter(writers, forClass(Message.class), new MediaType("application", "x-protobuf")); assertHasMessageWriter(writers, forClass(TestBean.class), APPLICATION_XML); assertHasMessageWriter(writers, forClass(TestBean.class), APPLICATION_JSON); assertHasMessageWriter(writers, forClass(TestBean.class), new MediaType("application", "x-jackson-smile")); assertHasMessageWriter(writers, forClass(TestBean.class), null); name = "webFluxContentTypeResolver"; RequestedContentTypeResolver resolver = context.getBean(name, RequestedContentTypeResolver.class); assertSame(resolver, handler.getContentTypeResolver()); }
Example #13
Source File: ViewResolutionResultHandlerTests.java From java-technology-stack with MIT License | 5 votes |
private ViewResolutionResultHandler resultHandler(List<View> defaultViews, ViewResolver... resolvers) { List<ViewResolver> resolverList = Arrays.asList(resolvers); RequestedContentTypeResolver contentTypeResolver = new HeaderContentTypeResolver(); ViewResolutionResultHandler handler = new ViewResolutionResultHandler(resolverList, contentTypeResolver); handler.setDefaultViews(defaultViews); return handler; }
Example #14
Source File: ResponseBodyResultHandler.java From java-technology-stack 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 #15
Source File: AbstractMessageWriterResultHandler.java From java-technology-stack 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 #16
Source File: ResponseEntityResultHandler.java From java-technology-stack 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 #17
Source File: ProducesRequestCondition.java From java-technology-stack with MIT License | 5 votes |
/** * Private constructor with already parsed media type expressions. */ private ProducesRequestCondition(Collection<ProduceMediaTypeExpression> expressions, RequestedContentTypeResolver resolver) { this.expressions = new ArrayList<>(expressions); Collections.sort(this.expressions); this.contentTypeResolver = (resolver != null ? resolver : new RequestedContentTypeResolverBuilder().build()); }
Example #18
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 #19
Source File: ViewResolutionResultHandler.java From java-technology-stack with MIT License | 5 votes |
/** * Constructor with an {@link ReactiveAdapterRegistry} instance. * @param viewResolvers the view resolver to use * @param contentTypeResolver to determine the requested content type * @param registry for adaptation to reactive types */ public ViewResolutionResultHandler(List<ViewResolver> viewResolvers, RequestedContentTypeResolver contentTypeResolver, ReactiveAdapterRegistry registry) { super(contentTypeResolver, registry); this.viewResolvers.addAll(viewResolvers); AnnotationAwareOrderComparator.sort(this.viewResolvers); }
Example #20
Source File: AdminServerWebConfiguration.java From Moss with Apache License 2.0 | 5 votes |
@Bean public org.springframework.web.reactive.result.method.annotation.RequestMappingHandlerMapping adminHandlerMapping( RequestedContentTypeResolver webFluxContentTypeResolver) { org.springframework.web.reactive.result.method.annotation.RequestMappingHandlerMapping mapping = new de.codecentric.boot.admin.server.web.reactive.AdminControllerHandlerMapping( adminServerProperties.getContextPath()); mapping.setOrder(0); mapping.setContentTypeResolver(webFluxContentTypeResolver); return mapping; }
Example #21
Source File: ResponseBodyResultHandlerTests.java From java-technology-stack with MIT License | 5 votes |
@Before public void setup() throws Exception { List<HttpMessageWriter<?>> writerList = new ArrayList<>(5); writerList.add(new EncoderHttpMessageWriter<>(new ByteBufferEncoder())); writerList.add(new EncoderHttpMessageWriter<>(CharSequenceEncoder.allMimeTypes())); writerList.add(new ResourceHttpMessageWriter()); writerList.add(new EncoderHttpMessageWriter<>(new Jaxb2XmlEncoder())); writerList.add(new EncoderHttpMessageWriter<>(new Jackson2JsonEncoder())); RequestedContentTypeResolver resolver = new RequestedContentTypeResolverBuilder().build(); this.resultHandler = new ResponseBodyResultHandler(writerList, resolver); }
Example #22
Source File: ResponseBodyResultHandlerTests.java From spring-analysis-note with MIT License | 5 votes |
@Before public void setup() throws Exception { List<HttpMessageWriter<?>> writerList = new ArrayList<>(5); writerList.add(new EncoderHttpMessageWriter<>(new ByteBufferEncoder())); writerList.add(new EncoderHttpMessageWriter<>(CharSequenceEncoder.allMimeTypes())); writerList.add(new ResourceHttpMessageWriter()); writerList.add(new EncoderHttpMessageWriter<>(new Jaxb2XmlEncoder())); writerList.add(new EncoderHttpMessageWriter<>(new Jackson2JsonEncoder())); RequestedContentTypeResolver resolver = new RequestedContentTypeResolverBuilder().build(); this.resultHandler = new ResponseBodyResultHandler(writerList, resolver); }
Example #23
Source File: ReactiveWebServerInitializer.java From spring-fu with Apache License 2.0 | 5 votes |
@Override public void initialize(GenericApplicationContext context) { context.registerBean("webServerFactoryCustomizerBeanPostProcessor", WebServerFactoryCustomizerBeanPostProcessor.class, WebServerFactoryCustomizerBeanPostProcessor::new); context.registerBean(ReactiveWebServerFactoryCustomizer.class, () -> new ReactiveWebServerFactoryCustomizer(this.serverProperties)); context.registerBean(ConfigurableReactiveWebServerFactory.class, () -> serverFactory); //noinspection deprecation context.registerBean(ErrorAttributes.class, () -> new DefaultErrorAttributes(serverProperties.getError().isIncludeException())); context.registerBean(ErrorWebExceptionHandler.class, () -> { ErrorWebFluxAutoConfiguration errorConfiguration = new ErrorWebFluxAutoConfiguration(this.serverProperties); return errorConfiguration.errorWebExceptionHandler(context.getBean(ErrorAttributes.class), this.resourceProperties, context.getBeanProvider(ViewResolver.class), context.getBean(SERVER_CODEC_CONFIGURER_BEAN_NAME, ServerCodecConfigurer.class), context); }); context.registerBean("fuWebFluxConfiguration", EnableWebFluxConfigurationWrapper.class, () -> new EnableWebFluxConfigurationWrapper(context, webFluxProperties)); context.registerBean(LOCALE_CONTEXT_RESOLVER_BEAN_NAME, LocaleContextResolver.class, () -> context.getBean(EnableWebFluxConfigurationWrapper.class).localeContextResolver()); context.registerBean("responseStatusExceptionHandler", WebExceptionHandler.class, () -> context.getBean("fuWebFluxConfiguration", EnableWebFluxConfigurationWrapper.class).responseStatusExceptionHandler()); context.registerBean(RouterFunctionMapping.class, () -> context.getBean("fuWebFluxConfiguration", EnableWebFluxConfigurationWrapper.class).routerFunctionMapping(context.getBean(SERVER_CODEC_CONFIGURER_BEAN_NAME, ServerCodecConfigurer.class))); context.registerBean(SERVER_CODEC_CONFIGURER_BEAN_NAME, ServerCodecConfigurer.class, () -> context.getBean("fuWebFluxConfiguration", EnableWebFluxConfigurationWrapper.class).serverCodecConfigurer()); context.registerBean("webFluxAdapterRegistry", ReactiveAdapterRegistry.class, () -> context.getBean("fuWebFluxConfiguration", EnableWebFluxConfigurationWrapper.class).webFluxAdapterRegistry()); context.registerBean("handlerFunctionAdapter", HandlerFunctionAdapter.class, () -> context.getBean("fuWebFluxConfiguration", EnableWebFluxConfigurationWrapper.class).handlerFunctionAdapter()); context.registerBean("webFluxContentTypeResolver", RequestedContentTypeResolver.class, () -> context.getBean("fuWebFluxConfiguration", EnableWebFluxConfigurationWrapper.class).webFluxContentTypeResolver()); context.registerBean("webFluxConversionService", FormattingConversionService.class, () -> context.getBean("fuWebFluxConfiguration", EnableWebFluxConfigurationWrapper.class).webFluxConversionService()); context.registerBean("serverResponseResultHandler", ServerResponseResultHandler.class, () -> context.getBean("fuWebFluxConfiguration", EnableWebFluxConfigurationWrapper.class).serverResponseResultHandler(context.getBean(SERVER_CODEC_CONFIGURER_BEAN_NAME, ServerCodecConfigurer.class))); context.registerBean("simpleHandlerAdapter", SimpleHandlerAdapter.class, () -> context.getBean("fuWebFluxConfiguration", EnableWebFluxConfigurationWrapper.class).simpleHandlerAdapter()); context.registerBean("viewResolutionResultHandler", ViewResolutionResultHandler.class, () -> context.getBean("fuWebFluxConfiguration", EnableWebFluxConfigurationWrapper.class).viewResolutionResultHandler(context.getBean("webFluxAdapterRegistry", ReactiveAdapterRegistry.class), context.getBean("webFluxContentTypeResolver", RequestedContentTypeResolver.class))); context.registerBean("webFluxValidator", Validator.class, () -> context.getBean("fuWebFluxConfiguration", EnableWebFluxConfigurationWrapper.class).webFluxValidator()); context.registerBean(HttpHandler.class, () -> applicationContext(context).build()); context.registerBean(WEB_HANDLER_BEAN_NAME, DispatcherHandler.class, (Supplier<DispatcherHandler>) DispatcherHandler::new); context.registerBean(WebFluxConfig.class, () -> new WebFluxConfig(resourceProperties, webFluxProperties, context, context.getBeanProvider(HandlerMethodArgumentResolver.class), context.getBeanProvider(CodecCustomizer.class), context.getBeanProvider(ResourceHandlerRegistrationCustomizer.class), context.getBeanProvider(ViewResolver.class))); }
Example #24
Source File: AdminServerWebConfiguration.java From spring-boot-admin with Apache License 2.0 | 5 votes |
@Bean public org.springframework.web.reactive.result.method.annotation.RequestMappingHandlerMapping adminHandlerMapping( RequestedContentTypeResolver webFluxContentTypeResolver) { org.springframework.web.reactive.result.method.annotation.RequestMappingHandlerMapping mapping = new de.codecentric.boot.admin.server.web.reactive.AdminControllerHandlerMapping( this.adminServerProperties.getContextPath()); mapping.setOrder(0); mapping.setContentTypeResolver(webFluxContentTypeResolver); return mapping; }
Example #25
Source File: ViewResolutionResultHandlerTests.java From spring-analysis-note with MIT License | 5 votes |
private ViewResolutionResultHandler resultHandler(List<View> defaultViews, ViewResolver... resolvers) { List<ViewResolver> resolverList = Arrays.asList(resolvers); RequestedContentTypeResolver contentTypeResolver = new HeaderContentTypeResolver(); ViewResolutionResultHandler handler = new ViewResolutionResultHandler(resolverList, contentTypeResolver); handler.setDefaultViews(defaultViews); return handler; }
Example #26
Source File: WebFluxConfigurationSupportTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void responseBodyResultHandler() throws Exception { ApplicationContext context = loadConfig(WebFluxConfig.class); String name = "responseBodyResultHandler"; ResponseBodyResultHandler handler = context.getBean(name, ResponseBodyResultHandler.class); assertNotNull(handler); assertEquals(100, handler.getOrder()); List<HttpMessageWriter<?>> writers = handler.getMessageWriters(); assertEquals(11, writers.size()); assertHasMessageWriter(writers, forClass(byte[].class), APPLICATION_OCTET_STREAM); assertHasMessageWriter(writers, forClass(ByteBuffer.class), APPLICATION_OCTET_STREAM); assertHasMessageWriter(writers, forClass(String.class), TEXT_PLAIN); assertHasMessageWriter(writers, forClass(Resource.class), IMAGE_PNG); assertHasMessageWriter(writers, forClass(Message.class), new MediaType("application", "x-protobuf")); assertHasMessageWriter(writers, forClass(TestBean.class), APPLICATION_XML); assertHasMessageWriter(writers, forClass(TestBean.class), APPLICATION_JSON); assertHasMessageWriter(writers, forClass(TestBean.class), new MediaType("application", "x-jackson-smile")); assertHasMessageWriter(writers, forClass(TestBean.class), null); name = "webFluxContentTypeResolver"; RequestedContentTypeResolver resolver = context.getBean(name, RequestedContentTypeResolver.class); assertSame(resolver, handler.getContentTypeResolver()); }
Example #27
Source File: WebFluxConfigurationSupportTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void responseEntityResultHandler() throws Exception { ApplicationContext context = loadConfig(WebFluxConfig.class); String name = "responseEntityResultHandler"; ResponseEntityResultHandler handler = context.getBean(name, ResponseEntityResultHandler.class); assertNotNull(handler); assertEquals(0, handler.getOrder()); List<HttpMessageWriter<?>> writers = handler.getMessageWriters(); assertEquals(11, writers.size()); assertHasMessageWriter(writers, forClass(byte[].class), APPLICATION_OCTET_STREAM); assertHasMessageWriter(writers, forClass(ByteBuffer.class), APPLICATION_OCTET_STREAM); assertHasMessageWriter(writers, forClass(String.class), TEXT_PLAIN); assertHasMessageWriter(writers, forClass(Resource.class), IMAGE_PNG); assertHasMessageWriter(writers, forClass(Message.class), new MediaType("application", "x-protobuf")); assertHasMessageWriter(writers, forClass(TestBean.class), APPLICATION_XML); assertHasMessageWriter(writers, forClass(TestBean.class), APPLICATION_JSON); assertHasMessageWriter(writers, forClass(TestBean.class), new MediaType("application", "x-jackson-smile")); assertHasMessageWriter(writers, forClass(TestBean.class), MediaType.parseMediaType("text/event-stream")); name = "webFluxContentTypeResolver"; RequestedContentTypeResolver resolver = context.getBean(name, RequestedContentTypeResolver.class); assertSame(resolver, handler.getContentTypeResolver()); }
Example #28
Source File: WebFluxConfigurationSupport.java From spring-analysis-note with MIT License | 5 votes |
@Bean public ResponseEntityResultHandler responseEntityResultHandler( ReactiveAdapterRegistry webFluxAdapterRegistry, ServerCodecConfigurer serverCodecConfigurer, RequestedContentTypeResolver webFluxContentTypeResolver) { return new ResponseEntityResultHandler(serverCodecConfigurer.getWriters(), webFluxContentTypeResolver, webFluxAdapterRegistry); }
Example #29
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 #30
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); }