• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java MessageHeaderAccessor类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.springframework.messaging.support.MessageHeaderAccessor的典型用法代码示例。如果您正苦于以下问题:Java MessageHeaderAccessor类的具体用法?Java MessageHeaderAccessor怎么用?Java MessageHeaderAccessor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



MessageHeaderAccessor类属于org.springframework.messaging.support包,在下文中一共展示了MessageHeaderAccessor类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: preSend

import org.springframework.messaging.support.MessageHeaderAccessor; //导入依赖的package包/类
@Override
public Message<?> preSend(final Message<?> message, final MessageChannel channel) throws AuthenticationException {
    final StompHeaderAccessor accessor = MessageHeaderAccessor.getAccessor(message, StompHeaderAccessor.class);

    if (StompCommand.CONNECT == accessor.getCommand()) {
        final String username = accessor.getFirstNativeHeader(USERNAME_HEADER);
        final String authToken = accessor.getFirstNativeHeader(TOKEN_HEADER);

        final Authentication user = webSocketAuthenticatorService.getAuthenticatedOrFail(username, authToken);

        accessor.setUser(user);
    }

    return message;
}
 
开发者ID:anthonyraymond,项目名称:joal,代码行数:16,代码来源:AuthChannelInterceptorAdapter.java


示例2: handleMatch

