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


Java StompHeaderAccessor类代码示例

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


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

示例1: onSessionConnected

import org.springframework.messaging.simp.stomp.StompHeaderAccessor; //导入依赖的package包/类
@EventListener
public void onSessionConnected(SessionConnectEvent event) {
    Message msg = event.getMessage();
    StompHeaderAccessor accessor = StompHeaderAccessor.wrap(msg);
    String sessionId = accessor.getSessionId();

    String spaceKey = (String) webSocketSessionStore.getAttribute(sessionId, "spaceKey");

    log.debug("Session connect: spaceKey => {}, sessionId => {} ", spaceKey, sessionId);

    if (spaceKey == null) {
        return;
    }

    boolean isToBeOnline = onlineWorkspaceStore.isEmpty(spaceKey);
    onlineWorkspaceStore.addSession(spaceKey, sessionId);

    if (isToBeOnline) {
        eventPublisher.publishEvent(new WorkspaceOnlineEvent(event, spaceKey));
    }
}
 
开发者ID:Coding,项目名称:WebIDE-Backend,代码行数:22,代码来源:EventExchange.java

示例2: preSend

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

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

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

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

示例6: handleError

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

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

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

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

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

示例11: clientInboundChannelSendMessage

import org.springframework.messaging.simp.stomp.StompHeaderAccessor; //导入依赖的package包/类
@Test
public void clientInboundChannelSendMessage() throws Exception {
	ApplicationContext config = createConfig(TestChannelConfig.class, TestConfigurer.class);
	TestChannel channel = config.getBean("clientInboundChannel", TestChannel.class);
	SubProtocolWebSocketHandler webSocketHandler = config.getBean(SubProtocolWebSocketHandler.class);

	List<ChannelInterceptor> interceptors = channel.getInterceptors();
	assertEquals(ImmutableMessageChannelInterceptor.class, interceptors.get(interceptors.size()-1).getClass());

	TestWebSocketSession session = new TestWebSocketSession("s1");
	session.setOpen(true);
	webSocketHandler.afterConnectionEstablished(session);

	TextMessage textMessage = StompTextMessageBuilder.create(StompCommand.SEND).headers("destination:/foo").build();
	webSocketHandler.handleMessage(session, textMessage);

	Message<?> message = channel.messages.get(0);
	StompHeaderAccessor accessor = StompHeaderAccessor.getAccessor(message, StompHeaderAccessor.class);
	assertNotNull(accessor);
	assertFalse(accessor.isMutable());
	assertEquals(SimpMessageType.MESSAGE, accessor.getMessageType());
	assertEquals("/foo", accessor.getDestination());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:24,代码来源:WebSocketMessageBrokerConfigurationSupportTests.java

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

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

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

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


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