本文整理汇总了Java中org.springframework.messaging.simp.stomp.StompHeaderAccessor.setDestination方法的典型用法代码示例。如果您正苦于以下问题:Java StompHeaderAccessor.setDestination方法的具体用法?Java StompHeaderAccessor.setDestination怎么用?Java StompHeaderAccessor.setDestination使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.messaging.simp.stomp.StompHeaderAccessor
的用法示例。
在下文中一共展示了StompHeaderAccessor.setDestination方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleMessageFromBrokerWithoutActiveSession
import org.springframework.messaging.simp.stomp.StompHeaderAccessor; //导入方法依赖的package包/类
@Test
public void handleMessageFromBrokerWithoutActiveSession() {
this.handler.setBroadcastDestination("/topic/unresolved");
given(this.brokerChannel.send(Mockito.any(Message.class))).willReturn(true);
StompHeaderAccessor accessor = StompHeaderAccessor.create(StompCommand.MESSAGE);
accessor.setSessionId("system123");
accessor.setDestination("/topic/unresolved");
accessor.setNativeHeader(ORIGINAL_DESTINATION, "/user/joe/queue/foo");
accessor.setLeaveMutable(true);
byte[] payload = "payload".getBytes(Charset.forName("UTF-8"));
this.handler.handleMessage(MessageBuilder.createMessage(payload, accessor.getMessageHeaders()));
// No re-broadcast
verifyNoMoreInteractions(this.brokerChannel);
}
示例2: clientOutboundChannelUsedByAnnotatedMethod
import org.springframework.messaging.simp.stomp.StompHeaderAccessor; //导入方法依赖的package包/类
@Test
public void clientOutboundChannelUsedByAnnotatedMethod() {
TestChannel channel = this.simpleBrokerContext.getBean("clientOutboundChannel", TestChannel.class);
SimpAnnotationMethodMessageHandler messageHandler = this.simpleBrokerContext.getBean(SimpAnnotationMethodMessageHandler.class);
StompHeaderAccessor headers = StompHeaderAccessor.create(StompCommand.SUBSCRIBE);
headers.setSessionId("sess1");
headers.setSessionAttributes(new ConcurrentHashMap<>());
headers.setSubscriptionId("subs1");
headers.setDestination("/foo");
Message<?> message = MessageBuilder.withPayload(new byte[0]).setHeaders(headers).build();
messageHandler.handleMessage(message);
message = channel.messages.get(0);
headers = StompHeaderAccessor.wrap(message);
assertEquals(SimpMessageType.MESSAGE, headers.getMessageType());
assertEquals("/foo", headers.getDestination());
assertEquals("bar", new String((byte[]) message.getPayload()));
}
示例3: brokerChannelUsedByAnnotatedMethod
import org.springframework.messaging.simp.stomp.StompHeaderAccessor; //导入方法依赖的package包/类
@Test
public void brokerChannelUsedByAnnotatedMethod() {
TestChannel channel = this.simpleBrokerContext.getBean("brokerChannel", TestChannel.class);
SimpAnnotationMethodMessageHandler messageHandler =
this.simpleBrokerContext.getBean(SimpAnnotationMethodMessageHandler.class);
StompHeaderAccessor headers = StompHeaderAccessor.create(StompCommand.SEND);
headers.setSessionId("sess1");
headers.setSessionAttributes(new ConcurrentHashMap<>());
headers.setDestination("/foo");
Message<?> message = MessageBuilder.createMessage(new byte[0], headers.getMessageHeaders());
messageHandler.handleMessage(message);
message = channel.messages.get(0);
headers = StompHeaderAccessor.wrap(message);
assertEquals(SimpMessageType.MESSAGE, headers.getMessageType());
assertEquals("/bar", headers.getDestination());
assertEquals("bar", new String((byte[]) message.getPayload()));
}
示例4: connectReceiveAndCloseWithStompFrame
import org.springframework.messaging.simp.stomp.StompHeaderAccessor; //导入方法依赖的package包/类
@Test
public void connectReceiveAndCloseWithStompFrame() throws Exception {
StompHeaderAccessor accessor = StompHeaderAccessor.create(StompCommand.SEND);
accessor.setDestination("/destination");
MessageHeaders headers = accessor.getMessageHeaders();
Message<byte[]> message = MessageBuilder.createMessage("body".getBytes(Charset.forName("UTF-8")), headers);
byte[] bytes = new StompEncoder().encode(message);
TextMessage textMessage = new TextMessage(bytes);
SockJsFrame frame = SockJsFrame.messageFrame(new Jackson2SockJsMessageCodec(), textMessage.getPayload());
String body = "o\n" + frame.getContent() + "\n" + "c[3000,\"Go away!\"]";
ClientHttpResponse response = response(HttpStatus.OK, body);
connect(response);
verify(this.webSocketHandler).afterConnectionEstablished(any());
verify(this.webSocketHandler).handleMessage(any(), eq(textMessage));
verify(this.webSocketHandler).afterConnectionClosed(any(), eq(new CloseStatus(3000, "Go away!")));
verifyNoMoreInteractions(this.webSocketHandler);
}
示例5: handleMessageToClientWithUserDestination
import org.springframework.messaging.simp.stomp.StompHeaderAccessor; //导入方法依赖的package包/类
@Test
public void handleMessageToClientWithUserDestination() {
StompHeaderAccessor headers = StompHeaderAccessor.create(StompCommand.MESSAGE);
headers.setMessageId("mess0");
headers.setSubscriptionId("sub0");
headers.setDestination("/queue/foo-user123");
headers.setNativeHeader(StompHeaderAccessor.ORIGINAL_DESTINATION, "/user/queue/foo");
Message<byte[]> message = MessageBuilder.createMessage(EMPTY_PAYLOAD, headers.getMessageHeaders());
this.protocolHandler.handleMessageToClient(this.session, message);
assertEquals(1, this.session.getSentMessages().size());
WebSocketMessage<?> textMessage = this.session.getSentMessages().get(0);
assertTrue(((String) textMessage.getPayload()).contains("destination:/user/queue/foo\n"));
assertFalse(((String) textMessage.getPayload()).contains(SimpMessageHeaderAccessor.ORIGINAL_DESTINATION));
}
示例6: sendWebSocketBinary
import org.springframework.messaging.simp.stomp.StompHeaderAccessor; //导入方法依赖的package包/类
@Test
public void sendWebSocketBinary() throws Exception {
StompHeaderAccessor accessor = StompHeaderAccessor.create(StompCommand.SEND);
accessor.setDestination("/b");
accessor.setContentType(MimeTypeUtils.APPLICATION_OCTET_STREAM);
byte[] payload = "payload".getBytes(UTF_8);
getTcpConnection().send(MessageBuilder.createMessage(payload, accessor.getMessageHeaders()));
ArgumentCaptor<BinaryMessage> binaryMessageCaptor = ArgumentCaptor.forClass(BinaryMessage.class);
verify(this.webSocketSession).sendMessage(binaryMessageCaptor.capture());
BinaryMessage binaryMessage = binaryMessageCaptor.getValue();
assertNotNull(binaryMessage);
assertEquals("SEND\ndestination:/b\ncontent-type:application/octet-stream\ncontent-length:7\n\npayload\0",
new String(binaryMessage.getPayload().array(), UTF_8));
}
示例7: sendHistoryToNewSubscriber
import org.springframework.messaging.simp.stomp.StompHeaderAccessor; //导入方法依赖的package包/类
private void sendHistoryToNewSubscriber(AbstractSubProtocolEvent ev) {
Message<byte[]> msg = ev.getMessage();
StompHeaderAccessor ha = StompHeaderAccessor.wrap(msg);
String pattern = ha.getDestination();
if(!pattern.startsWith(PREFIX)) {
// we must send only to appropriate paths
return;
}
MessageConverter messageConverter = this.simpMessagingTemplate.getMessageConverter();
for(BusData data: buses.values()) {
String dest = getDestination(data.getId());
if(!this.pathMatcher.match(pattern, dest)) {
continue;
}
for(Object obj: data.getEvents()) {
StompHeaderAccessor mha = Stomp.createHeaders(ha.getSessionId(), ha.getSubscriptionId());
mha.setDestination(dest);
Message<?> message = messageConverter.toMessage(obj, mha.getMessageHeaders());
clientChannel.send(message);
}
}
}
示例8: handleMessageFromBrokerWithActiveSession
import org.springframework.messaging.simp.stomp.StompHeaderAccessor; //导入方法依赖的package包/类
@Test
public void handleMessageFromBrokerWithActiveSession() {
TestSimpUser simpUser = new TestSimpUser("joe");
simpUser.addSessions(new TestSimpSession("123"));
when(this.registry.getUser("joe")).thenReturn(simpUser);
this.handler.setBroadcastDestination("/topic/unresolved");
given(this.brokerChannel.send(Mockito.any(Message.class))).willReturn(true);
StompHeaderAccessor accessor = StompHeaderAccessor.create(StompCommand.MESSAGE);
accessor.setSessionId("system123");
accessor.setDestination("/topic/unresolved");
accessor.setNativeHeader(ORIGINAL_DESTINATION, "/user/joe/queue/foo");
accessor.setNativeHeader("customHeader", "customHeaderValue");
accessor.setLeaveMutable(true);
byte[] payload = "payload".getBytes(Charset.forName("UTF-8"));
this.handler.handleMessage(MessageBuilder.createMessage(payload, accessor.getMessageHeaders()));
ArgumentCaptor<Message> captor = ArgumentCaptor.forClass(Message.class);
Mockito.verify(this.brokerChannel).send(captor.capture());
assertNotNull(captor.getValue());
SimpMessageHeaderAccessor headers = SimpMessageHeaderAccessor.wrap(captor.getValue());
assertEquals("/queue/foo-user123", headers.getDestination());
assertEquals("/user/queue/foo", headers.getFirstNativeHeader(ORIGINAL_DESTINATION));
assertEquals("customHeaderValue", headers.getFirstNativeHeader("customHeader"));
assertArrayEquals(payload, (byte[]) captor.getValue().getPayload());
}
示例9: doSendWithStompHeaders
import org.springframework.messaging.simp.stomp.StompHeaderAccessor; //导入方法依赖的package包/类
@Test
public void doSendWithStompHeaders() {
StompHeaderAccessor accessor = StompHeaderAccessor.create(StompCommand.SUBSCRIBE);
accessor.setDestination("/user/queue/foo");
Message<?> message = MessageBuilder.createMessage(new byte[0], accessor.getMessageHeaders());
this.messagingTemplate.doSend("/queue/foo-user123", message);
List<Message<byte[]>> messages = this.messageChannel.getMessages();
Message<byte[]> sentMessage = messages.get(0);
MessageHeaderAccessor sentAccessor = MessageHeaderAccessor.getAccessor(sentMessage, MessageHeaderAccessor.class);
assertEquals(StompHeaderAccessor.class, sentAccessor.getClass());
assertEquals("/queue/foo-user123", ((StompHeaderAccessor) sentAccessor).getDestination());
}
示例10: clientOutboundChannelUsedBySimpleBroker
import org.springframework.messaging.simp.stomp.StompHeaderAccessor; //导入方法依赖的package包/类
@Test
public void clientOutboundChannelUsedBySimpleBroker() {
TestChannel channel = this.simpleBrokerContext.getBean("clientOutboundChannel", TestChannel.class);
SimpleBrokerMessageHandler broker = this.simpleBrokerContext.getBean(SimpleBrokerMessageHandler.class);
StompHeaderAccessor headers = StompHeaderAccessor.create(StompCommand.SUBSCRIBE);
headers.setSessionId("sess1");
headers.setSubscriptionId("subs1");
headers.setDestination("/foo");
Message<?> message = MessageBuilder.createMessage(new byte[0], headers.getMessageHeaders());
// subscribe
broker.handleMessage(message);
headers = StompHeaderAccessor.create(StompCommand.SEND);
headers.setSessionId("sess1");
headers.setDestination("/foo");
message = MessageBuilder.createMessage("bar".getBytes(), headers.getMessageHeaders());
// message
broker.handleMessage(message);
message = channel.messages.get(0);
headers = StompHeaderAccessor.wrap(message);
assertEquals(SimpMessageType.MESSAGE, headers.getMessageType());
assertEquals("/foo", headers.getDestination());
assertEquals("bar", new String((byte[]) message.getPayload()));
}
示例11: handleMessageToClientWithBinaryWebSocketMessage
import org.springframework.messaging.simp.stomp.StompHeaderAccessor; //导入方法依赖的package包/类
@Test
public void handleMessageToClientWithBinaryWebSocketMessage() {
StompHeaderAccessor headers = StompHeaderAccessor.create(StompCommand.MESSAGE);
headers.setMessageId("mess0");
headers.setSubscriptionId("sub0");
headers.setContentType(MimeTypeUtils.APPLICATION_OCTET_STREAM);
headers.setDestination("/queue/foo");
// Non-empty payload
byte[] payload = new byte[1];
Message<byte[]> message = MessageBuilder.createMessage(payload, headers.getMessageHeaders());
this.protocolHandler.handleMessageToClient(this.session, message);
assertEquals(1, this.session.getSentMessages().size());
WebSocketMessage<?> webSocketMessage = this.session.getSentMessages().get(0);
assertTrue(webSocketMessage instanceof BinaryMessage);
// Empty payload
payload = EMPTY_PAYLOAD;
message = MessageBuilder.createMessage(payload, headers.getMessageHeaders());
this.protocolHandler.handleMessageToClient(this.session, message);
assertEquals(2, this.session.getSentMessages().size());
webSocketMessage = this.session.getSentMessages().get(1);
assertTrue(webSocketMessage instanceof TextMessage);
}
示例12: sendWebSocketMessage
import org.springframework.messaging.simp.stomp.StompHeaderAccessor; //导入方法依赖的package包/类
@Test
public void sendWebSocketMessage() throws Exception {
StompHeaderAccessor accessor = StompHeaderAccessor.create(StompCommand.SEND);
accessor.setDestination("/topic/foo");
byte[] payload = "payload".getBytes(UTF_8);
getTcpConnection().send(MessageBuilder.createMessage(payload, accessor.getMessageHeaders()));
ArgumentCaptor<TextMessage> textMessageCaptor = ArgumentCaptor.forClass(TextMessage.class);
verify(this.webSocketSession).sendMessage(textMessageCaptor.capture());
TextMessage textMessage = textMessageCaptor.getValue();
assertNotNull(textMessage);
assertEquals("SEND\ndestination:/topic/foo\ncontent-length:7\n\npayload\0", textMessage.getPayload());
}
示例13: sendToSubscription
import org.springframework.messaging.simp.stomp.StompHeaderAccessor; //导入方法依赖的package包/类
/**
* Send message to queue of current session
* @param subscriptionId
* @param dest
* @param msg
*/
public void sendToSubscription(String subscriptionId, String dest, Object msg) {
Assert.notNull(subscriptionId, "subscriptionId is null");
StompHeaderAccessor sha = createHeaders(sessionId, subscriptionId);
MessageConverter messageConverter = this.template.getMessageConverter();
sha.setDestination("/queue/" + dest);
Message<?> message = messageConverter.toMessage(msg, sha.getMessageHeaders());
clientChannel.send(message);
}
示例14: getPositions
import org.springframework.messaging.simp.stomp.StompHeaderAccessor; //导入方法依赖的package包/类
@Test
public void getPositions() throws Exception {
StompHeaderAccessor headers = StompHeaderAccessor.create(StompCommand.SUBSCRIBE);
headers.setSubscriptionId("0");
headers.setDestination("/app/positions");
headers.setSessionId("0");
headers.setUser(new TestPrincipal("fabrice"));
headers.setSessionAttributes(new HashMap<String, Object>());
Message<byte[]> message = MessageBuilder.createMessage(new byte[0], headers.getMessageHeaders());
this.clientOutboundChannelInterceptor.setIncludedDestinations("/app/positions");
this.clientInboundChannel.send(message);
Message<?> reply = this.clientOutboundChannelInterceptor.awaitMessage(5);
assertNotNull(reply);
StompHeaderAccessor replyHeaders = StompHeaderAccessor.wrap(reply);
assertEquals("0", replyHeaders.getSessionId());
assertEquals("0", replyHeaders.getSubscriptionId());
assertEquals("/app/positions", replyHeaders.getDestination());
String json = new String((byte[]) reply.getPayload(), Charset.forName("UTF-8"));
new JsonPathExpectationsHelper("$[0].company").assertValue(json, "Citrix Systems, Inc.");
new JsonPathExpectationsHelper("$[1].company").assertValue(json, "Dell Inc.");
new JsonPathExpectationsHelper("$[2].company").assertValue(json, "Microsoft");
new JsonPathExpectationsHelper("$[3].company").assertValue(json, "Oracle");
}
示例15: executeTrade
import org.springframework.messaging.simp.stomp.StompHeaderAccessor; //导入方法依赖的package包/类
@Test
public void executeTrade() throws Exception {
Trade trade = new Trade();
trade.setAction(Trade.TradeAction.Buy);
trade.setTicker("DELL");
trade.setShares(25);
byte[] payload = new ObjectMapper().writeValueAsBytes(trade);
StompHeaderAccessor headers = StompHeaderAccessor.create(StompCommand.SEND);
headers.setDestination("/app/trade");
headers.setSessionId("0");
headers.setUser(new TestPrincipal("fabrice"));
headers.setSessionAttributes(new HashMap<String, Object>());
Message<byte[]> message = MessageBuilder.createMessage(payload, headers.getMessageHeaders());
this.brokerChannelInterceptor.setIncludedDestinations("/user/**");
this.clientInboundChannel.send(message);
Message<?> positionUpdate = this.brokerChannelInterceptor.awaitMessage(5);
assertNotNull(positionUpdate);
StompHeaderAccessor positionUpdateHeaders = StompHeaderAccessor.wrap(positionUpdate);
assertEquals("/user/fabrice/queue/position-updates", positionUpdateHeaders.getDestination());
String json = new String((byte[]) positionUpdate.getPayload(), Charset.forName("UTF-8"));
new JsonPathExpectationsHelper("$.ticker").assertValue(json, "DELL");
new JsonPathExpectationsHelper("$.shares").assertValue(json, 75);
}