Search in sources :

Example 1 with DestinationPatternsMessageCondition

use of org.springframework.messaging.handler.DestinationPatternsMessageCondition in project spring-framework by spring-projects.

the class SimpMessageMappingInfo method getMatchingCondition.

@Override
public SimpMessageMappingInfo getMatchingCondition(Message<?> message) {
    SimpMessageTypeMessageCondition typeCond = this.messageTypeMessageCondition.getMatchingCondition(message);
    if (typeCond == null) {
        return null;
    }
    DestinationPatternsMessageCondition destCond = this.destinationConditions.getMatchingCondition(message);
    if (destCond == null) {
        return null;
    }
    return new SimpMessageMappingInfo(typeCond, destCond);
}
Also used : DestinationPatternsMessageCondition(org.springframework.messaging.handler.DestinationPatternsMessageCondition)

Example 2 with DestinationPatternsMessageCondition

use of org.springframework.messaging.handler.DestinationPatternsMessageCondition in project spring-framework by spring-projects.

the class MessageMappingMessageHandler method getCondition.

/**
 * Determine the mapping condition for the given annotated element.
 * @param element the element to check
 * @return the condition, or {@code null}
 */
@Nullable
protected CompositeMessageCondition getCondition(AnnotatedElement element) {
    MessageMapping ann = AnnotatedElementUtils.findMergedAnnotation(element, MessageMapping.class);
    if (ann == null || ann.value().length == 0) {
        return null;
    }
    String[] patterns = processDestinations(ann.value());
    return new CompositeMessageCondition(new DestinationPatternsMessageCondition(patterns, obtainRouteMatcher()));
}
Also used : CompositeMessageCondition(org.springframework.messaging.handler.CompositeMessageCondition) DestinationPatternsMessageCondition(org.springframework.messaging.handler.DestinationPatternsMessageCondition) MessageMapping(org.springframework.messaging.handler.annotation.MessageMapping) Nullable(org.springframework.lang.Nullable)

Example 3 with DestinationPatternsMessageCondition

use of org.springframework.messaging.handler.DestinationPatternsMessageCondition in project spring-framework by spring-projects.

the class RSocketMessageHandler method getCondition.

@Override
@Nullable
protected CompositeMessageCondition getCondition(AnnotatedElement element) {
    MessageMapping ann1 = AnnotatedElementUtils.findMergedAnnotation(element, MessageMapping.class);
    if (ann1 != null && ann1.value().length > 0) {
        return new CompositeMessageCondition(RSocketFrameTypeMessageCondition.EMPTY_CONDITION, new DestinationPatternsMessageCondition(processDestinations(ann1.value()), obtainRouteMatcher()));
    }
    ConnectMapping ann2 = AnnotatedElementUtils.findMergedAnnotation(element, ConnectMapping.class);
    if (ann2 != null) {
        String[] patterns = processDestinations(ann2.value());
        return new CompositeMessageCondition(RSocketFrameTypeMessageCondition.CONNECT_CONDITION, new DestinationPatternsMessageCondition(patterns, obtainRouteMatcher()));
    }
    return null;
}
Also used : CompositeMessageCondition(org.springframework.messaging.handler.CompositeMessageCondition) DestinationPatternsMessageCondition(org.springframework.messaging.handler.DestinationPatternsMessageCondition) ConnectMapping(org.springframework.messaging.rsocket.annotation.ConnectMapping) MessageMapping(org.springframework.messaging.handler.annotation.MessageMapping) Nullable(org.springframework.lang.Nullable)

Example 4 with DestinationPatternsMessageCondition

use of org.springframework.messaging.handler.DestinationPatternsMessageCondition in project spring-framework by spring-projects.

the class RSocketMessageHandler method extendMapping.

