@SendToUser({"/dest1", "/dest2"}) @SuppressWarnings("unused") String handleAndSendToUser() { return PAYLOAD; }
@SubscribeMapping("/number") public int number() { return 42; } }
@SubscribeMapping("/jsonview") // not needed for the tests but here for completeness @JsonView(MyJacksonView1.class) public JacksonViewBean getJsonView() { JacksonViewBean payload = new JacksonViewBean(); payload.setWithView1("with"); payload.setWithView2("with"); payload.setWithoutView("without"); return payload; }
DestinationHelper destinationHelper = getDestinationHelper(headers, returnType); SendToUser sendToUser = destinationHelper.getSendToUser(); if (sendToUser != null) { boolean broadcast = sendToUser.broadcast(); String user = getUserName(message, headers); if (user == null) { if (sessionId == null) { throw new MissingSessionUserException(message); String[] destinations = getTargetDestinations(sendToUser, message, this.defaultUserDestinationPrefix); for (String destination : destinations) { destination = destinationHelper.expandTemplateVars(destination); if (broadcast) { this.messagingTemplate.convertAndSendToUser( user, destination, returnValue, createHeaders(null, returnType)); user, destination, returnValue, createHeaders(sessionId, returnType)); SendTo sendTo = destinationHelper.getSendTo(); if (sendTo != null || sendToUser == null) { String[] destinations = getTargetDestinations(sendTo, message, this.defaultDestinationPrefix); for (String destination : destinations) { destination = destinationHelper.expandTemplateVars(destination); this.messagingTemplate.convertAndSend(destination, returnValue, createHeaders(sessionId, returnType));
SimpMessageMappingInfo result = createMessageMappingCondition(messageAnn.value()); if (typeAnn != null) { result = createMessageMappingCondition(typeAnn.value()).combine(result); if (subscribeAnn.value().length > 0 || (typeAnn != null && typeAnn.value().length > 0)) { SimpMessageMappingInfo result = createSubscribeMappingCondition(subscribeAnn.value()); if (typeAnn != null) { result = createMessageMappingCondition(typeAnn.value()).combine(result);
private DestinationHelper getDestinationHelper(MessageHeaders headers, MethodParameter returnType) { SendToUser m1 = AnnotatedElementUtils.findMergedAnnotation(returnType.getExecutable(), SendToUser.class); SendTo m2 = AnnotatedElementUtils.findMergedAnnotation(returnType.getExecutable(), SendTo.class); if ((m1 != null && !ObjectUtils.isEmpty(m1.value())) || (m2 != null && !ObjectUtils.isEmpty(m2.value()))) { return new DestinationHelper(headers, m1, m2); } SendToUser c1 = AnnotatedElementUtils.findMergedAnnotation(returnType.getDeclaringClass(), SendToUser.class); SendTo c2 = AnnotatedElementUtils.findMergedAnnotation(returnType.getDeclaringClass(), SendTo.class); if ((c1 != null && !ObjectUtils.isEmpty(c1.value())) || (c2 != null && !ObjectUtils.isEmpty(c2.value()))) { return new DestinationHelper(headers, c1, c2); } return (m1 != null || m2 != null ? new DestinationHelper(headers, m1, m2) : new DestinationHelper(headers, c1, c2)); }
@SendToUser(destinations = { "/dest1", "/dest2" }, broadcast = false) @SuppressWarnings("unused") String handleAndSendToUserInSession() { return PAYLOAD; }
@SubscribeMapping("/foo") public String handleSubscribe() { return "bar"; }
@SendToUser @SuppressWarnings("unused") String handleAndSendToUserDefaultDest() { return PAYLOAD; }
@SubscribeMapping("/foo") public String handleSubscribe() { return "bar"; }
@SendToUser(broadcast = false) @SuppressWarnings("unused") String handleAndSendToUserDefaultDestInSession() { return PAYLOAD; }
@SubscribeMapping("/data") // not needed for the tests but here for completeness private String getData() { return PAYLOAD; }
@SendToUser String handleAndSendToDefaultDest() { return PAYLOAD; }
@SubscribeMapping("/data") // not needed for the tests but here for completeness @SendTo("/sendToDest") private String getDataAndSendTo() { return PAYLOAD; }
@SendTo({"/dest1", "/dest2"}) @SendToUser({"/dest1", "/dest2"}) @SuppressWarnings("unused") String handleAndSendToAndSendToUser() { return PAYLOAD; }
@SubscribeMapping("/sub/{foo}/{name}") public void subscribeEventDestinationVariable(@DestinationVariable("foo") String param1, @DestinationVariable("name") String param2) { this.method = "subscribeEventDestinationVariable"; this.arguments.put("foo", param1); this.arguments.put("name", param2); }
@MessageExceptionHandler @SendToUser("/queue/error") public String handleException(IllegalArgumentException ex) { return "Got error: " + ex.getMessage(); } }
@SubscribeMapping("/number") public int number() { return 42; }
@SendToUser @Retention(RetentionPolicy.RUNTIME) @interface MySendToUser {
@MessageExceptionHandler @SendToUser("/queue/error") public String handleException(IllegalArgumentException ex) { return "Got error: " + ex.getMessage(); }