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

The following examples show how to use org.springframework.core.ReactiveAdapter#isNoValue() . 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: ViewResolutionResultHandler.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Override
public boolean supports(HandlerResult result) {
	if (hasModelAnnotation(result.getReturnTypeSource())) {
		return true;
	}

	Class<?> type = result.getReturnType().toClass();
	ReactiveAdapter adapter = getAdapter(result);
	if (adapter != null) {
		if (adapter.isNoValue()) {
			return true;
		}
		type = result.getReturnType().getGeneric().toClass();
	}

	return (CharSequence.class.isAssignableFrom(type) || Rendering.class.isAssignableFrom(type) ||
			Model.class.isAssignableFrom(type) || Map.class.isAssignableFrom(type) ||
			void.class.equals(type) || View.class.isAssignableFrom(type) ||
			!BeanUtils.isSimpleProperty(type));
}
 
Example 2
Source File: ViewResolutionResultHandler.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Override
public boolean supports(HandlerResult result) {
	if (hasModelAnnotation(result.getReturnTypeSource())) {
		return true;
	}

	Class<?> type = result.getReturnType().toClass();
	ReactiveAdapter adapter = getAdapter(result);
	if (adapter != null) {
		if (adapter.isNoValue()) {
			return true;
		}
		type = result.getReturnType().getGeneric().toClass();
	}

	return (CharSequence.class.isAssignableFrom(type) || Rendering.class.isAssignableFrom(type) ||
			Model.class.isAssignableFrom(type) || Map.class.isAssignableFrom(type) ||
			void.class.equals(type) || View.class.isAssignableFrom(type) ||
			!BeanUtils.isSimpleProperty(type));
}
 
Example 3
Source File: InvocableHandlerMethod.java    From spring-analysis-note with MIT License 5 votes vote down vote up
private static boolean isAsyncVoidReturnType(MethodParameter returnType, @Nullable ReactiveAdapter adapter) {
	if (adapter != null && adapter.supportsEmpty()) {
		if (adapter.isNoValue()) {
			return true;
		}
		Type parameterType = returnType.getGenericParameterType();
		if (parameterType instanceof ParameterizedType) {
			ParameterizedType type = (ParameterizedType) parameterType;
			if (type.getActualTypeArguments().length == 1) {
				return Void.class.equals(type.getActualTypeArguments()[0]);
			}
		}
	}
	return false;
}
 
Example 4
Source File: InvocableHandlerMethod.java    From java-technology-stack with MIT License 5 votes vote down vote up
private static boolean isAsyncVoidReturnType(MethodParameter returnType, @Nullable ReactiveAdapter adapter) {
	if (adapter != null && adapter.supportsEmpty()) {
		if (adapter.isNoValue()) {
			return true;
		}
		Type parameterType = returnType.getGenericParameterType();
		if (parameterType instanceof ParameterizedType) {
			ParameterizedType type = (ParameterizedType) parameterType;
			if (type.getActualTypeArguments().length == 1) {
				return Void.class.equals(type.getActualTypeArguments()[0]);
			}
		}
	}
	return false;
}
 
Example 5
Source File: AbstractMessageWriterResultHandler.java    From java-technology-stack with MIT License 5 votes vote down vote up
private ResolvableType getElementType(ReactiveAdapter adapter, ResolvableType genericType) {
	if (adapter.isNoValue()) {
		return ResolvableType.forClass(Void.class);
	}
	else if (genericType != ResolvableType.NONE) {
		return genericType;
	}
	else {
		return ResolvableType.forClass(Object.class);
	}
}
 
Example 6
Source File: ResponseEntityResultHandler.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public boolean supports(HandlerResult result) {
	Class<?> valueType = resolveReturnValueType(result);
	if (isSupportedType(valueType)) {
		return true;
	}
	ReactiveAdapter adapter = getAdapter(result);
	return adapter != null && !adapter.isNoValue() &&
			isSupportedType(result.getReturnType().getGeneric().toClass());
}
 
Example 7
Source File: AbstractEncoderMethodReturnValueHandler.java    From spring-analysis-note with MIT License 5 votes vote down vote up
private ResolvableType getElementType(ReactiveAdapter adapter, ResolvableType type) {
	if (adapter.isNoValue()) {
		return VOID_RESOLVABLE_TYPE;
	}
	else if (type != ResolvableType.NONE) {
		return type;
	}
	else {
		return OBJECT_RESOLVABLE_TYPE;
	}
}
 
Example 8
Source File: AbstractMessageWriterResultHandler.java    From spring-analysis-note with MIT License 5 votes vote down vote up
private ResolvableType getElementType(ReactiveAdapter adapter, ResolvableType genericType) {
	if (adapter.isNoValue()) {
		return ResolvableType.forClass(Void.class);
	}
	else if (genericType != ResolvableType.NONE) {
		return genericType;
	}
	else {
		return ResolvableType.forClass(Object.class);
	}
}
 