import org.springframework.messaging.support.MessageHeaderAccessor; //导入依赖的package包/类
@Override
protected void handleMatch(SimpMessageMappingInfo mapping, HandlerMethod handlerMethod,
		String lookupDestination, Message<?> message) {

	Set<String> patterns = mapping.getDestinationConditions().getPatterns();
	if (!CollectionUtils.isEmpty(patterns)) {
		String pattern = patterns.iterator().next();
		Map<String, String> vars = getPathMatcher().extractUriTemplateVariables(pattern, lookupDestination);
		if (!CollectionUtils.isEmpty(vars)) {
			MessageHeaderAccessor mha = MessageHeaderAccessor.getAccessor(message, MessageHeaderAccessor.class);
			Assert.state(mha != null && mha.isMutable());
			mha.setHeader(DestinationVariableMethodArgumentResolver.DESTINATION_TEMPLATE_VARIABLES_HEADER, vars);
		}
	}

	try {
		SimpAttributesContextHolder.setAttributesFromMessage(message);
		super.handleMatch(mapping, handlerMethod, lookupDestination, message);
	}
	finally {
		SimpAttributesContextHolder.resetAttributes();
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:24,代码来源:SimpAnnotationMethodMessageHandler.java


示例3: handleMessage

import org.springframework.messaging.support.MessageHeaderAccessor; //导入依赖的package包/类
@Override
public void handleMessage(Message<byte[]> message) {
	StompHeaderAccessor accessor = MessageHeaderAccessor.getAccessor(message, StompHeaderAccessor.class);
	accessor.setSessionId(this.sessionId);
	accessor.setUser(this.connectHeaders.getUser());

	StompCommand command = accessor.getCommand();
	if (StompCommand.CONNECTED.equals(command)) {
		if (logger.isDebugEnabled()) {
			logger.debug("Received " + accessor.getShortLogMessage(EMPTY_PAYLOAD));
		}
		afterStompConnected(accessor);
	}
	else if (logger.isErrorEnabled() && StompCommand.ERROR.equals(command)) {
		logger.error("Received " + accessor.getShortLogMessage(message.getPayload()));
	}
	else if (logger.isTraceEnabled()) {
		logger.trace("Received " + accessor.getDetailedLogMessage(message.getPayload()));
	}

	handleInboundMessage(message);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:23,代码来源:StompBrokerRelayMessageHandler.java


示例4: read

import org.springframework.messaging.support.MessageHeaderAccessor; //导入依赖的package包/类
@Override
public TypedValue read(EvaluationContext context, Object target, String name) throws AccessException {
	MessageHeaders headers = (MessageHeaders) target;
	SimpMessageHeaderAccessor accessor =
			MessageHeaderAccessor.getAccessor(headers, SimpMessageHeaderAccessor.class);
	Object value;
	if ("destination".equalsIgnoreCase(name)) {
		value = accessor.getDestination();
	}
	else {
		value = accessor.getFirstNativeHeader(name);
		if (value == null) {
			value = headers.get(name);
		}
	}
	return new TypedValue(value);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:18,代码来源:DefaultSubscriptionRegistry.java


示例5: handleMessage

import org.springframework.messaging.support.MessageHeaderAccessor; //导入依赖的package包/类
@Override
public void handleMessage(Message<?> message) throws MessagingException {
	String destination = getDestination(message);
	if (destination == null) {
		return;
	}
	String lookupDestination = getLookupDestination(destination);
	if (lookupDestination == null) {
		return;
	}
	MessageHeaderAccessor headerAccessor = MessageHeaderAccessor.getMutableAccessor(message);
	headerAccessor.setHeader(DestinationPatternsMessageCondition.LOOKUP_DESTINATION_HEADER, lookupDestination);
	headerAccessor.setLeaveMutable(true);
	message = MessageBuilder.createMessage(message.getPayload(), headerAccessor.getMessageHeaders());

	if (logger.isDebugEnabled()) {
		logger.debug("Searching methods to handle " + headerAccessor.getShortLogMessage(message.getPayload()));
	}

	handleMessageInternal(message, lookupDestination);
	headerAccessor.setImmutable();
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:23,代码来源:AbstractMethodMessageHandler.java


示例6: doSend

import org.springframework.messaging.support.MessageHeaderAccessor; //导入依赖的package包/类
@Override
protected final void doSend(MessageChannel channel, Message<?> message) {
	Assert.notNull(channel, "'channel' is required");

	MessageHeaderAccessor accessor = MessageHeaderAccessor.getAccessor(message, MessageHeaderAccessor.class);
	if (accessor != null && accessor.isMutable()) {
		accessor.setImmutable();
	}

	long timeout = this.sendTimeout;
	boolean sent = (timeout >= 0 ? channel.send(message, timeout) : channel.send(message));

	if (!sent) {
		throw new MessageDeliveryException(message,
				"failed to send message to channel '" + channel + "' within timeout: " + timeout);
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:18,代码来源:GenericMessagingTemplate.java


示例7: testHeadersPassedToMessagingTemplate

import org.springframework.messaging.support.MessageHeaderAccessor; //导入依赖的package包/类
@Test
@SuppressWarnings({ "unchecked", "rawtypes" })
public void testHeadersPassedToMessagingTemplate() throws Exception {
	String sessionId = "sess1";
	String subscriptionId = "subs1";
	String destination = "/dest";
	Message<?> inputMessage = createInputMessage(sessionId, subscriptionId, destination, null);

	MessageSendingOperations messagingTemplate = Mockito.mock(MessageSendingOperations.class);
	SubscriptionMethodReturnValueHandler handler = new SubscriptionMethodReturnValueHandler(messagingTemplate);

	handler.handleReturnValue(PAYLOAD, this.subscribeEventReturnType, inputMessage);

	ArgumentCaptor<MessageHeaders> captor = ArgumentCaptor.forClass(MessageHeaders.class);
	verify(messagingTemplate).convertAndSend(eq("/dest"), eq(PAYLOAD), captor.capture());

	SimpMessageHeaderAccessor headerAccessor =
			MessageHeaderAccessor.getAccessor(captor.getValue(), SimpMessageHeaderAccessor.class);

	assertNotNull(headerAccessor);
	assertTrue(headerAccessor.isMutable());
	assertEquals(sessionId, headerAccessor.getSessionId());
	assertEquals(subscriptionId, headerAccessor.getSubscriptionId());
	assertEquals(this.subscribeEventReturnType, headerAccessor.getHeader(SimpMessagingTemplate.CONVERSION_HINT_HEADER));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:26,代码来源:SubscriptionMethodReturnValueHandlerTests.java


示例8: afterConnected

import org.springframework.messaging.support.MessageHeaderAccessor; //导入依赖的package包/类
@Test
public void afterConnected() throws Exception {

	assertFalse(this.session.isConnected());
	this.connectHeaders.setHost("my-host");
	this.connectHeaders.setHeartbeat(new long[] {11, 12});

	this.session.afterConnected(this.connection);
	assertTrue(this.session.isConnected());

	Message<byte[]> message = this.messageCaptor.getValue();
	StompHeaderAccessor accessor = MessageHeaderAccessor.getAccessor(message, StompHeaderAccessor.class);
	assertEquals(StompCommand.CONNECT, accessor.getCommand());
	assertEquals("my-host", accessor.getHost());
	assertThat(accessor.getAcceptVersion(), containsInAnyOrder("1.1", "1.2"));
	assertArrayEquals(new long[] {11, 12}, accessor.getHeartbeat());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:18,代码来源:DefaultStompSessionTests.java


示例9: send

import org.springframework.messaging.support.MessageHeaderAccessor; //导入依赖的package包/类
@Test
public void send() throws Exception {

	this.session.afterConnected(this.connection);
	assertTrue(this.session.isConnected());

	String destination = "/topic/foo";
	String payload = "sample payload";
	this.session.send(destination, payload);

	Message<byte[]> message = this.messageCaptor.getValue();
	StompHeaderAccessor accessor = MessageHeaderAccessor.getAccessor(message, StompHeaderAccessor.class);
	assertEquals(StompCommand.SEND, accessor.getCommand());

	StompHeaders stompHeaders = StompHeaders.readOnlyStompHeaders(accessor.getNativeHeaders());
	assertEquals(stompHeaders.toString(), 2, stompHeaders.size());

	assertEquals(destination, stompHeaders.getDestination());
	assertEquals(new MimeType("text", "plain", UTF_8), stompHeaders.getContentType());
	assertEquals(-1, stompHeaders.getContentLength()); // StompEncoder isn't involved
	assertEquals(payload, new String(message.getPayload(), UTF_8));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:23,代码来源:DefaultStompSessionTests.java


示例10: sendWithReceipt

import org.springframework.messaging.support.MessageHeaderAccessor; //导入依赖的package包/类
@Test
public void sendWithReceipt() throws Exception {

	this.session.afterConnected(this.connection);
	assertTrue(this.session.isConnected());

	this.session.setTaskScheduler(mock(TaskScheduler.class));
	this.session.setAutoReceipt(true);
	this.session.send("/topic/foo", "sample payload");

	Message<byte[]> message = this.messageCaptor.getValue();
	StompHeaderAccessor accessor = MessageHeaderAccessor.getAccessor(message, StompHeaderAccessor.class);
	assertNotNull(accessor.getReceipt());

	StompHeaders stompHeaders = new StompHeaders();
	stompHeaders.setDestination("/topic/foo");
	stompHeaders.setReceipt("my-receipt");
	this.session.send(stompHeaders, "sample payload");

	message = this.messageCaptor.getValue();
	accessor = MessageHeaderAccessor.getAccessor(message, StompHeaderAccessor.class);
	assertEquals("my-receipt", accessor.getReceipt());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:24,代码来源:DefaultStompSessionTests.java


示例11: subscribe

import org.springframework.messaging.support.MessageHeaderAccessor; //导入依赖的package包/类
@Test
public void subscribe() throws Exception {

	this.session.afterConnected(this.connection);
	assertTrue(this.session.isConnected());

	String destination = "/topic/foo";
	StompFrameHandler frameHandler = mock(StompFrameHandler.class);
	Subscription subscription = this.session.subscribe(destination, frameHandler);

	Message<byte[]> message = this.messageCaptor.getValue();
	StompHeaderAccessor accessor = MessageHeaderAccessor.getAccessor(message, StompHeaderAccessor.class);
	assertEquals(StompCommand.SUBSCRIBE, accessor.getCommand());

	StompHeaders stompHeaders = StompHeaders.readOnlyStompHeaders(accessor.getNativeHeaders());
	assertEquals(stompHeaders.toString(), 2, stompHeaders.size());
	assertEquals(destination, stompHeaders.getDestination());
	assertEquals(subscription.getSubscriptionId(), stompHeaders.getId());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:20,代码来源:DefaultStompSessionTests.java


示例12: subscribeWithHeaders

import org.springframework.messaging.support.MessageHeaderAccessor; //导入依赖的package包/类
@Test
public void subscribeWithHeaders() throws Exception {

	this.session.afterConnected(this.connection);
	assertTrue(this.session.isConnected());

	String subscriptionId = "123";
	String destination = "/topic/foo";

	StompHeaders stompHeaders = new StompHeaders();
	stompHeaders.setId(subscriptionId);
	stompHeaders.setDestination(destination);
	StompFrameHandler frameHandler = mock(StompFrameHandler.class);

	Subscription subscription = this.session.subscribe(stompHeaders, frameHandler);
	assertEquals(subscriptionId, subscription.getSubscriptionId());

	Message<byte[]> message = this.messageCaptor.getValue();
	StompHeaderAccessor accessor = MessageHeaderAccessor.getAccessor(message, StompHeaderAccessor.class);
	assertEquals(StompCommand.SUBSCRIBE, accessor.getCommand());

	stompHeaders = StompHeaders.readOnlyStompHeaders(accessor.getNativeHeaders());
	assertEquals(stompHeaders.toString(), 2, stompHeaders.size());
	assertEquals(destination, stompHeaders.getDestination());
	assertEquals(subscriptionId, stompHeaders.getId());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:27,代码来源:DefaultStompSessionTests.java


示例13: unsubscribe

import org.springframework.messaging.support.MessageHeaderAccessor; //导入依赖的package包/类
@Test
public void unsubscribe() throws Exception {

	this.session.afterConnected(this.connection);
	assertTrue(this.session.isConnected());

	String destination = "/topic/foo";
	StompFrameHandler frameHandler = mock(StompFrameHandler.class);
	Subscription subscription = this.session.subscribe(destination, frameHandler);
	subscription.unsubscribe();

	Message<byte[]> message = this.messageCaptor.getValue();
	StompHeaderAccessor accessor = MessageHeaderAccessor.getAccessor(message, StompHeaderAccessor.class);
	assertEquals(StompCommand.UNSUBSCRIBE, accessor.getCommand());

	StompHeaders stompHeaders = StompHeaders.readOnlyStompHeaders(accessor.getNativeHeaders());
	assertEquals(stompHeaders.toString(), 1, stompHeaders.size());
	assertEquals(subscription.getSubscriptionId(), stompHeaders.getId());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:20,代码来源:DefaultStompSessionTests.java


示例14: convertAndSendWithCustomHeaderNonNative

import org.springframework.messaging.support.MessageHeaderAccessor; //导入依赖的package包/类
@Test
public void convertAndSendWithCustomHeaderNonNative() {
	Map<String, Object> headers = new HashMap<>();
	headers.put("key", "value");
	headers.put(NativeMessageHeaderAccessor.NATIVE_HEADERS, new LinkedMultiValueMap<String, String>());
	this.messagingTemplate.convertAndSend("/foo", "data", headers);

	List<Message<byte[]>> messages = this.messageChannel.getMessages();

	SimpMessageHeaderAccessor headerAccessor =
			MessageHeaderAccessor.getAccessor(messages.get(0), SimpMessageHeaderAccessor.class);

	assertNotNull(headerAccessor);
	assertEquals("value", headerAccessor.toMap().get("key"));
	assertNull(headerAccessor.getNativeHeader("key"));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:17,代码来源:SimpMessagingTemplateTests.java


示例15: convertAndSendWithCustomDestinationPrefix

import org.springframework.messaging.support.MessageHeaderAccessor; //导入依赖的package包/类
@Test
public void convertAndSendWithCustomDestinationPrefix() {
	this.messagingTemplate.setUserDestinationPrefix("/prefix");
	this.messagingTemplate.convertAndSendToUser("joe", "/queue/foo", "data");
	List<Message<byte[]>> messages = this.messageChannel.getMessages();

	assertEquals(1, messages.size());

	Message<byte[]> message = messages.get(0);
	SimpMessageHeaderAccessor headerAccessor =
			MessageHeaderAccessor.getAccessor(message, SimpMessageHeaderAccessor.class);

	assertNotNull(headerAccessor);
	assertEquals(SimpMessageType.MESSAGE, headerAccessor.getMessageType());
	assertEquals("/prefix/joe/queue/foo", headerAccessor.getDestination());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:17,代码来源:SimpMessagingTemplateTests.java


示例16: setup

import org.springframework.messaging.support.MessageHeaderAccessor; //导入依赖的package包/类
@Before
public void setup() throws Exception {
	this.resolver = new HeadersMethodArgumentResolver();

	Method method = getClass().getDeclaredMethod("handleMessage", Map.class, String.class,
			MessageHeaders.class, MessageHeaderAccessor.class, TestMessageHeaderAccessor.class);

	this.paramAnnotated = new MethodParameter(method, 0);
	this.paramAnnotatedNotMap = new MethodParameter(method, 1);
	this.paramMessageHeaders = new MethodParameter(method, 2);
	this.paramMessageHeaderAccessor = new MethodParameter(method, 3);
	this.paramMessageHeaderAccessorSubclass = new MethodParameter(method, 4);

	Map<String, Object> headers = new HashMap<String, Object>();
	headers.put("foo", "bar");
	this.message = MessageBuilder.withPayload(new byte[0]).copyHeaders(headers).build();
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:18,代码来源:HeadersMethodArgumentResolverTests.java


示例17: handleError

import org.springframework.messaging.support.MessageHeaderAccessor; //导入依赖的package包/类
@SuppressWarnings("deprecation")
private void handleError(WebSocketSession session, Throwable ex, Message<byte[]> clientMessage) {
	if (getErrorHandler() == null) {
		sendErrorMessage(session, ex);
		return;
	}

	Message<byte[]> message = getErrorHandler().handleClientMessageProcessingError(clientMessage, ex);
	if (message == null) {
		return;
	}

	StompHeaderAccessor accessor = MessageHeaderAccessor.getAccessor(message, StompHeaderAccessor.class);
	Assert.notNull(accessor, "Expected STOMP headers");
	sendToClient(session, accessor, message.getPayload());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:17,代码来源:StompSubProtocolHandler.java


示例18: convertConnectAcktoStompConnected

import org.springframework.messaging.support.MessageHeaderAccessor; //导入依赖的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


示例19: handleClientMessageProcessingError

import org.springframework.messaging.support.MessageHeaderAccessor; //导入依赖的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


示例20: handleWebSocketMessage

import org.springframework.messaging.support.MessageHeaderAccessor; //导入依赖的package包/类
@Test
@SuppressWarnings({ "unchecked", "rawtypes" })
public void handleWebSocketMessage() throws Exception {
	String text = "SEND\na:alpha\n\nMessage payload\0";
	connect().handleMessage(this.webSocketSession, new TextMessage(text));

	ArgumentCaptor<Message> captor = ArgumentCaptor.forClass(Message.class);
	verify(this.stompSession).handleMessage(captor.capture());
	Message<byte[]> message = captor.getValue();
	assertNotNull(message);

	StompHeaderAccessor accessor = MessageHeaderAccessor.getAccessor(message, StompHeaderAccessor.class);
	StompHeaders headers = StompHeaders.readOnlyStompHeaders(accessor.toNativeHeaderMap());
	assertEquals(StompCommand.SEND, accessor.getCommand());
	assertEquals("alpha", headers.getFirst("a"));
	assertEquals("Message payload", new String(message.getPayload(), UTF_8));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:18,代码来源:WebSocketStompClientTests.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java StringStatistic类代码示例发布时间:2022-05-23
下一篇:
Java LexerlessGrammarBuilder类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap