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


Java MessageHeaders类代码示例

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


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

示例1: addComment

import org.springframework.messaging.MessageHeaders; //导入依赖的package包/类
@PostMapping("/comments")
public Mono<String> addComment(Mono<Comment> newComment) {
	if (commentSink != null) {
		return newComment
			.map(comment -> {
				commentSink.next(MessageBuilder
					.withPayload(comment)
					.setHeader(MessageHeaders.CONTENT_TYPE,
						MediaType.APPLICATION_JSON_VALUE)
					.build());
				return comment;
			})
			.flatMap(comment -> {
				meterRegistry
					.counter("comments.produced", "imageId", comment.getImageId())
					.increment();
				return Mono.just("redirect:/");
			});
	} else {
		return Mono.just("redirect:/");
	}
}
 
开发者ID:PacktPublishing,项目名称:Learning-Spring-Boot-2.0-Second-Edition,代码行数:23,代码来源:CommentController.java

示例2: addComment

import org.springframework.messaging.MessageHeaders; //导入依赖的package包/类
@PreAuthorize("hasRole('USER')")
@PostMapping("/comments")
public Mono<ResponseEntity<?>> addComment(Mono<Comment> newComment) {
	if (commentSink != null) {
		return newComment
			.map(comment -> {
				System.out.println("Got " + comment);
				commentSink.next(MessageBuilder
					.withPayload(comment)
					.setHeader(MessageHeaders.CONTENT_TYPE,
						MediaType.APPLICATION_JSON_VALUE)
					.build());
				return comment;
			})
			.flatMap(comment -> {
				meterRegistry
					.counter("comments.produced", "imageId", comment.getImageId())
					.increment();
				return Mono.just(ResponseEntity.noContent().build());
			});
	} else {
		return Mono.just(ResponseEntity.noContent().build());
	}
}
 
开发者ID:PacktPublishing,项目名称:Learning-Spring-Boot-2.0-Second-Edition,代码行数:25,代码来源:CommentController.java

示例3: addComment

import org.springframework.messaging.MessageHeaders; //导入依赖的package包/类
@PostMapping("/comments")
public Mono<ResponseEntity<?>> addComment(Mono<Comment> newComment) {
	if (commentSink != null) {
		return newComment
			.map(comment -> {
				commentSink.next(MessageBuilder
					.withPayload(comment)
					.setHeader(MessageHeaders.CONTENT_TYPE,
						MediaType.APPLICATION_JSON_VALUE)
					.build());
				return comment;
			})
			.flatMap(comment -> {
				meterRegistry
					.counter("comments.produced", "imageId", comment.getImageId())
					.increment();
				return Mono.just(ResponseEntity.noContent().build());
			});
	} else {
		return Mono.just(ResponseEntity.noContent().build());
	}
}
 
开发者ID:PacktPublishing,项目名称:Learning-Spring-Boot-2.0-Second-Edition,代码行数:23,代码来源:CommentController.java

示例4: testSendMessageToEntity

import org.springframework.messaging.MessageHeaders; //导入依赖的package包/类
@Test
public void testSendMessageToEntity() throws Exception {
    entityService.sendMessageToEntity(entity, output);

    verify(simpMessagingTemplate).convertAndSendToUser(
            eq("stompUsername"),
            eq("/queue/output"),
            eq(output),
            messageHeadersArgumentCaptor.capture());

    MessageHeaders headers = messageHeadersArgumentCaptor.getValue();
    SimpMessageHeaderAccessor accessor = SimpMessageHeaderAccessor.getAccessor(headers, SimpMessageHeaderAccessor.class);

    assertEquals("stompSessionId", accessor.getSessionId());
    assertTrue(accessor.isMutable());
}
 
开发者ID:scionaltera,项目名称:emergentmud,代码行数:17,代码来源:EntityServiceTest.java

示例5: verifyContents

import org.springframework.messaging.MessageHeaders; //导入依赖的package包/类
private void verifyContents() {
    for (int i = 0; i < contents.size(); i++) {
        verify(simpMessagingTemplate).convertAndSendToUser(
                eq("stompUsername" + i),
                eq("/queue/output"),
                eq(output),
                messageHeadersArgumentCaptor.capture()
        );

        MessageHeaders headers = messageHeadersArgumentCaptor.getValue();
        SimpMessageHeaderAccessor accessor = SimpMessageHeaderAccessor.getAccessor(headers, SimpMessageHeaderAccessor.class);

        assertEquals("stompSessionId" + i, accessor.getSessionId());
        assertTrue(accessor.isMutable());
    }
}
 
