当前位置: 首页>>代码示例>>Java>>正文


Java StompHeaderAccessor.create方法代码示例

本文整理汇总了Java中org.springframework.messaging.simp.stomp.StompHeaderAccessor.create方法的典型用法代码示例。如果您正苦于以下问题:Java StompHeaderAccessor.create方法的具体用法?Java StompHeaderAccessor.create怎么用?Java StompHeaderAccessor.create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.messaging.simp.stomp.StompHeaderAccessor的用法示例。


在下文中一共展示了StompHeaderAccessor.create方法的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);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:17,代码来源:UserDestinationMessageHandlerTests.java

示例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()));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:22,代码来源:MessageBrokerConfigurationTests.java

示例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()));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:22,代码来源:MessageBrokerConfigurationTests.java

示例4: convertConnectAcktoStompConnected

import org.springframework.messaging.simp.stomp.StompHeaderAccessor; //导入方法依赖的package包/类
/**
 * The simple broker produces {@code SimpMessageType.CONNECT_ACK} that's not STOMP
 * specific and needs to be turned into a STOMP CONNECTED frame.
 */
private StompHeaderAccessor convertConnectAcktoStompConnected(StompHeaderAccessor connectAckHeaders) {
	String name = StompHeaderAccessor.CONNECT_MESSAGE_HEADER;
	Message<?> message = (Message<?>) connectAckHeaders.getHeader(name);
	Assert.notNull(message, "Original STOMP CONNECT not found in " + connectAckHeaders);
	StompHeaderAccessor connectHeaders = MessageHeaderAccessor.getAccessor(message, StompHeaderAccessor.class);
	StompHeaderAccessor connectedHeaders = StompHeaderAccessor.create(StompCommand.CONNECTED);
	Set<String> acceptVersions = connectHeaders.getAcceptVersion();
	if (acceptVersions.contains("1.2")) {
		connectedHeaders.setVersion("1.2");
	}
	else if (acceptVersions.contains("1.1")) {
		connectedHeaders.setVersion("1.1");
	}
	else if (!acceptVersions.isEmpty()) {
		throw new IllegalArgumentException("Unsupported STOMP version '" + acceptVersions + "'");
	}
	long[] heartbeat = (long[]) connectAckHeaders.getHeader(SimpMessageHeaderAccessor.HEART_BEAT_HEADER);
	if (heartbeat != null) {
		connectedHeaders.setHeartbeat(heartbeat[0], heartbeat[1]);
	}
	else {
		connectedHeaders.setHeartbeat(0, 0);
	}
	return connectedHeaders;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:30,代码来源:StompSubProtocolHandler.java

示例5: handleClientMessageProcessingError

import org.springframework.messaging.simp.stomp.StompHeaderAccessor; //导入方法依赖的package包/类
@Override
public Message<byte[]> handleClientMessageProcessingError(Message<byte[]> clientMessage, Throwable ex) {
	StompHeaderAccessor accessor = StompHeaderAccessor.create(StompCommand.ERROR);
	accessor.setMessage(ex.getMessage());
	accessor.setLeaveMutable(true);

	StompHeaderAccessor clientHeaderAccessor = null;
	if (clientMessage != null) {
		clientHeaderAccessor = MessageHeaderAccessor.getAccessor(clientMessage, StompHeaderAccessor.class);
		String receiptId = clientHeaderAccessor.getReceipt();
		if (receiptId != null) {
			accessor.setReceiptId(receiptId);
		}
	}

	return handleInternal(accessor, EMPTY_PAYLOAD, ex, clientHeaderAccessor);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:18,代码来源:StompSubProtocolErrorHandler.java

示例6: 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);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:20,代码来源:RestTemplateXhrTransportTests.java

示例7: 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));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:17,代码来源:WebSocketStompClientTests.java

示例8: handleMessageToClientWithSimpConnectAck

