Java Code Examples for org.springframework.core.ReactiveAdapter#fromPublisher()

The following examples show how to use org.springframework.core.ReactiveAdapter#fromPublisher() . 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: RequestAttributeMethodArgumentResolver.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Override
protected Object resolveNamedValue(String name, MethodParameter parameter, ServerWebExchange exchange) {
	Object value = exchange.getAttribute(name);
	ReactiveAdapter toAdapter = getAdapterRegistry().getAdapter(parameter.getParameterType());
	if (toAdapter != null) {
		if (value == null) {
			Assert.isTrue(toAdapter.supportsEmpty(),
					() -> "No request attribute '" + name + "' and target type " +
							parameter.getGenericParameterType() + " doesn't support empty values.");
			return toAdapter.fromPublisher(Mono.empty());
		}
		if (parameter.getParameterType().isAssignableFrom(value.getClass())) {
			return value;
		}
		ReactiveAdapter fromAdapter = getAdapterRegistry().getAdapter(value.getClass());
		Assert.isTrue(fromAdapter != null,
				() -> getClass().getSimpleName() + " doesn't support " +
						"reactive type wrapper: " + parameter.getGenericParameterType());
		return toAdapter.fromPublisher(fromAdapter.toPublisher(value));
	}
	return value;
}
 
Example 2
Source File: RequestAttributeMethodArgumentResolver.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Override
protected Object resolveNamedValue(String name, MethodParameter parameter, ServerWebExchange exchange) {
	Object value = exchange.getAttribute(name);
	ReactiveAdapter toAdapter = getAdapterRegistry().getAdapter(parameter.getParameterType());
	if (toAdapter != null) {
		if (value == null) {
			Assert.isTrue(toAdapter.supportsEmpty(),
					() -> "No request attribute '" + name + "' and target type " +
							parameter.getGenericParameterType() + " doesn't support empty values.");
			return toAdapter.fromPublisher(Mono.empty());
		}
		if (parameter.getParameterType().isAssignableFrom(value.getClass())) {
			return value;
		}
		ReactiveAdapter fromAdapter = getAdapterRegistry().getAdapter(value.getClass());
		Assert.isTrue(fromAdapter != null,
				() -> getClass().getSimpleName() + " doesn't support " +
						"reactive type wrapper: " + parameter.getGenericParameterType());
		return toAdapter.fromPublisher(fromAdapter.toPublisher(value));
	}
	return value;
}