Search in sources :

Example 6 with ArgumentBinder

use of io.micronaut.core.bind.ArgumentBinder in project micronaut-core by micronaut-projects.

the class WebSocketStateBinderRegistry method findArgumentBinder.

@Override
public <T> Optional<ArgumentBinder<T, WebSocketState>> findArgumentBinder(Argument<T> argument, WebSocketState source) {
    Optional<ArgumentBinder<T, HttpRequest<?>>> argumentBinder = requestBinderRegistry.findArgumentBinder(argument, source.getOriginatingRequest());
    if (argumentBinder.isPresent()) {
        ArgumentBinder<T, HttpRequest<?>> adapted = argumentBinder.get();
        boolean isParameterBinder = adapted instanceof AnnotatedArgumentBinder && ((AnnotatedArgumentBinder) adapted).getAnnotationType() == QueryValue.class;
        if (!isParameterBinder) {
            return Optional.of((context, source1) -> adapted.bind(context, source.getOriginatingRequest()));
        }
    }
    ArgumentBinder binder = byType.get(argument.getType());
    if (binder != null) {
        // noinspection unchecked
        return Optional.of(binder);
    } else {
        ConvertibleValues<Object> uriVariables = source.getSession().getUriVariables();
        if (uriVariables.contains(argument.getName())) {
            return Optional.of((context, s) -> () -> uriVariables.get(argument.getName(), argument));
        } else {
            return Optional.of((context, s) -> (ArgumentBinder.BindingResult<T>) queryValueArgumentBinder.bind((ArgumentConversionContext<Object>) context, s.getOriginatingRequest()));
        }
    }
}
Also used : HttpRequest(io.micronaut.http.HttpRequest) AnnotatedArgumentBinder(io.micronaut.core.bind.annotation.AnnotatedArgumentBinder) QueryValueArgumentBinder(io.micronaut.http.bind.binders.QueryValueArgumentBinder) AnnotatedArgumentBinder(io.micronaut.core.bind.annotation.AnnotatedArgumentBinder) ArgumentBinder(io.micronaut.core.bind.ArgumentBinder) QueryValue(io.micronaut.http.annotation.QueryValue)

Aggregations

ArgumentBinder (io.micronaut.core.bind.ArgumentBinder)6 Annotation (java.lang.annotation.Annotation)3 ArgumentConversionContext (io.micronaut.core.convert.ArgumentConversionContext)2 AnnotatedArgumentBinder (io.micronaut.core.bind.annotation.AnnotatedArgumentBinder)1 HttpRequest (io.micronaut.http.HttpRequest)1 QueryValue (io.micronaut.http.annotation.QueryValue)1 BodyArgumentBinder (io.micronaut.http.bind.binders.BodyArgumentBinder)1 NonBlockingBodyArgumentBinder (io.micronaut.http.bind.binders.NonBlockingBodyArgumentBinder)1 QueryValueArgumentBinder (io.micronaut.http.bind.binders.QueryValueArgumentBinder)1 RequestBeanAnnotationBinder (io.micronaut.http.bind.binders.RequestBeanAnnotationBinder)1 UnresolvedArgument (io.micronaut.web.router.UnresolvedArgument)1 Message (io.nats.client.Message)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Optional (java.util.Optional)1 Publisher (org.reactivestreams.Publisher)1