Example 9
Source File: ResponseEntityResultHandler.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
public boolean supports(HandlerResult result) {
	Class<?> valueType = resolveReturnValueType(result);
	if (isSupportedType(valueType)) {
		return true;
	}
	ReactiveAdapter adapter = getAdapter(result);
	return adapter != null && !adapter.isNoValue() &&
			isSupportedType(result.getReturnType().getGeneric().toClass());
}
 
Example 10
Source File: InvocableHandlerMethod.java    From spring-analysis-note with MIT License 5 votes vote down vote up
private boolean isAsyncVoidReturnType(MethodParameter returnType, @Nullable ReactiveAdapter reactiveAdapter) {
	if (reactiveAdapter != null && reactiveAdapter.supportsEmpty()) {
		if (reactiveAdapter.isNoValue()) {
			return true;
		}
		Type parameterType = returnType.getGenericParameterType();
		if (parameterType instanceof ParameterizedType) {
			ParameterizedType type = (ParameterizedType) parameterType;
			if (type.getActualTypeArguments().length == 1) {
				return Void.class.equals(type.getActualTypeArguments()[0]);
			}
		}
	}
	return false;
}
 
Example 11
Source File: HandlerMethodArgumentResolverSupport.java    From spring-analysis-note with MIT License 4 votes vote down vote up
private void assertHasValues(ReactiveAdapter adapter, MethodParameter param) {
	if (adapter.isNoValue()) {
		throw new IllegalArgumentException(
				"No value reactive types not supported: " + param.getGenericParameterType());
	}
}
 
Example 12
Source File: ReactiveReturnValueHandler.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
public boolean isAsyncReturnValue(Object returnValue, MethodParameter returnType) {
	ReactiveAdapter adapter = this.adapterRegistry.getAdapter(returnType.getParameterType(), returnValue);
	return (adapter != null && !adapter.isMultiValue() && !adapter.isNoValue());
}
 
Example 13
Source File: ModelInitializer.java    From spring-analysis-note with MIT License 4 votes vote down vote up
private boolean isAsyncVoidType(ResolvableType type, @Nullable  ReactiveAdapter adapter) {
	return (adapter != null && (adapter.isNoValue() || type.resolveGeneric() == Void.class));
}
 
Example 14
Source File: ViewResolutionResultHandler.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public Mono<Void> handleResult(ServerWebExchange exchange, HandlerResult result) {
	Mono<Object> valueMono;
	ResolvableType valueType;
	ReactiveAdapter adapter = getAdapter(result);

	if (adapter != null) {
		if (adapter.isMultiValue()) {
			throw new IllegalArgumentException(
					"Multi-value reactive types not supported in view resolution: " + result.getReturnType());
		}

		valueMono = (result.getReturnValue() != null ?
				Mono.from(adapter.toPublisher(result.getReturnValue())) : Mono.empty());

		valueType = (adapter.isNoValue() ? ResolvableType.forClass(Void.class) :
				result.getReturnType().getGeneric());
	}
	else {
		valueMono = Mono.justOrEmpty(result.getReturnValue());
		valueType = result.getReturnType();
	}

	return valueMono
			.switchIfEmpty(exchange.isNotModified() ? Mono.empty() : NO_VALUE_MONO)
			.flatMap(returnValue -> {

				Mono<List<View>> viewsMono;
				Model model = result.getModel();
				MethodParameter parameter = result.getReturnTypeSource();
				Locale locale = LocaleContextHolder.getLocale(exchange.getLocaleContext());

				Class<?> clazz = valueType.toClass();
				if (clazz == Object.class) {
					clazz = returnValue.getClass();
				}

				if (returnValue == NO_VALUE || clazz == void.class || clazz == Void.class) {
					viewsMono = resolveViews(getDefaultViewName(exchange), locale);
				}
				else if (CharSequence.class.isAssignableFrom(clazz) && !hasModelAnnotation(parameter)) {
					viewsMono = resolveViews(returnValue.toString(), locale);
				}
				else if (Rendering.class.isAssignableFrom(clazz)) {
					Rendering render = (Rendering) returnValue;
					HttpStatus status = render.status();
					if (status != null) {
						exchange.getResponse().setStatusCode(status);
					}
					exchange.getResponse().getHeaders().putAll(render.headers());
					model.addAllAttributes(render.modelAttributes());
					Object view = render.view();
					if (view == null) {
						view = getDefaultViewName(exchange);
					}
					viewsMono = (view instanceof String ? resolveViews((String) view, locale) :
							Mono.just(Collections.singletonList((View) view)));
				}
				else if (Model.class.isAssignableFrom(clazz)) {
					model.addAllAttributes(((Model) returnValue).asMap());
					viewsMono = resolveViews(getDefaultViewName(exchange), locale);
				}
				else if (Map.class.isAssignableFrom(clazz) && !hasModelAnnotation(parameter)) {
					model.addAllAttributes((Map<String, ?>) returnValue);
					viewsMono = resolveViews(getDefaultViewName(exchange), locale);
				}
				else if (View.class.isAssignableFrom(clazz)) {
					viewsMono = Mono.just(Collections.singletonList((View) returnValue));
				}
				else {
					String name = getNameForReturnValue(parameter);
					model.addAttribute(name, returnValue);
					viewsMono = resolveViews(getDefaultViewName(exchange), locale);
				}

				updateBindingContext(result.getBindingContext(), exchange);

				return viewsMono.flatMap(views -> render(views, model.asMap(), exchange));
			});
}
 
