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


Java StompHeaderAccessor.setSessionAttributes方法代码示例

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


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

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

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

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

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

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

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

示例7: 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.setSessionAttributes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。