Java Code Examples for org.springframework.http.codec.ServerCodecConfigurer#create()

The following examples show how to use org.springframework.http.codec.ServerCodecConfigurer#create() . 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: RequestMappingHandlerAdapter.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@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 2
Source File: NashornScriptTemplateTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test // gh-22754
public void subscribeWithoutDemand() throws Exception {
	ZeroDemandResponse response = new ZeroDemandResponse();
	ServerWebExchange exchange = new DefaultServerWebExchange(
			MockServerHttpRequest.get("/path").build(), response,
			new DefaultWebSessionManager(), ServerCodecConfigurer.create(),
			new AcceptHeaderLocaleContextResolver());

	Map<String, Object> model = new HashMap<>();
	model.put("title", "Layout example");
	model.put("body", "This is the body");
	String viewUrl = "org/springframework/web/reactive/result/view/script/nashorn/template.html";
	ScriptTemplateView view = createViewWithUrl(viewUrl, ScriptTemplatingConfiguration.class);
	view.render(model, null, exchange).subscribe();

	response.cancelWrite();
	response.checkForLeaks();
}
 
Example 3
Source File: FreeMarkerViewTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test // gh-22754
public void subscribeWithoutDemand() {
	ZeroDemandResponse response = new ZeroDemandResponse();
	ServerWebExchange exchange = new DefaultServerWebExchange(
			MockServerHttpRequest.get("/path").build(), response,
			new DefaultWebSessionManager(), ServerCodecConfigurer.create(),
			new AcceptHeaderLocaleContextResolver());

	FreeMarkerView view = new FreeMarkerView();
	view.setConfiguration(this.freeMarkerConfig);
	view.setUrl("test.ftl");

	ModelMap model = new ExtendedModelMap();
	model.addAttribute("hello", "hi FreeMarker");
	view.render(model, null, exchange).subscribe();

	response.cancelWrite();
	response.checkForLeaks();
}
 
Example 4
Source File: ControllerMethodResolverTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Before
public void setup() {
	ArgumentResolverConfigurer resolvers = new ArgumentResolverConfigurer();
	resolvers.addCustomResolver(new CustomArgumentResolver());
	resolvers.addCustomResolver(new CustomSyncArgumentResolver());

	ServerCodecConfigurer codecs = ServerCodecConfigurer.create();
	codecs.customCodecs().decoder(new ByteArrayDecoder());
	codecs.customCodecs().decoder(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);
}
 
Example 5
Source File: DefaultWebSessionManagerTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Before
public void setUp() throws Exception {

	given(this.createSession.save()).willReturn(Mono.empty());
	given(this.createSession.getId()).willReturn("create-session-id");
	given(this.updateSession.getId()).willReturn("update-session-id");

	given(this.sessionStore.createWebSession()).willReturn(Mono.just(this.createSession));
	given(this.sessionStore.retrieveSession(this.updateSession.getId())).willReturn(Mono.just(this.updateSession));

	this.sessionManager = new DefaultWebSessionManager();
	this.sessionManager.setSessionIdResolver(this.sessionIdResolver);
	this.sessionManager.setSessionStore(this.sessionStore);

	MockServerHttpRequest request = MockServerHttpRequest.get("/path").build();
	MockServerHttpResponse response = new MockServerHttpResponse();
	this.exchange = new DefaultServerWebExchange(request, response, this.sessionManager,
			ServerCodecConfigurer.create(), new AcceptHeaderLocaleContextResolver());
}
 
Example 6
Source File: DefaultWebSessionManagerTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Before
public void setUp() throws Exception {

	when(this.createSession.save()).thenReturn(Mono.empty());
	when(this.createSession.getId()).thenReturn("create-session-id");
	when(this.updateSession.getId()).thenReturn("update-session-id");

	when(this.sessionStore.createWebSession()).thenReturn(Mono.just(this.createSession));
	when(this.sessionStore.retrieveSession(this.updateSession.getId())).thenReturn(Mono.just(this.updateSession));

	this.sessionManager = new DefaultWebSessionManager();
	this.sessionManager.setSessionIdResolver(this.sessionIdResolver);
	this.sessionManager.setSessionStore(this.sessionStore);

	MockServerHttpRequest request = MockServerHttpRequest.get("/path").build();
	MockServerHttpResponse response = new MockServerHttpResponse();
	this.exchange = new DefaultServerWebExchange(request, response, this.sessionManager,
			ServerCodecConfigurer.create(), new AcceptHeaderLocaleContextResolver());
}
 
Example 7
Source File: ControllerMethodResolverTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Before
public void setup() {
	ArgumentResolverConfigurer resolvers = new ArgumentResolverConfigurer();
	resolvers.addCustomResolver(new CustomArgumentResolver());
	resolvers.addCustomResolver(new CustomSyncArgumentResolver());

	ServerCodecConfigurer codecs = ServerCodecConfigurer.create();
	codecs.customCodecs().decoder(new ByteArrayDecoder());
	codecs.customCodecs().decoder(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);
}
 