Example 15
Source File: ModelInitializer.java    From java-technology-stack with MIT License 4 votes vote down vote up
private boolean isAsyncVoidType(ResolvableType type, @Nullable  ReactiveAdapter adapter) {
	return (adapter != null && (adapter.isNoValue() || type.resolveGeneric() == Void.class));
}
 
Example 16
Source File: ViewResolutionResultHandler.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public Mono<Void> handleResult(ServerWebExchange exchange, HandlerResult result) {
	Mono<Object> valueMono;
	ResolvableType valueType;
	ReactiveAdapter adapter = getAdapter(result);

	if (adapter != null) {
		if (adapter.isMultiValue()) {
			throw new IllegalArgumentException(
					"Multi-value reactive types not supported in view resolution: " + result.getReturnType());
		}

		valueMono = (result.getReturnValue() != null ?
				Mono.from(adapter.toPublisher(result.getReturnValue())) : Mono.empty());

		valueType = (adapter.isNoValue() ? ResolvableType.forClass(Void.class) :
				result.getReturnType().getGeneric());
	}
	else {
		valueMono = Mono.justOrEmpty(result.getReturnValue());
		valueType = result.getReturnType();
	}

	return valueMono
			.switchIfEmpty(exchange.isNotModified() ? Mono.empty() : NO_VALUE_MONO)
			.flatMap(returnValue -> {

				Mono<List<View>> viewsMono;
				Model model = result.getModel();
				MethodParameter parameter = result.getReturnTypeSource();
				Locale locale = LocaleContextHolder.getLocale(exchange.getLocaleContext());

				Class<?> clazz = valueType.toClass();
				if (clazz == Object.class) {
					clazz = returnValue.getClass();
				}

				if (returnValue == NO_VALUE || clazz == void.class || clazz == Void.class) {
					viewsMono = resolveViews(getDefaultViewName(exchange), locale);
				}
				else if (CharSequence.class.isAssignableFrom(clazz) && !hasModelAnnotation(parameter)) {
					viewsMono = resolveViews(returnValue.toString(), locale);
				}
				else if (Rendering.class.isAssignableFrom(clazz)) {
					Rendering render = (Rendering) returnValue;
					HttpStatus status = render.status();
					if (status != null) {
						exchange.getResponse().setStatusCode(status);
					}
					exchange.getResponse().getHeaders().putAll(render.headers());
					model.addAllAttributes(render.modelAttributes());
					Object view = render.view();
					if (view == null) {
						view = getDefaultViewName(exchange);
					}
					viewsMono = (view instanceof String ? resolveViews((String) view, locale) :
							Mono.just(Collections.singletonList((View) view)));
				}
				else if (Model.class.isAssignableFrom(clazz)) {
					model.addAllAttributes(((Model) returnValue).asMap());
					viewsMono = resolveViews(getDefaultViewName(exchange), locale);
				}
				else if (Map.class.isAssignableFrom(clazz) && !hasModelAnnotation(parameter)) {
					model.addAllAttributes((Map<String, ?>) returnValue);
					viewsMono = resolveViews(getDefaultViewName(exchange), locale);
				}
				else if (View.class.isAssignableFrom(clazz)) {
					viewsMono = Mono.just(Collections.singletonList((View) returnValue));
				}
				else {
					String name = getNameForReturnValue(parameter);
					model.addAttribute(name, returnValue);
					viewsMono = resolveViews(getDefaultViewName(exchange), locale);
				}

				updateBindingContext(result.getBindingContext(), exchange);

				return viewsMono.flatMap(views -> render(views, model.asMap(), exchange));
			});
}
 
Example 17
Source File: ReactiveReturnValueHandler.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
public boolean isAsyncReturnValue(Object returnValue, MethodParameter returnType) {
	ReactiveAdapter adapter = this.adapterRegistry.getAdapter(returnType.getParameterType(), returnValue);
	return (adapter != null && !adapter.isMultiValue() && !adapter.isNoValue());
}
 
Example 18
Source File: HandlerMethodArgumentResolverSupport.java    From java-technology-stack with MIT License 4 votes vote down vote up
private void assertHasValues(ReactiveAdapter adapter, MethodParameter param) {
	if (adapter.isNoValue()) {
		throw new IllegalArgumentException(
				"No value reactive types not supported: " + param.getGenericParameterType());
	}
}