开发者ID:scionaltera,项目名称:emergentmud,代码行数:17,代码来源:EntityServiceTest.java

示例6: authenticateUser

import org.springframework.messaging.MessageHeaders; //导入依赖的package包/类
/**
 * Authenticate user before he is allowed to connect to
 * the socket.
 *
 * @param message Message<?>
 * @return Principal
 */
private Principal authenticateUser(Message<?> message) {
	MessageHeaders headers = message.getHeaders();
	String token = this.parseToken(headers);

	UserService service = new UserService();
	Traveler user = service.getUserByToken(token);

	if (user.getUid() == null) {
		System.out.println("invalid token");
		return null;
	}

	System.out.println("valid token");
	System.out.println(user.getUid());
	return user;
}
 
开发者ID:trvlrch,项目名称:trvlr-backend,代码行数:24,代码来源:AuthenticationInterceptor.java

示例7: receiveMessage

import org.springframework.messaging.MessageHeaders; //导入依赖的package包/类
private void receiveMessage(PubsubMessage message, AckReplyConsumer consumer) {
	Map<String, Object> messageHeaders = new HashMap<>();

	message.getAttributesMap().forEach(messageHeaders::put);

	if (this.ackMode == AckMode.MANUAL) {
		// Send the consumer downstream so user decides on when to ack/nack.
		messageHeaders.put(GcpHeaders.ACKNOWLEDGEMENT, consumer);
	}

	try {
		sendMessage(this.messageConverter.toMessage(
				message.getData().toStringUtf8(),
				new MessageHeaders(messageHeaders)));
	}
	catch (RuntimeException re) {
		if (this.ackMode == AckMode.AUTO) {
			consumer.nack();
		}
		throw re;
	}

	if (this.ackMode == AckMode.AUTO) {
		consumer.ack();
	}
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-gcp,代码行数:27,代码来源:PubSubInboundChannelAdapter.java

示例8: testWorkDelegatesMethodCall

import org.springframework.messaging.MessageHeaders; //导入依赖的package包/类
@Test
public void testWorkDelegatesMethodCall() throws Exception {
    // given
    AtomicInteger counter = new AtomicInteger(0);
    MessageWorker<String, Integer> uut = new MessageWorker<String, Integer>() {
        @Override
        public Integer work(String object) {
            return counter.incrementAndGet();
        }
    };
    MessageHeaders messageHeaders = mock(MessageHeaders.class);

    // when
    uut.work("dummy value", messageHeaders);

    // then
    assertEquals(1, counter.intValue());
    verifyZeroInteractions(messageHeaders);
}
 
开发者ID:Mercateo,项目名称:sqs-utils,代码行数:20,代码来源:MessageWorkerTest.java

示例9: canConvertTo

import org.springframework.messaging.MessageHeaders; //导入依赖的package包/类
@Override
protected boolean canConvertTo(Object payload, MessageHeaders headers) {
	if (!jackson23Available || !logger.isWarnEnabled()) {
		return (this.objectMapper.canSerialize(payload.getClass()) && supportsMimeType(headers));
	}
	AtomicReference<Throwable> causeRef = new AtomicReference<Throwable>();
	if (this.objectMapper.canSerialize(payload.getClass(), causeRef) && supportsMimeType(headers)) {
		return true;
	}
	Throwable cause = causeRef.get();
	if (cause != null) {
		String msg = "Failed to evaluate serialization for type [" + payload.getClass() + "]";
		if (logger.isDebugEnabled()) {
			logger.warn(msg, cause);
		}
		else {
			logger.warn(msg + ": " + cause);
		}
	}
	return false;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:22,代码来源:MappingJackson2MessageConverter.java

示例10: resolve

import org.springframework.messaging.MessageHeaders; //导入依赖的package包/类
@Override
public MimeType resolve(MessageHeaders headers) {
	if (headers == null || headers.get(MessageHeaders.CONTENT_TYPE) == null) {
		return this.defaultMimeType;
	}
	Object value = headers.get(MessageHeaders.CONTENT_TYPE);
	if (value instanceof MimeType) {
		return (MimeType) value;
	}
	else if (value instanceof String) {
		return MimeType.valueOf((String) value);
	}
	else {
		throw new IllegalArgumentException(
				"Unknown type for contentType header value: " + value.getClass());
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:18,代码来源:DefaultContentTypeResolver.java

示例11: setup

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

示例12: existingHeadersModification

import org.springframework.messaging.MessageHeaders; //导入依赖的package包/类
@Test
public void existingHeadersModification() throws InterruptedException {
	Map<String, Object> map = new HashMap<>();
	map.put("foo", "bar");
	map.put("bar", "baz");
	GenericMessage<String> message = new GenericMessage<>("payload", map);

	Thread.sleep(50);

	MessageHeaderAccessor accessor = new MessageHeaderAccessor(message);
	accessor.setHeader("foo", "BAR");
	MessageHeaders actual = accessor.getMessageHeaders();

	assertEquals(3, actual.size());
	assertNotEquals(message.getHeaders().getId(), actual.getId());
	assertEquals("BAR", actual.get("foo"));
	assertEquals("baz", actual.get("bar"));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:19,代码来源:MessageHeaderAccessorTests.java

示例13: sendSystemSubscriptions

import org.springframework.messaging.MessageHeaders; //导入依赖的package包/类
private void sendSystemSubscriptions() {
	int i = 0;
	for (String destination : getSystemSubscriptions().keySet()) {
		StompHeaderAccessor accessor = StompHeaderAccessor.create(StompCommand.SUBSCRIBE);
		accessor.setSubscriptionId(String.valueOf(i++));
		accessor.setDestination(destination);
		if (logger.isDebugEnabled()) {
			logger.debug("Subscribing to " + destination + " on \"system\" connection.");
		}
		TcpConnection<byte[]> conn = getTcpConnection();
		if (conn != null) {
			MessageHeaders headers = accessor.getMessageHeaders();
			conn.send(MessageBuilder.createMessage(EMPTY_PAYLOAD, headers)).addCallback(
					new ListenableFutureCallback<Void>() {
						public void onSuccess(Void result) {
						}
						public void onFailure(Throwable ex) {
							String error = "Failed to subscribe in \"system\" session.";
							handleTcpConnectionFailure(error, ex);
						}
					});
		}
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:25,代码来源:StompBrokerRelayMessageHandler.java

示例14: testHeadersToSend

import org.springframework.messaging.MessageHeaders; //导入依赖的package包/类
@Test
public void testHeadersToSend() throws Exception {
	Message<?> inputMessage = createInputMessage("sess1", "sub1", "/app", "/dest", null);

	SimpMessageSendingOperations messagingTemplate = Mockito.mock(SimpMessageSendingOperations.class);
	SendToMethodReturnValueHandler handler = new SendToMethodReturnValueHandler(messagingTemplate, false);

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

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

	MessageHeaders messageHeaders = captor.getValue();
	SimpMessageHeaderAccessor accessor = getAccessor(messageHeaders, SimpMessageHeaderAccessor.class);
	assertNotNull(accessor);
	assertTrue(accessor.isMutable());
	assertEquals("sess1", accessor.getSessionId());
	assertNull("Subscription id should not be copied", accessor.getSubscriptionId());
	assertEquals(this.noAnnotationsReturnType, accessor.getHeader(SimpMessagingTemplate.CONVERSION_HINT_HEADER));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:21,代码来源:SendToMethodReturnValueHandlerTests.java

示例15: unregisterSubscription

import org.springframework.messaging.MessageHeaders; //导入依赖的package包/类
@Override
public final void unregisterSubscription(Message<?> message) {
	MessageHeaders headers = message.getHeaders();

	SimpMessageType messageType = SimpMessageHeaderAccessor.getMessageType(headers);
	if (!SimpMessageType.UNSUBSCRIBE.equals(messageType)) {
		throw new IllegalArgumentException("Expected UNSUBSCRIBE: " + message);
	}

	String sessionId = SimpMessageHeaderAccessor.getSessionId(headers);
	if (sessionId == null) {
		logger.error("No sessionId in " + message);
		return;
	}

	String subscriptionId = SimpMessageHeaderAccessor.getSubscriptionId(headers);
	if (subscriptionId == null) {
		logger.error("No subscriptionId " + message);
		return;
	}

	removeSubscriptionInternal(sessionId, subscriptionId, message);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:24,代码来源:AbstractSubscriptionRegistry.java


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