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


Java NativeMessageHeaderAccessor类代码示例

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


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

示例1: convertAndSendWithCustomHeaderNonNative

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

示例2: nativeSpanHeadersAdded

import org.springframework.messaging.support.NativeMessageHeaderAccessor; //导入依赖的package包/类
@Test
public void nativeSpanHeadersAdded() {
	Span span = Span.builder().name("http:foo").spanId(1L).traceId(2L).build();
	MessageHeaderAccessor accessor = SimpMessageHeaderAccessor.create();
	Message<String> messageToBuild = MessageBuilder.createMessage("Hello World",
			accessor.getMessageHeaders());
	MessageBuilder<String> messageBuilder = MessageBuilder
			.fromMessage(messageToBuild);

	this.messagingSpanInjector.inject(span, messageBuilder);

	Message<String> message = messageBuilder.build();
	assertThat(message.getHeaders())
			.containsKey(NativeMessageHeaderAccessor.NATIVE_HEADERS);
	MessageHeaderAccessor natives = NativeMessageHeaderAccessor
			.getMutableAccessor(message);
	assertThat(natives.getMessageHeaders()).containsKey(Span.SPAN_ID_NAME);
}
 
开发者ID:reshmik,项目名称:Zipkin,代码行数:19,代码来源:MessagingSpanInjectorTests.java

示例3: nativeSpanHeadersAdded

