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


Java StompHeaderAccessor.setSessionId方法代码示例

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


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

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

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

示例7: createDisconnectMessage

import org.springframework.messaging.simp.stomp.StompHeaderAccessor; //导入方法依赖的package包/类
private Message<byte[]> createDisconnectMessage(WebSocketSession session) {
	StompHeaderAccessor headerAccessor = StompHeaderAccessor.create(StompCommand.DISCONNECT);
	if (getHeaderInitializer() != null) {
		getHeaderInitializer().initHeaders(headerAccessor);
	}
	headerAccessor.setSessionId(session.getId());
	headerAccessor.setSessionAttributes(session.getAttributes());
	headerAccessor.setUser(session.getPrincipal());
	return MessageBuilder.createMessage(EMPTY_PAYLOAD, headerAccessor.getMessageHeaders());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:11,代码来源:StompSubProtocolHandler.java

示例8: createHeaders

import org.springframework.messaging.simp.stomp.StompHeaderAccessor; //导入方法依赖的package包/类
public static StompHeaderAccessor createHeaders(String sessionId, String subscriptionId) {
    StompHeaderAccessor mha = StompHeaderAccessor.create(StompCommand.MESSAGE);
    mha.setLeaveMutable(true);
    mha.setMessageTypeIfNotSet(SimpMessageType.MESSAGE);
    mha.setSubscriptionId(subscriptionId);
    mha.setSessionId(sessionId);
    mha.setContentType(MimeTypeUtils.APPLICATION_JSON);
    return mha;
}
 
开发者ID:codeabovelab,项目名称:haven-platform,代码行数:10,代码来源:Stomp.java

示例9: 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");
}
 
开发者ID:Appverse,项目名称:appverse-server,代码行数:29,代码来源:WebsocketTest.java

示例10: 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);
}
 
开发者ID:Appverse,项目名称:appverse-server,代码行数:31,代码来源:WebsocketTest.java

示例11: createMessage

import org.springframework.messaging.simp.stomp.StompHeaderAccessor; //导入方法依赖的package包/类
private Message<byte[]> createMessage(String type, String destination, String data, UUID userId) throws Exception {
    byte[] payload = null;
    if(data != null) {
        //Create a MapMessage object for message payload
        MapMessage mapMessage = new MapMessage();
        mapMessage.setType(type);
        mapMessage.setData(data);
        payload = new ObjectMapper().writeValueAsBytes(mapMessage);
    } else {
        //Create an BeanMessage object for message payload
        BeanMessage beanMessage = new BeanMessage();
        beanMessage.setType(type);
        payload = new ObjectMapper().writeValueAsBytes(beanMessage);
    }

    //Create headers
    StompHeaderAccessor headers = StompHeaderAccessor.create(StompCommand.SEND);
    headers.setDestination(destination);
    headers.setSessionId("0");
    headers.setSessionAttributes(new HashMap<String, Object>());

    //Generate a user
    headers.setUser(new TestPrincipal(userId == null ? this.uuid : userId.toString()));

    //Build the message (with a payload and headers)
    Message<byte[]> message = MessageBuilder.withPayload(payload).setHeaders(headers).build();
    return message;
}
 
开发者ID:wieden-kennedy,项目名称:composite-framework,代码行数:29,代码来源:ContextCompositeTests.java

示例12: sendToSession

import org.springframework.messaging.simp.stomp.StompHeaderAccessor; //导入方法依赖的package包/类
public void sendToSession(String dest, Object msg) {
    StompHeaderAccessor sha = StompHeaderAccessor.create(StompCommand.MESSAGE);
    sha.setLeaveMutable(true);
    sha.setSessionId(sessionId);
    this.template.convertAndSendToUser(sessionId, "/queue/" + dest, msg, sha.getMessageHeaders());
}
 
开发者ID:codeabovelab,项目名称:haven-platform,代码行数:7,代码来源:Stomp.java

示例13: createMatchMessage

import org.springframework.messaging.simp.stomp.StompHeaderAccessor; //导入方法依赖的package包/类
private Message<byte[]> createMatchMessage(String type, String destination, String appId, UUID userId) throws Exception {

        //Create a device
        Device device = new Device(userId == null ? this.uuid : userId.toString());
        device.setHeight(400);
        device.setWidth(400);

        byte[] payload = null;
        switch(type) {
            case "join":
                //Create a JoinMessage object for message payload
                JoinMessage joinMessage = new JoinMessage();
                joinMessage.setDevice(device);
                joinMessage.setGeo(new float[]{0, 0});
                joinMessage.setType(JoinMessage.Types.exit);
                joinMessage.setApplicationId(appId);
                payload = new ObjectMapper().writeValueAsBytes(joinMessage);
                break;
            case "pair":
                //Create a PairMessage object for message payload
                PairMessage pairMessage= new PairMessage();
                pairMessage.setDevice(device);
                pairMessage.setGeo(new float[]{0, 0});
                pairMessage.setType(PairMessage.Types.exit);
                pairMessage.setApplicationId(appId);
                payload = new ObjectMapper().writeValueAsBytes(pairMessage);
                break;
            default:
                return null;
        }

        //Create headers
        StompHeaderAccessor headers = StompHeaderAccessor.create(StompCommand.SEND);
        headers.setDestination(destination);
        headers.setSessionId("0");
        headers.setSessionAttributes(new HashMap<String, Object>());

        //Generate a user
        headers.setUser(new TestPrincipal(userId == null ? this.uuid : userId.toString()));

        //Build the message (with a payload and headers)
        Message<byte[]> message = MessageBuilder.withPayload(payload).setHeaders(headers).build();
        return message;
    }
 
开发者ID:wieden-kennedy,项目名称:composite-framework,代码行数:45,代码来源:ContextCompositeTests.java


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