@Override
protected CompositeMessageCondition extendMapping(CompositeMessageCondition composite, HandlerMethod handler) {
    List<MessageCondition<?>> conditions = composite.getMessageConditions();
    Assert.isTrue(conditions.size() == 2 && conditions.get(0) instanceof RSocketFrameTypeMessageCondition && conditions.get(1) instanceof DestinationPatternsMessageCondition, "Unexpected message condition types");
    if (conditions.get(0) != RSocketFrameTypeMessageCondition.EMPTY_CONDITION) {
        return composite;
    }
    int responseCardinality = getCardinality(handler.getReturnType());
    int requestCardinality = 0;
    for (MethodParameter parameter : handler.getMethodParameters()) {
        if (getArgumentResolvers().getArgumentResolver(parameter) instanceof PayloadMethodArgumentResolver) {
            requestCardinality = getCardinality(parameter);
        }
    }
    return new CompositeMessageCondition(RSocketFrameTypeMessageCondition.getCondition(requestCardinality, responseCardinality), conditions.get(1));
}
Also used : DestinationPatternsMessageCondition(org.springframework.messaging.handler.DestinationPatternsMessageCondition) MessageCondition(org.springframework.messaging.handler.MessageCondition) CompositeMessageCondition(org.springframework.messaging.handler.CompositeMessageCondition) CompositeMessageCondition(org.springframework.messaging.handler.CompositeMessageCondition) DestinationPatternsMessageCondition(org.springframework.messaging.handler.DestinationPatternsMessageCondition) PayloadMethodArgumentResolver(org.springframework.messaging.handler.annotation.reactive.PayloadMethodArgumentResolver) MethodParameter(org.springframework.core.MethodParameter)

Example 5 with DestinationPatternsMessageCondition

use of org.springframework.messaging.handler.DestinationPatternsMessageCondition in project spring-framework by spring-projects.

the class RSocketMessageHandlerTests method testMapping.

private static void testMapping(Object controller, String... expectedPatterns) {
    RSocketMessageHandler handler = new RSocketMessageHandler();
    handler.setDecoders(Collections.singletonList(StringDecoder.allMimeTypes()));
    handler.setEncoders(Collections.singletonList(CharSequenceEncoder.allMimeTypes()));
    handler.setHandlers(Collections.singletonList(controller));
    handler.afterPropertiesSet();
    Map<CompositeMessageCondition, HandlerMethod> map = handler.getHandlerMethods();
    assertThat(map).hasSize(1);
    CompositeMessageCondition condition = map.entrySet().iterator().next().getKey();
    RSocketFrameTypeMessageCondition c1 = condition.getCondition(RSocketFrameTypeMessageCondition.class);
    assertThat(c1.getFrameTypes()).contains(FrameType.SETUP, FrameType.METADATA_PUSH);
    DestinationPatternsMessageCondition c2 = condition.getCondition(DestinationPatternsMessageCondition.class);
    if (ObjectUtils.isEmpty(expectedPatterns)) {
        assertThat(c2.getPatterns()).isEmpty();
    } else {
        assertThat(c2.getPatterns()).contains(expectedPatterns);
    }
}
Also used : CompositeMessageCondition(org.springframework.messaging.handler.CompositeMessageCondition) DestinationPatternsMessageCondition(org.springframework.messaging.handler.DestinationPatternsMessageCondition) HandlerMethod(org.springframework.messaging.handler.HandlerMethod)

Aggregations

DestinationPatternsMessageCondition (org.springframework.messaging.handler.DestinationPatternsMessageCondition)6 CompositeMessageCondition (org.springframework.messaging.handler.CompositeMessageCondition)4 Nullable (org.springframework.lang.Nullable)2 MessageMapping (org.springframework.messaging.handler.annotation.MessageMapping)2 MethodParameter (org.springframework.core.MethodParameter)1 HandlerMethod (org.springframework.messaging.handler.HandlerMethod)1 MessageCondition (org.springframework.messaging.handler.MessageCondition)1 PayloadMethodArgumentResolver (org.springframework.messaging.handler.annotation.reactive.PayloadMethodArgumentResolver)1 ConnectMapping (org.springframework.messaging.rsocket.annotation.ConnectMapping)1