import org.springframework.messaging.support.NativeMessageHeaderAccessor; //导入依赖的package包/类
@Test
public void nativeSpanHeadersAdded() {
	Span span = Span.builder().name("http:foo").spanId(1L).traceId(2L).build();
	MessageHeaderAccessor accessor = SimpMessageHeaderAccessor.create();
	Message<String> messageToBuild = MessageBuilder.createMessage("Hello World",
			accessor.getMessageHeaders());
	MessageBuilder<String> messageBuilder = MessageBuilder
			.fromMessage(messageToBuild);

	this.spanInjector.inject(span, new MessagingTextMap(messageBuilder));

	Message<String> message = messageBuilder.build();
	assertThat(message.getHeaders())
			.containsKey(NativeMessageHeaderAccessor.NATIVE_HEADERS);
	MessageHeaderAccessor natives = NativeMessageHeaderAccessor
			.getMutableAccessor(message);
	assertThat(natives.getMessageHeaders()).containsKey(TraceMessageHeaders.SPAN_ID_NAME);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-sleuth,代码行数:19,代码来源:MessagingSpanInjectorTests.java

示例4: inject

import org.springframework.messaging.support.NativeMessageHeaderAccessor; //导入依赖的package包/类
@Override
public void inject(Span span, MessageBuilder<?> carrier) {
	Message<?> initialMessage = carrier.build();
	MessageHeaderAccessor accessor = MessageHeaderAccessor
			.getMutableAccessor(initialMessage);
	if (span == null) {
		if (!Span.SPAN_SAMPLED
				.equals(initialMessage.getHeaders().get(Span.SAMPLED_NAME))) {
			accessor.setHeader(Span.SAMPLED_NAME, Span.SPAN_NOT_SAMPLED);
			carrier.setHeaders(accessor);
			return;
		}
		return;
	}
	Map<String, String> headers = new HashMap<>();
	addHeader(headers, Span.TRACE_ID_NAME, Span.idToHex(span.getTraceId()));
	addHeader(headers, Span.SPAN_ID_NAME, Span.idToHex(span.getSpanId()));
	if (span.isExportable()) {
		addAnnotations(this.traceKeys, initialMessage, span);
		Long parentId = getFirst(span.getParents());
		if (parentId != null) {
			addHeader(headers, Span.PARENT_ID_NAME, Span.idToHex(parentId));
		}
		addHeader(headers, Span.SPAN_NAME_NAME, span.getName());
		addHeader(headers, Span.PROCESS_ID_NAME, span.getProcessId());
		addHeader(headers, Span.SAMPLED_NAME, Span.SPAN_SAMPLED);
	}
	else {
		addHeader(headers, Span.SAMPLED_NAME, Span.SPAN_NOT_SAMPLED);
	}
	accessor.setHeader(SPAN_HEADER, span);
	accessor.copyHeaders(headers);
	if (accessor instanceof NativeMessageHeaderAccessor) {
		NativeMessageHeaderAccessor nativeAccessor = (NativeMessageHeaderAccessor) accessor;
		for (String name : headers.keySet()) {
			nativeAccessor.setNativeHeader(name, headers.get(name));
		}
	}
	carrier.setHeaders(accessor);
}
 
开发者ID:reshmik,项目名称:Zipkin,代码行数:41,代码来源:MessagingSpanInjector.java

示例5: iterator

import org.springframework.messaging.support.NativeMessageHeaderAccessor; //导入依赖的package包/类
@Override
public Iterator<Map.Entry<String, String>> iterator() {
	Map<String, String> map = new HashMap<>();
	for (Map.Entry<String, Object> entry : this.delegate.build().getHeaders()
			.entrySet()) {
		if (!NativeMessageHeaderAccessor.NATIVE_HEADERS.equals(entry.getKey())) {
			map.put(entry.getKey(), String.valueOf(entry.getValue()));
		}
	}
	return map.entrySet().iterator();
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-sleuth,代码行数:12,代码来源:MessagingTextMap.java

示例6: vanilla

import org.springframework.messaging.support.NativeMessageHeaderAccessor; //导入依赖的package包/类
@Test
public void vanilla() {
	MessageBuilder<String> builder = MessageBuilder.withPayload("foo");
	MessagingTextMap map = new MessagingTextMap(builder);
	map.put("foo", "bar");
	Set<String> keys = new HashSet<>();
	map.forEach(entry -> keys.add(entry.getKey()));
	assertThat(keys).contains("foo");
	@SuppressWarnings("unchecked")
	MultiValueMap<String, String> natives = (MultiValueMap<String, String>) builder.build().getHeaders().get(NativeMessageHeaderAccessor.NATIVE_HEADERS);
	assertThat(natives).containsKey("foo");
	assertThat(keys).doesNotContain(NativeMessageHeaderAccessor.NATIVE_HEADERS);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-sleuth,代码行数:14,代码来源:MessagingTextMapTests.java

示例7: nativeHeadersAlreadyExist

import org.springframework.messaging.support.NativeMessageHeaderAccessor; //导入依赖的package包/类
@Test
public void nativeHeadersAlreadyExist() {
	MessageBuilder<String> builder = MessageBuilder.withPayload("foo").setHeader(
			NativeMessageHeaderAccessor.NATIVE_HEADERS, new LinkedMultiValueMap<>());
	MessagingTextMap map = new MessagingTextMap(builder);
	map.put("foo", "bar");
	Set<String> keys = new HashSet<>();
	map.forEach(entry -> keys.add(entry.getKey()));
	assertThat(keys).contains("foo");
	@SuppressWarnings("unchecked")
	MultiValueMap<String, String> natives = (MultiValueMap<String, String>) builder.build().getHeaders().get(NativeMessageHeaderAccessor.NATIVE_HEADERS);
	assertThat(natives).containsKey("foo");
	assertThat(keys).doesNotContain(NativeMessageHeaderAccessor.NATIVE_HEADERS);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-sleuth,代码行数:15,代码来源:MessagingTextMapTests.java

示例8: nativeHeaders

import org.springframework.messaging.support.NativeMessageHeaderAccessor; //导入依赖的package包/类
@Test
public void nativeHeaders() {
	Message<String> message = MessageBuilder.withPayload("foo").build();
	MessageBuilder<String> builder = MessageBuilder.fromMessage(message)
			.setHeaders(NativeMessageHeaderAccessor.getMutableAccessor(message));
	MessagingTextMap map = new MessagingTextMap(builder);
	map.put("foo", "bar");
	Set<String> keys = new HashSet<>();
	map.forEach(entry -> keys.add(entry.getKey()));
	assertThat(keys).contains("foo");
	@SuppressWarnings("unchecked")
	MultiValueMap<String, String> natives = (MultiValueMap<String, String>) builder.build().getHeaders().get(NativeMessageHeaderAccessor.NATIVE_HEADERS);
	assertThat(natives).containsKey("foo");
	assertThat(keys).doesNotContain(NativeMessageHeaderAccessor.NATIVE_HEADERS);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-sleuth,代码行数:16,代码来源:MessagingTextMapTests.java

示例9: writeHeaders

import org.springframework.messaging.support.NativeMessageHeaderAccessor; //导入依赖的package包/类
private void writeHeaders(StompCommand command, Map<String, Object> headers, byte[] payload, DataOutputStream output)
		throws IOException {

	@SuppressWarnings("unchecked")
	Map<String,List<String>> nativeHeaders =
			(Map<String, List<String>>) headers.get(NativeMessageHeaderAccessor.NATIVE_HEADERS);

	if (logger.isTraceEnabled()) {
		logger.trace("Encoding STOMP " + command + ", headers=" + nativeHeaders);
	}

	if (nativeHeaders == null) {
		return;
	}

	boolean shouldEscape = (command != StompCommand.CONNECT && command != StompCommand.CONNECTED);

	for (Entry<String, List<String>> entry : nativeHeaders.entrySet()) {
		byte[] key = encodeHeaderString(entry.getKey(), shouldEscape);
		if (command.requiresContentLength() && "content-length".equals(entry.getKey())) {
			continue;
		}
		List<String> values = entry.getValue();
		if (StompCommand.CONNECT.equals(command) &&
				StompHeaderAccessor.STOMP_PASSCODE_HEADER.equals(entry.getKey())) {
			values = Arrays.asList(StompHeaderAccessor.getPasscode(headers));
		}
		for (String value : values) {
			output.write(key);
			output.write(COLON);
			output.write(encodeHeaderString(value, shouldEscape));
			output.write(LF);
		}
	}
	if (command.requiresContentLength()) {
		int contentLength = payload.length;
		output.write("content-length:".getBytes(StompDecoder.UTF8_CHARSET));
		output.write(Integer.toString(contentLength).getBytes(StompDecoder.UTF8_CHARSET));
		output.write(LF);
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:42,代码来源:StompEncoder.java

示例10: getNativeHeaders

import org.springframework.messaging.support.NativeMessageHeaderAccessor; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private Map<String, List<String>> getNativeHeaders(Message<?> message) {
	return (Map<String, List<String>>) message.getHeaders().get(
			NativeMessageHeaderAccessor.NATIVE_HEADERS);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:6,代码来源:HeaderMethodArgumentResolver.java


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