Java Code Examples for org.springframework.messaging.simp.SimpMessageHeaderAccessor#setSubscriptionId()

The following examples show how to use org.springframework.messaging.simp.SimpMessageHeaderAccessor#setSubscriptionId() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SendToMethodReturnValueHandlerTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test  // SPR-12170
public void sendToWithDestinationPlaceholders() throws Exception {
	given(this.messageChannel.send(any(Message.class))).willReturn(true);

	Map<String, String> vars = new LinkedHashMap<>(1);
	vars.put("roomName", "roomA");

	String sessionId = "sess1";
	SimpMessageHeaderAccessor accessor = SimpMessageHeaderAccessor.create();
	accessor.setSessionId(sessionId);
	accessor.setSubscriptionId("sub1");
	accessor.setHeader(DESTINATION_TEMPLATE_VARIABLES_HEADER, vars);
	Message<?> message = MessageBuilder.createMessage(PAYLOAD, accessor.getMessageHeaders());
	this.handler.handleReturnValue(PAYLOAD, this.sendToWithPlaceholdersReturnType, message);

	verify(this.messageChannel, times(1)).send(this.messageCaptor.capture());

	SimpMessageHeaderAccessor actual = getCapturedAccessor(0);
	assertEquals(sessionId, actual.getSessionId());
	assertEquals("/topic/chat.message.filtered.roomA", actual.getDestination());
}
 
Example 2
Source File: SendToMethodReturnValueHandlerTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test  // SPR-12170
public void sendToWithDestinationPlaceholders() throws Exception {
	given(this.messageChannel.send(any(Message.class))).willReturn(true);

	Map<String, String> vars = new LinkedHashMap<>(1);
	vars.put("roomName", "roomA");

	String sessionId = "sess1";
	SimpMessageHeaderAccessor accessor = SimpMessageHeaderAccessor.create();
	accessor.setSessionId(sessionId);
	accessor.setSubscriptionId("sub1");
	accessor.setHeader(DestinationVariableMethodArgumentResolver.DESTINATION_TEMPLATE_VARIABLES_HEADER, vars);
	Message<?> message = MessageBuilder.createMessage(PAYLOAD, accessor.getMessageHeaders());
	this.handler.handleReturnValue(PAYLOAD, this.sendToWithPlaceholdersReturnType, message);

	verify(this.messageChannel, times(1)).send(this.messageCaptor.capture());

	SimpMessageHeaderAccessor actual = getCapturedAccessor(0);
	assertEquals(sessionId, actual.getSessionId());
	assertEquals("/topic/chat.message.filtered.roomA", actual.getDestination());
}
 
Example 3
Source File: SendToMethodReturnValueHandlerTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
private Message<?> createMessage(String sessId, String subsId, String destPrefix, String dest, Principal user) {
	SimpMessageHeaderAccessor headerAccessor = SimpMessageHeaderAccessor.create();
	headerAccessor.setSessionId(sessId);
	headerAccessor.setSubscriptionId(subsId);
	if (dest != null && destPrefix != null) {
		headerAccessor.setDestination(destPrefix + dest);
		headerAccessor.setHeader(DestinationPatternsMessageCondition.LOOKUP_DESTINATION_HEADER, dest);
	}
	if (user != null) {
		headerAccessor.setUser(user);
	}
	return MessageBuilder.createMessage(new byte[0], headerAccessor.getMessageHeaders());
}
 
Example 4
Source File: SendToMethodReturnValueHandlerTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
private Message<?> createInputMessage(String sessId, String subsId, String destinationPrefix,
           String destination, Principal principal) {

	SimpMessageHeaderAccessor headerAccessor = SimpMessageHeaderAccessor.create();
	headerAccessor.setSessionId(sessId);
	headerAccessor.setSubscriptionId(subsId);
	if (destination != null && destinationPrefix != null) {
		headerAccessor.setDestination(destinationPrefix + destination);
		headerAccessor.setHeader(DestinationPatternsMessageCondition.LOOKUP_DESTINATION_HEADER, destination);
	}
	if (principal != null) {
		headerAccessor.setUser(principal);
	}
	return MessageBuilder.createMessage(new byte[0], headerAccessor.getMessageHeaders());
}
 
Example 5
Source File: SimpleBrokerMessageHandlerTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
private Message<String> createSubscriptionMessage(String sessionId, String subcriptionId, String destination) {
	SimpMessageHeaderAccessor headers = SimpMessageHeaderAccessor.create(SimpMessageType.SUBSCRIBE);
	headers.setSubscriptionId(subcriptionId);
	headers.setDestination(destination);
	headers.setSessionId(sessionId);
	return MessageBuilder.createMessage("", headers.getMessageHeaders());
}
 
