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


Java StompHeaderAccessor.setNativeHeader方法代码示例

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


在下文中一共展示了StompHeaderAccessor.setNativeHeader方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: afterStompSessionConnected

import org.springframework.messaging.simp.stomp.StompHeaderAccessor; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
private StompHeaderAccessor afterStompSessionConnected(Message<?> message, StompHeaderAccessor accessor,
		WebSocketSession session) {

	Principal principal = session.getPrincipal();
	if (principal != null) {
		accessor = toMutableAccessor(accessor, message);
		accessor.setNativeHeader(CONNECTED_USER_HEADER, principal.getName());
		if (this.userSessionRegistry != null) {
			String userName = getSessionRegistryUserName(principal);
			this.userSessionRegistry.registerSessionId(userName, session.getId());
		}
	}

	long[] heartbeat = accessor.getHeartbeat();
	if (heartbeat[1] > 0) {
		session = WebSocketSessionDecorator.unwrap(session);
		if (session instanceof SockJsSession) {
			((SockJsSession) session).disableHeartbeat();
		}
	}

	return accessor;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:25,代码来源:StompSubProtocolHandler.java

示例3: 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

示例4: 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


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