use of org.springframework.messaging.handler.CompositeMessageCondition 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.CompositeMessageCondition 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.CompositeMessageCondition 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.CompositeMessageCondition 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);
}
}
use of org.springframework.messaging.handler.CompositeMessageCondition in project spring-framework by spring-projects.
the class RSocketMessageHandler method handleNoMatch.
@Override
protected void handleNoMatch(@Nullable RouteMatcher.Route destination, Message<?> message) {
FrameType frameType = RSocketFrameTypeMessageCondition.getFrameType(message);
if (frameType == FrameType.SETUP || frameType == FrameType.METADATA_PUSH) {
// optional handling
return;
}
if (frameType == FrameType.REQUEST_FNF) {
// Can't propagate error to client, so just log
logger.warn("No handler for fireAndForget to '" + destination + "'");
return;
}
Set<FrameType> frameTypes = getHandlerMethods().keySet().stream().map(CompositeMessageCondition::getMessageConditions).filter(conditions -> conditions.get(1).getMatchingCondition(message) != null).map(conditions -> (RSocketFrameTypeMessageCondition) conditions.get(0)).flatMap(condition -> condition.getFrameTypes().stream()).collect(Collectors.toSet());
throw new MessageDeliveryException(frameTypes.isEmpty() ? "No handler for destination '" + destination + "'" : "Destination '" + destination + "' does not support " + frameType + ". " + "Supported interaction(s): " + frameTypes);
}
Aggregations