Example 6
Source File: SubscriptionMethodReturnValueHandler.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
private MessageHeaders createHeaders(String sessionId, String subscriptionId, MethodParameter returnType) {
	SimpMessageHeaderAccessor headerAccessor = SimpMessageHeaderAccessor.create(SimpMessageType.MESSAGE);
	if (getHeaderInitializer() != null) {
		getHeaderInitializer().initHeaders(headerAccessor);
	}
	headerAccessor.setSessionId(sessionId);
	headerAccessor.setSubscriptionId(subscriptionId);
	headerAccessor.setHeader(SimpMessagingTemplate.CONVERSION_HINT_HEADER, returnType);
	headerAccessor.setLeaveMutable(true);
	return headerAccessor.getMessageHeaders();
}
 
Example 7
Source File: DefaultSimpUserRegistryTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
private Message<byte[]> createMessage(SimpMessageType type, String sessionId, String subscriptionId,
		String destination) {

	SimpMessageHeaderAccessor accessor = SimpMessageHeaderAccessor.create(type);
	accessor.setSessionId(sessionId);
	if (destination != null) {
		accessor.setDestination(destination);
	}
	if (subscriptionId != null) {
		accessor.setSubscriptionId(subscriptionId);
	}
	return MessageBuilder.createMessage(new byte[0], accessor.getMessageHeaders());
}
 
Example 8
Source File: SimpleBrokerMessageHandlerTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
private Message<String> createSubscriptionMessage(String sessionId, String subscriptionId, String destination) {
	SimpMessageHeaderAccessor headers = SimpMessageHeaderAccessor.create(SimpMessageType.SUBSCRIBE);
	headers.setSubscriptionId(subscriptionId);
	headers.setDestination(destination);
	headers.setSessionId(sessionId);
	return MessageBuilder.createMessage("", headers.getMessageHeaders());
}
 
Example 9
Source File: DefaultSubscriptionRegistryTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
private Message<?> subscribeMessage(String sessionId, String subscriptionId, String dest, String selector) {
	SimpMessageHeaderAccessor accessor = SimpMessageHeaderAccessor.create(SimpMessageType.SUBSCRIBE);
	accessor.setSessionId(sessionId);
	accessor.setSubscriptionId(subscriptionId);
	if (dest != null) {
		accessor.setDestination(dest);
	}
	if (selector != null) {
		accessor.setNativeHeader("selector", selector);
	}
	return MessageBuilder.createMessage("", accessor.getMessageHeaders());
}
 
Example 10
Source File: SubscriptionMethodReturnValueHandlerTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
private Message<?> createInputMessage(String sessId, String subsId, String dest, Principal principal) {
	SimpMessageHeaderAccessor headers = SimpMessageHeaderAccessor.create();
	headers.setSessionId(sessId);
	headers.setSubscriptionId(subsId);
	headers.setDestination(dest);
	headers.setUser(principal);
	return MessageBuilder.withPayload(new byte[0]).copyHeaders(headers.toMap()).build();
}
 
Example 11
Source File: SubscriptionMethodReturnValueHandler.java    From spring-analysis-note with MIT License 5 votes vote down vote up
private MessageHeaders createHeaders(@Nullable String sessionId, String subscriptionId, MethodParameter returnType) {
	SimpMessageHeaderAccessor accessor = SimpMessageHeaderAccessor.create(SimpMessageType.MESSAGE);
	if (getHeaderInitializer() != null) {
		getHeaderInitializer().initHeaders(accessor);
	}
	if (sessionId != null) {
		accessor.setSessionId(sessionId);
	}
	accessor.setSubscriptionId(subscriptionId);
	accessor.setHeader(SimpMessagingTemplate.CONVERSION_HINT_HEADER, returnType);
	accessor.setLeaveMutable(true);
	return accessor.getMessageHeaders();
}
 
Example 12
Source File: SubscriptionMethodReturnValueHandler.java    From java-technology-stack with MIT License 5 votes vote down vote up
private MessageHeaders createHeaders(@Nullable String sessionId, String subscriptionId, MethodParameter returnType) {
	SimpMessageHeaderAccessor accessor = SimpMessageHeaderAccessor.create(SimpMessageType.MESSAGE);
	if (getHeaderInitializer() != null) {
		getHeaderInitializer().initHeaders(accessor);
	}
	if (sessionId != null) {
		accessor.setSessionId(sessionId);
	}
	accessor.setSubscriptionId(subscriptionId);
	accessor.setHeader(SimpMessagingTemplate.CONVERSION_HINT_HEADER, returnType);
	accessor.setLeaveMutable(true);
	return accessor.getMessageHeaders();
}
 
