List of usage examples for org.springframework.messaging Message getHeaders
MessageHeaders getHeaders();
From source file:org.springframework.messaging.simp.user.DefaultUserDestinationResolver.java
@Nullable private ParseResult parseSubscriptionMessage(Message<?> message, String sourceDestination) { MessageHeaders headers = message.getHeaders(); String sessionId = SimpMessageHeaderAccessor.getSessionId(headers); if (sessionId == null) { logger.error("No session id. Ignoring " + message); return null; }//from w ww. java2s . c o m int prefixEnd = this.prefix.length() - 1; String actualDestination = sourceDestination.substring(prefixEnd); if (isRemoveLeadingSlash()) { actualDestination = actualDestination.substring(1); } Principal principal = SimpMessageHeaderAccessor.getUser(headers); String user = (principal != null ? principal.getName() : null); Set<String> sessionIds = Collections.singleton(sessionId); return new ParseResult(sourceDestination, actualDestination, sourceDestination, sessionIds, user); }
From source file:org.springframework.messaging.support.MessageHeaderAccessor.java
/** * A constructor accepting the headers of an existing message to copy. *//*from w w w.jav a2 s . c o m*/ public MessageHeaderAccessor(Message<?> message) { if (message != null) { this.headers = new MutableMessageHeaders(message.getHeaders()); } else { this.headers = new MutableMessageHeaders(); } }
From source file:org.springframework.messaging.support.MessageHeaderAccessor.java
/** * Return the original {@code MessageHeaderAccessor} used to create the headers * of the given {@code Message}, or {@code null} if that's not available or if * its type does not match the required type. * <p>This is for cases where the existence of an accessor is strongly expected * (to be followed up with an assertion) or will created if not provided. * @return an accessor instance of the specified type, or {@code null} if none * @since 4.1// w ww. j a va 2s.c o m */ public static <T extends MessageHeaderAccessor> T getAccessor(Message<?> message, Class<T> requiredType) { return getAccessor(message.getHeaders(), requiredType); }
From source file:org.springframework.messaging.support.MessageHeaderAccessor.java
/** * Return a mutable {@code MessageHeaderAccessor} for the given message attempting * to match the type of accessor used to create the message headers, or otherwise * wrapping the message with a {@code MessageHeaderAccessor} instance. * <p>This is for cases where a header needs to be updated in generic code * while preserving the accessor type for downstream processing. * @return an accessor of the required type, never {@code null}. * @since 4.1// w w w . j av a2 s . c o m */ public static MessageHeaderAccessor getMutableAccessor(Message<?> message) { if (message.getHeaders() instanceof MutableMessageHeaders) { MutableMessageHeaders mutableHeaders = (MutableMessageHeaders) message.getHeaders(); MessageHeaderAccessor accessor = mutableHeaders.getMessageHeaderAccessor(); if (accessor != null) { return (accessor.isMutable() ? accessor : accessor.createAccessor(message)); } } return new MessageHeaderAccessor(message); }
From source file:org.springframework.statemachine.support.AbstractStateMachine.java
private StateContext<S, E> buildStateContext(Stage stage, Message<E> message, Transition<S, E> transition, StateMachine<S, E> stateMachine) { MessageHeaders messageHeaders = message != null ? message.getHeaders() : new MessageHeaders(new HashMap<String, Object>()); return new DefaultStateContext<S, E>(stage, message, messageHeaders, extendedState, transition, stateMachine, null, null, null); }
From source file:org.springframework.statemachine.support.AbstractStateMachine.java
private StateContext<S, E> buildStateContext(Stage stage, Message<E> message, Transition<S, E> transition, StateMachine<S, E> stateMachine, Exception exception) { MessageHeaders messageHeaders = message != null ? message.getHeaders() : new MessageHeaders(new HashMap<String, Object>()); return new DefaultStateContext<S, E>(stage, message, messageHeaders, extendedState, transition, stateMachine, null, null, exception); }
From source file:org.springframework.statemachine.support.AbstractStateMachine.java
private StateContext<S, E> buildStateContext(Stage stage, Message<E> message, Transition<S, E> transition, StateMachine<S, E> stateMachine, State<S, E> source, State<S, E> target) { MessageHeaders messageHeaders = message != null ? message.getHeaders() : new MessageHeaders(new HashMap<String, Object>()); return new DefaultStateContext<S, E>(stage, message, messageHeaders, extendedState, transition, stateMachine, source, target, null); }
From source file:org.springframework.statemachine.support.AbstractStateMachine.java
private StateContext<S, E> buildStateContext(Stage stage, Message<E> message, Transition<S, E> transition, StateMachine<S, E> stateMachine, Collection<State<S, E>> sources, Collection<State<S, E>> targets) { MessageHeaders messageHeaders = message != null ? message.getHeaders() : new MessageHeaders(new HashMap<String, Object>()); return new DefaultStateContext<S, E>(stage, message, messageHeaders, extendedState, transition, stateMachine, null, null, sources, targets, null); }
From source file:org.springframework.statemachine.support.DefaultStateMachineExecutor.java
private StateContext<S, E> buildStateContext(Message<E> message, Transition<S, E> transition, StateMachine<S, E> stateMachine) { // TODO: maybe a direct use of MessageHeaders is wring, combine // payload and headers as a message? // add sm id to headers so that user of a StateContext can // see who initiated this transition MessageHeaders messageHeaders = message != null ? message.getHeaders() : new MessageHeaders(new HashMap<String, Object>()); Map<String, Object> map = new HashMap<String, Object>(messageHeaders); if (!map.containsKey(StateMachineSystemConstants.STATEMACHINE_IDENTIFIER)) { // don't set sm id if it's already present because // we want to keep the originating sm id map.put(StateMachineSystemConstants.STATEMACHINE_IDENTIFIER, stateMachine.getUuid()); }//from ww w. j a va 2 s.c o m return new DefaultStateContext<S, E>(Stage.TRANSITION, message, new MessageHeaders(map), stateMachine.getExtendedState(), transition, stateMachine, null, null, null); }
From source file:org.springframework.web.socket.messaging.StompSubProtocolHandler.java
private StompHeaderAccessor getStompHeaderAccessor(Message<?> message) { MessageHeaderAccessor accessor = MessageHeaderAccessor.getAccessor(message, MessageHeaderAccessor.class); if (accessor instanceof StompHeaderAccessor) { return (StompHeaderAccessor) accessor; } else {//from w ww.j a v a2 s .co m StompHeaderAccessor stompAccessor = StompHeaderAccessor.wrap(message); SimpMessageType messageType = SimpMessageHeaderAccessor.getMessageType(message.getHeaders()); if (SimpMessageType.CONNECT_ACK.equals(messageType)) { stompAccessor = convertConnectAcktoStompConnected(stompAccessor); } else if (SimpMessageType.DISCONNECT_ACK.equals(messageType)) { String receipt = getDisconnectReceipt(stompAccessor); if (receipt != null) { stompAccessor = StompHeaderAccessor.create(StompCommand.RECEIPT); stompAccessor.setReceiptId(receipt); } else { stompAccessor = StompHeaderAccessor.create(StompCommand.ERROR); stompAccessor.setMessage("Session closed."); } } else if (SimpMessageType.HEARTBEAT.equals(messageType)) { stompAccessor = StompHeaderAccessor.createForHeartbeat(); } else if (stompAccessor.getCommand() == null || StompCommand.SEND.equals(stompAccessor.getCommand())) { stompAccessor.updateStompCommandAsServerMessage(); } return stompAccessor; } }