Example 8
Source File: RequestMappingHandlerAdapter.java    From java-technology-stack with MIT License 6 votes vote down vote up
@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: FunctionEndpointInitializer.java    From spring-cloud-function with Apache License 2.0 5 votes vote down vote up
private DefaultErrorWebExceptionHandler errorHandler(GenericApplicationContext context) {
	context.registerBean(ErrorAttributes.class, () -> new DefaultErrorAttributes());
	context.registerBean(ErrorProperties.class, () -> new ErrorProperties());
	context.registerBean(ResourceProperties.class, () -> new ResourceProperties());
	DefaultErrorWebExceptionHandler handler = new DefaultErrorWebExceptionHandler(
			context.getBean(ErrorAttributes.class), context.getBean(ResourceProperties.class),
			context.getBean(ErrorProperties.class), context);
	ServerCodecConfigurer codecs = ServerCodecConfigurer.create();
	handler.setMessageWriters(codecs.getWriters());
	handler.setMessageReaders(codecs.getReaders());
	return handler;
}
 
Example 10
Source File: RouterFunctionMapping.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
public void afterPropertiesSet() throws Exception {
	if (CollectionUtils.isEmpty(this.messageReaders)) {
		ServerCodecConfigurer codecConfigurer = ServerCodecConfigurer.create();
		this.messageReaders = codecConfigurer.getReaders();
	}

	if (this.routerFunction == null) {
		initRouterFunctions();
	}
}
 
Example 11
Source File: ReactiveWebServerInitializer.java    From spring-fu with Apache License 2.0 5 votes vote down vote up
@Override
public ServerCodecConfigurer serverCodecConfigurer() {
	ServerCodecConfigurer configurer = ServerCodecConfigurer.create();
	configurer.registerDefaults(false);
	getApplicationContext().getBeanProvider(CodecCustomizer.class)
			.forEach((customizer) -> customizer.customize(configurer));
	return configurer;
}
 
Example 12
Source File: RouterFunctionMapping.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public void afterPropertiesSet() throws Exception {
	if (CollectionUtils.isEmpty(this.messageReaders)) {
		ServerCodecConfigurer codecConfigurer = ServerCodecConfigurer.create();
		this.messageReaders = codecConfigurer.getReaders();
	}

	if (this.routerFunction == null) {
		initRouterFunctions();
	}
}
 
Example 13
Source File: MockServerWebExchange.java    From spring-analysis-note with MIT License 4 votes vote down vote up
private MockServerWebExchange(MockServerHttpRequest request, WebSessionManager sessionManager) {
	super(request, new MockServerHttpResponse(), sessionManager,
			ServerCodecConfigurer.create(), new AcceptHeaderLocaleContextResolver());
}
 
Example 14
Source File: DefaultServerWebExchangeTests.java    From java-technology-stack with MIT License 4 votes vote down vote up
private DefaultServerWebExchange createExchange(MockServerHttpRequest request) {
	return new DefaultServerWebExchange(request, new MockServerHttpResponse(),
			new DefaultWebSessionManager(), ServerCodecConfigurer.create(),
			new AcceptHeaderLocaleContextResolver());
}
 
Example 15
Source File: MockServerWebExchange.java    From java-technology-stack with MIT License 4 votes vote down vote up
private MockServerWebExchange(MockServerHttpRequest request, WebSessionManager sessionManager) {
	super(request, new MockServerHttpResponse(), sessionManager,
			ServerCodecConfigurer.create(), new AcceptHeaderLocaleContextResolver());
}
 
Example 16
Source File: MockServerWebExchange.java    From java-technology-stack with MIT License 4 votes vote down vote up
private MockServerWebExchange(MockServerHttpRequest request, WebSessionManager sessionManager) {
	super(request, new MockServerHttpResponse(), sessionManager,
			ServerCodecConfigurer.create(), new AcceptHeaderLocaleContextResolver());
}
 
Example 17
Source File: MockServerWebExchange.java    From spring-analysis-note with MIT License 4 votes vote down vote up
private MockServerWebExchange(MockServerHttpRequest request, WebSessionManager sessionManager) {
	super(request, new MockServerHttpResponse(), sessionManager,
			ServerCodecConfigurer.create(), new AcceptHeaderLocaleContextResolver());
}
 
Example 18
Source File: DefaultServerWebExchangeTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
private DefaultServerWebExchange createExchange(MockServerHttpRequest request) {
	return new DefaultServerWebExchange(request, new MockServerHttpResponse(),
			new DefaultWebSessionManager(), ServerCodecConfigurer.create(),
			new AcceptHeaderLocaleContextResolver());
}