Java Code Examples for org.springframework.messaging.simp.SimpMessageHeaderAccessor#getFirstNativeHeader()
The following examples show how to use
org.springframework.messaging.simp.SimpMessageHeaderAccessor#getFirstNativeHeader() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UserDestinationMessageHandler.java From spring-analysis-note with MIT License | 6 votes |
public void handleUnresolved(Message<?> message) { MessageHeaders headers = message.getHeaders(); if (SimpMessageHeaderAccessor.getFirstNativeHeader( SimpMessageHeaderAccessor.ORIGINAL_DESTINATION, headers) != null) { // Re-broadcast return; } SimpMessageHeaderAccessor accessor = SimpMessageHeaderAccessor.wrap(message); String destination = accessor.getDestination(); accessor.setNativeHeader(SimpMessageHeaderAccessor.ORIGINAL_DESTINATION, destination); accessor.setLeaveMutable(true); message = MessageBuilder.createMessage(message.getPayload(), accessor.getMessageHeaders()); if (logger.isTraceEnabled()) { logger.trace("Translated " + destination + " -> " + getBroadcastDestination()); } this.messagingTemplate.send(getBroadcastDestination(), message); }
Example 2
Source File: DefaultSubscriptionRegistry.java From spring-analysis-note with MIT License | 6 votes |
@Nullable private Expression getSelectorExpression(MessageHeaders headers) { Expression expression = null; if (getSelectorHeaderName() != null) { String selector = SimpMessageHeaderAccessor.getFirstNativeHeader(getSelectorHeaderName(), headers); if (selector != null) { try { expression = this.expressionParser.parseExpression(selector); this.selectorHeaderInUse = true; if (logger.isTraceEnabled()) { logger.trace("Subscription selector: [" + selector + "]"); } } catch (Throwable ex) { if (logger.isDebugEnabled()) { logger.debug("Failed to parse selector: " + selector, ex); } } } } return expression; }
Example 3
Source File: UserDestinationMessageHandler.java From java-technology-stack with MIT License | 6 votes |
public void handleUnresolved(Message<?> message) { MessageHeaders headers = message.getHeaders(); if (SimpMessageHeaderAccessor.getFirstNativeHeader( SimpMessageHeaderAccessor.ORIGINAL_DESTINATION, headers) != null) { // Re-broadcast return; } SimpMessageHeaderAccessor accessor = SimpMessageHeaderAccessor.wrap(message); String destination = accessor.getDestination(); accessor.setNativeHeader(SimpMessageHeaderAccessor.ORIGINAL_DESTINATION, destination); accessor.setLeaveMutable(true); message = MessageBuilder.createMessage(message.getPayload(), accessor.getMessageHeaders()); if (logger.isTraceEnabled()) { logger.trace("Translated " + destination + " -> " + getBroadcastDestination()); } this.messagingTemplate.send(getBroadcastDestination(), message); }
Example 4
Source File: DefaultSubscriptionRegistry.java From java-technology-stack with MIT License | 6 votes |
@Nullable private Expression getSelectorExpression(MessageHeaders headers) { Expression expression = null; if (getSelectorHeaderName() != null) { String selector = SimpMessageHeaderAccessor.getFirstNativeHeader(getSelectorHeaderName(), headers); if (selector != null) { try { expression = this.expressionParser.parseExpression(selector); this.selectorHeaderInUse = true; if (logger.isTraceEnabled()) { logger.trace("Subscription selector: [" + selector + "]"); } } catch (Throwable ex) { if (logger.isDebugEnabled()) { logger.debug("Failed to parse selector: " + selector, ex); } } } } return expression; }
Example 5
Source File: UserDestinationMessageHandler.java From spring4-understanding with Apache License 2.0 | 6 votes |
public Message<?> preHandle(Message<?> message) throws MessagingException { String destination = SimpMessageHeaderAccessor.getDestination(message.getHeaders()); if (!getBroadcastDestination().equals(destination)) { return message; } SimpMessageHeaderAccessor accessor = getAccessor(message, SimpMessageHeaderAccessor.class); if (accessor.getSessionId() == null) { // Our own broadcast return null; } destination = accessor.getFirstNativeHeader(ORIGINAL_DESTINATION); if (logger.isTraceEnabled()) { logger.trace("Checking unresolved user destination: " + destination); } SimpMessageHeaderAccessor newAccessor = SimpMessageHeaderAccessor.create(SimpMessageType.MESSAGE); for (String name : accessor.toNativeHeaderMap().keySet()) { if (NO_COPY_LIST.contains(name)) { continue; } newAccessor.setNativeHeader(name, accessor.getFirstNativeHeader(name)); } newAccessor.setDestination(destination); newAccessor.setHeader(SimpMessageHeaderAccessor.IGNORE_ERROR, true); // ensure send doesn't block return MessageBuilder.createMessage(message.getPayload(), newAccessor.getMessageHeaders()); }
Example 6
Source File: UserDestinationMessageHandler.java From spring4-understanding with Apache License 2.0 | 6 votes |
public void handleUnresolved(Message<?> message) { MessageHeaders headers = message.getHeaders(); if (SimpMessageHeaderAccessor.getFirstNativeHeader(ORIGINAL_DESTINATION, headers) != null) { // Re-broadcast return; } SimpMessageHeaderAccessor accessor = SimpMessageHeaderAccessor.wrap(message); String destination = accessor.getDestination(); accessor.setNativeHeader(ORIGINAL_DESTINATION, destination); accessor.setLeaveMutable(true); message = MessageBuilder.createMessage(message.getPayload(), accessor.getMessageHeaders()); if (logger.isTraceEnabled()) { logger.trace("Translated " + destination + " -> " + getBroadcastDestination()); } this.messagingTemplate.send(getBroadcastDestination(), message); }
Example 7
Source File: DefaultSubscriptionRegistry.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Override protected void addSubscriptionInternal(String sessionId, String subsId, String destination, Message<?> message) { Expression expression = null; MessageHeaders headers = message.getHeaders(); String selector = SimpMessageHeaderAccessor.getFirstNativeHeader(getSelectorHeaderName(), headers); if (selector != null) { try { expression = this.expressionParser.parseExpression(selector); this.selectorHeaderInUse = true; if (logger.isTraceEnabled()) { logger.trace("Subscription selector: [" + selector + "]"); } } catch (Throwable ex) { if (logger.isDebugEnabled()) { logger.debug("Failed to parse selector: " + selector, ex); } } } this.subscriptionRegistry.addSubscription(sessionId, subsId, destination, expression); this.destinationCache.updateAfterNewSubscription(destination, sessionId, subsId); }
Example 8
Source File: DefaultSubscriptionRegistry.java From spring4-understanding with Apache License 2.0 | 6 votes |
@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); }
Example 9
Source File: UserDestinationMessageHandler.java From spring-analysis-note with MIT License | 5 votes |
@Nullable public Message<?> preHandle(Message<?> message) throws MessagingException { String destination = SimpMessageHeaderAccessor.getDestination(message.getHeaders()); if (!getBroadcastDestination().equals(destination)) { return message; } SimpMessageHeaderAccessor accessor = SimpMessageHeaderAccessor.getAccessor(message, SimpMessageHeaderAccessor.class); Assert.state(accessor != null, "No SimpMessageHeaderAccessor"); if (accessor.getSessionId() == null) { // Our own broadcast return null; } destination = accessor.getFirstNativeHeader(SimpMessageHeaderAccessor.ORIGINAL_DESTINATION); if (logger.isTraceEnabled()) { logger.trace("Checking unresolved user destination: " + destination); } SimpMessageHeaderAccessor newAccessor = SimpMessageHeaderAccessor.create(SimpMessageType.MESSAGE); for (String name : accessor.toNativeHeaderMap().keySet()) { if (NO_COPY_LIST.contains(name)) { continue; } newAccessor.setNativeHeader(name, accessor.getFirstNativeHeader(name)); } if (destination != null) { newAccessor.setDestination(destination); } newAccessor.setHeader(SimpMessageHeaderAccessor.IGNORE_ERROR, true); // ensure send doesn't block return MessageBuilder.createMessage(message.getPayload(), newAccessor.getMessageHeaders()); }
Example 10
Source File: DefaultSubscriptionRegistry.java From spring-analysis-note with MIT License | 5 votes |
@Override public TypedValue read(EvaluationContext context, @Nullable Object target, String name) { Object value; if (target instanceof Message) { value = name.equals("headers") ? ((Message) target).getHeaders() : null; } else if (target instanceof MessageHeaders) { MessageHeaders headers = (MessageHeaders) target; SimpMessageHeaderAccessor accessor = MessageHeaderAccessor.getAccessor(headers, SimpMessageHeaderAccessor.class); Assert.state(accessor != null, "No SimpMessageHeaderAccessor"); if ("destination".equalsIgnoreCase(name)) { value = accessor.getDestination(); } else { value = accessor.getFirstNativeHeader(name); if (value == null) { value = headers.get(name); } } } else { // Should never happen... throw new IllegalStateException("Expected Message or MessageHeaders."); } return new TypedValue(value); }
Example 11
Source File: UserDestinationMessageHandler.java From java-technology-stack with MIT License | 5 votes |
@Nullable public Message<?> preHandle(Message<?> message) throws MessagingException { String destination = SimpMessageHeaderAccessor.getDestination(message.getHeaders()); if (!getBroadcastDestination().equals(destination)) { return message; } SimpMessageHeaderAccessor accessor = SimpMessageHeaderAccessor.getAccessor(message, SimpMessageHeaderAccessor.class); Assert.state(accessor != null, "No SimpMessageHeaderAccessor"); if (accessor.getSessionId() == null) { // Our own broadcast return null; } destination = accessor.getFirstNativeHeader(SimpMessageHeaderAccessor.ORIGINAL_DESTINATION); if (logger.isTraceEnabled()) { logger.trace("Checking unresolved user destination: " + destination); } SimpMessageHeaderAccessor newAccessor = SimpMessageHeaderAccessor.create(SimpMessageType.MESSAGE); for (String name : accessor.toNativeHeaderMap().keySet()) { if (NO_COPY_LIST.contains(name)) { continue; } newAccessor.setNativeHeader(name, accessor.getFirstNativeHeader(name)); } if (destination != null) { newAccessor.setDestination(destination); } newAccessor.setHeader(SimpMessageHeaderAccessor.IGNORE_ERROR, true); // ensure send doesn't block return MessageBuilder.createMessage(message.getPayload(), newAccessor.getMessageHeaders()); }
Example 12
Source File: DefaultSubscriptionRegistry.java From java-technology-stack with MIT License | 5 votes |
@Override public TypedValue read(EvaluationContext context, @Nullable Object target, String name) { Object value; if (target instanceof Message) { value = name.equals("headers") ? ((Message) target).getHeaders() : null; } else if (target instanceof MessageHeaders) { MessageHeaders headers = (MessageHeaders) target; SimpMessageHeaderAccessor accessor = MessageHeaderAccessor.getAccessor(headers, SimpMessageHeaderAccessor.class); Assert.state(accessor != null, "No SimpMessageHeaderAccessor"); if ("destination".equalsIgnoreCase(name)) { value = accessor.getDestination(); } else { value = accessor.getFirstNativeHeader(name); if (value == null) { value = headers.get(name); } } } else { // Should never happen... throw new IllegalStateException("Expected Message or MessageHeaders."); } return new TypedValue(value); }