Example 13
Source File: SimpleBrokerMessageHandlerTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
private Message<String> createSubscriptionMessage(String sessionId, String subscriptionId, String destination) {
	SimpMessageHeaderAccessor headers = SimpMessageHeaderAccessor.create(SimpMessageType.SUBSCRIBE);
	headers.setSubscriptionId(subscriptionId);
	headers.setDestination(destination);
	headers.setSessionId(sessionId);
	return MessageBuilder.createMessage("", headers.getMessageHeaders());
}
 
Example 14
Source File: DefaultSubscriptionRegistryTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
private Message<?> subscribeMessage(String sessionId, String subscriptionId, String dest, String selector) {
	SimpMessageHeaderAccessor accessor = SimpMessageHeaderAccessor.create(SimpMessageType.SUBSCRIBE);
	accessor.setSessionId(sessionId);
	accessor.setSubscriptionId(subscriptionId);
	if (dest != null) {
		accessor.setDestination(dest);
	}
	if (selector != null) {
		accessor.setNativeHeader("selector", selector);
	}
	return MessageBuilder.createMessage("", accessor.getMessageHeaders());
}
 
Example 15
Source File: SubscriptionMethodReturnValueHandlerTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
private Message<?> createInputMessage(String sessId, String subsId, String dest, Principal principal) {
	SimpMessageHeaderAccessor headers = SimpMessageHeaderAccessor.create();
	headers.setSessionId(sessId);
	headers.setSubscriptionId(subsId);
	headers.setDestination(dest);
	headers.setUser(principal);
	return MessageBuilder.withPayload(new byte[0]).copyHeaders(headers.toMap()).build();
}
 
Example 16
Source File: SendToMethodReturnValueHandlerTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
private Message<?> createMessage(String sessId, String subsId, String destPrefix, String dest, Principal user) {
	SimpMessageHeaderAccessor headerAccessor = SimpMessageHeaderAccessor.create();
	headerAccessor.setSessionId(sessId);
	headerAccessor.setSubscriptionId(subsId);
	if (dest != null && destPrefix != null) {
		headerAccessor.setDestination(destPrefix + dest);
		headerAccessor.setHeader(DestinationPatternsMessageCondition.LOOKUP_DESTINATION_HEADER, dest);
	}
	if (user != null) {
		headerAccessor.setUser(user);
	}
	return MessageBuilder.createMessage(new byte[0], headerAccessor.getMessageHeaders());
}
 
Example 17
Source File: SubscriptionMethodReturnValueHandlerTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
private Message<?> createInputMessage(String sessId, String subsId, String dest, Principal principal) {
	SimpMessageHeaderAccessor headers = SimpMessageHeaderAccessor.create();
	headers.setSessionId(sessId);
	headers.setSubscriptionId(subsId);
	headers.setDestination(dest);
	headers.setUser(principal);
	return MessageBuilder.withPayload(new byte[0]).copyHeaders(headers.toMap()).build();
}
 
Example 18
Source File: DefaultSubscriptionRegistryTests.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
private Message<?> unsubscribeMessage(String sessionId, String subscriptionId) {
	SimpMessageHeaderAccessor accessor = SimpMessageHeaderAccessor.create(SimpMessageType.UNSUBSCRIBE);
	accessor.setSessionId(sessionId);
	accessor.setSubscriptionId(subscriptionId);
	return MessageBuilder.createMessage("", accessor.getMessageHeaders());
}
 
Example 19
Source File: DefaultSubscriptionRegistryTests.java    From java-technology-stack with MIT License 4 votes vote down vote up
private Message<?> unsubscribeMessage(String sessionId, String subscriptionId) {
	SimpMessageHeaderAccessor accessor = SimpMessageHeaderAccessor.create(SimpMessageType.UNSUBSCRIBE);
	accessor.setSessionId(sessionId);
	accessor.setSubscriptionId(subscriptionId);
	return MessageBuilder.createMessage("", accessor.getMessageHeaders());
}
 
Example 20
Source File: DefaultSubscriptionRegistryTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
private Message<?> unsubscribeMessage(String sessionId, String subscriptionId) {
	SimpMessageHeaderAccessor accessor = SimpMessageHeaderAccessor.create(SimpMessageType.UNSUBSCRIBE);
	accessor.setSessionId(sessionId);
	accessor.setSubscriptionId(subscriptionId);
	return MessageBuilder.createMessage("", accessor.getMessageHeaders());
}