import org.springframework.messaging.simp.stomp.StompHeaderAccessor; //导入方法依赖的package包/类
@Test
public void handleMessageToClientWithSimpConnectAck() {

	StompHeaderAccessor accessor = StompHeaderAccessor.create(StompCommand.CONNECT);
	accessor.setHeartbeat(10000, 10000);
	accessor.setAcceptVersion("1.0,1.1");
	Message<?> connectMessage = MessageBuilder.createMessage(EMPTY_PAYLOAD, accessor.getMessageHeaders());

	SimpMessageHeaderAccessor ackAccessor = SimpMessageHeaderAccessor.create(SimpMessageType.CONNECT_ACK);
	ackAccessor.setHeader(SimpMessageHeaderAccessor.CONNECT_MESSAGE_HEADER, connectMessage);
	ackAccessor.setHeader(SimpMessageHeaderAccessor.HEART_BEAT_HEADER, new long[] {15000, 15000});
	Message<byte[]> ackMessage = MessageBuilder.createMessage(EMPTY_PAYLOAD, ackAccessor.getMessageHeaders());
	this.protocolHandler.handleMessageToClient(this.session, ackMessage);

	assertEquals(1, this.session.getSentMessages().size());
	TextMessage actual = (TextMessage) this.session.getSentMessages().get(0);
	assertEquals("CONNECTED\n" + "version:1.1\n" + "heart-beat:15000,15000\n" +
			"user-name:joe\n" + "\n" + "\u0000", actual.getPayload());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:20,代码来源:StompSubProtocolHandlerTests.java

示例9: handleMessageToClientWithSimpConnectAckDefaultHeartBeat

import org.springframework.messaging.simp.stomp.StompHeaderAccessor; //导入方法依赖的package包/类
@Test
public void handleMessageToClientWithSimpConnectAckDefaultHeartBeat() {

	StompHeaderAccessor accessor = StompHeaderAccessor.create(StompCommand.CONNECT);
	accessor.setHeartbeat(10000, 10000);
	accessor.setAcceptVersion("1.0,1.1");
	Message<?> connectMessage = MessageBuilder.createMessage(EMPTY_PAYLOAD, accessor.getMessageHeaders());

	SimpMessageHeaderAccessor ackAccessor = SimpMessageHeaderAccessor.create(SimpMessageType.CONNECT_ACK);
	ackAccessor.setHeader(SimpMessageHeaderAccessor.CONNECT_MESSAGE_HEADER, connectMessage);
	Message<byte[]> ackMessage = MessageBuilder.createMessage(EMPTY_PAYLOAD, ackAccessor.getMessageHeaders());
	this.protocolHandler.handleMessageToClient(this.session, ackMessage);

	assertEquals(1, this.session.getSentMessages().size());
	TextMessage actual = (TextMessage) this.session.getSentMessages().get(0);
	assertEquals("CONNECTED\n" + "version:1.1\n" + "heart-beat:0,0\n" +
			"user-name:joe\n" + "\n" + "\u0000", actual.getPayload());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:19,代码来源:StompSubProtocolHandlerTests.java

示例10: handleMessageToClientWithHeartbeatSuppressingSockJsHeartbeat

import org.springframework.messaging.simp.stomp.StompHeaderAccessor; //导入方法依赖的package包/类
@Test
public void handleMessageToClientWithHeartbeatSuppressingSockJsHeartbeat() throws IOException {

	SockJsSession sockJsSession = Mockito.mock(SockJsSession.class);
	StompHeaderAccessor accessor = StompHeaderAccessor.create(StompCommand.CONNECTED);
	accessor.setHeartbeat(0, 10);
	Message<byte[]> message = MessageBuilder.createMessage(EMPTY_PAYLOAD, accessor.getMessageHeaders());
	this.protocolHandler.handleMessageToClient(sockJsSession, message);

	verify(sockJsSession).getPrincipal();
	verify(sockJsSession).disableHeartbeat();
	verify(sockJsSession).sendMessage(any(WebSocketMessage.class));
	verifyNoMoreInteractions(sockJsSession);

	sockJsSession = Mockito.mock(SockJsSession.class);
	accessor = StompHeaderAccessor.create(StompCommand.CONNECTED);
	accessor.setHeartbeat(0, 0);
	message = MessageBuilder.createMessage(EMPTY_PAYLOAD, accessor.getMessageHeaders());
	this.protocolHandler.handleMessageToClient(sockJsSession, message);

	verify(sockJsSession).getPrincipal();
	verify(sockJsSession).sendMessage(any(WebSocketMessage.class));
	verifyNoMoreInteractions(sockJsSession);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:25,代码来源:StompSubProtocolHandlerTests.java

示例11: 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));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:17,代码来源:StompSubProtocolHandlerTests.java

示例12: sendErrorMessage

import org.springframework.messaging.simp.stomp.StompHeaderAccessor; //导入方法依赖的package包/类
private void sendErrorMessage(String message, String sessionId) {
	StompHeaderAccessor headerAccessor = StompHeaderAccessor.create(StompCommand.ERROR);
	headerAccessor.setMessage(message);
	headerAccessor.setSessionId(sessionId);
	Message<byte[]> error = MessageBuilder.createMessage(new byte[0], headerAccessor.getMessageHeaders());
	System.out.println("Error: " + message);
	this.clientOutboundChannel.send(error);
}
 
开发者ID:trvlrch,项目名称:trvlr-backend,代码行数:9,代码来源:AuthenticationInterceptor.java

示例13: 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());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:29,代码来源:UserDestinationMessageHandlerTests.java

示例14: 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());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:16,代码来源:SimpMessagingTemplateTests.java

示例15: 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()));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:30,代码来源:MessageBrokerConfigurationTests.java


注:本文中的org.springframework.messaging.simp.stomp.StompHeaderAccessor.create方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。