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);
}
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()));
}
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;
}
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));
}
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);
}
}
Aggregations