org.mule.runtime.api.message.Message.getAttributes()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(10.5k)|赞(0)|评价(0)|浏览(122)

本文整理了Java中org.mule.runtime.api.message.Message.getAttributes()方法的一些代码示例,展示了Message.getAttributes()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Message.getAttributes()方法的具体详情如下:
包路径:org.mule.runtime.api.message.Message
类名称:Message
方法名:getAttributes

Message.getAttributes介绍

[英]Gets the attributes associated with the Message. The Attributes attributes object is specific to the connector that was the source of the current message and is used for obtaining message properties or headers if applicable plus additional information that provides context for the current message such as file size, file name and last modified date for FILE, and origin IP address, query parameters etc. for HTTP.

If there are no attributes associated with the current message, for example if the source of the message was not a connector, then the attributes with be null.
[中]获取与消息关联的属性。Attributes对象特定于作为当前消息源的连接器,用于获取消息属性或标题(如果适用),以及提供当前消息上下文的附加信息,例如文件大小、文件名和文件的上次修改日期,以及源IP地址,HTTP的查询参数等。
如果没有与当前消息关联的属性,例如,如果消息的源不是连接器,则具有的属性将为null。

代码示例

代码示例来源:origin: mulesoft/mule

private void assertTestMessage(Message message) {
 assertThat(message.getPayload().getValue(), is(TEST_PAYLOAD));
 assertThat(message.getPayload().getDataType(), is(TEXT_STRING));
 assertThat(message.getAttributes().getValue(), is(nullValue()));
 assertThat(message.getAttributes().getDataType(), is(OBJECT));
}

代码示例来源:origin: mulesoft/mule

@Test
public void wholeAttributes() {
 Message message = Message.builder().nullValue().attributes(new TypedValue<>(EMPTY_JSON, JSON_STRING)).build();
 assertThat(message.getAttributes().getValue(), equalTo(EMPTY_JSON));
 assertThat(message.getAttributes().getDataType().getType(), equalTo(String.class));
 assertThat(message.getAttributes().getDataType().getMediaType(), is(APPLICATION_JSON));
}

代码示例来源:origin: mulesoft/mule

@Test
 public void attributes() throws Exception {
  Object attributes = mock(Object.class);
  when(message.getAttributes()).thenReturn(new TypedValue<>(attributes, DataType.OBJECT));
  assertThat(evaluate("message.attributes", event), is(sameInstance(attributes)));
 }
}

代码示例来源:origin: mulesoft/mule

@Before
public void setup() throws MuleException {
 when(message.getPayload()).thenReturn(new TypedValue<>(null, DataType.STRING));
 when(message.getAttributes()).thenReturn(new TypedValue<>(null, DataType.STRING));
 event = spy(getEventBuilder().message(message).build());
 when(((PrivilegedMuleContext) context).getErrorTypeLocator()).thenReturn(locator);
}

代码示例来源:origin: mulesoft/mule

private void assertEnemyMessage(HeisenbergExtension heisenberg, int index, Message enemyMessage) {
 assertThat(enemyMessage.getPayload().getValue(), is(heisenberg.getEnemies().get(index)));
 assertThat(enemyMessage.getAttributes().getValue(), is(instanceOf(IntegerAttributes.class)));
 assertThat(((IntegerAttributes) enemyMessage.getAttributes().getValue()).getValue(), is(index));
}

代码示例来源:origin: mulesoft/mule

@Test
public void listenMessages() throws Exception {
 assertThat(latch.await(5, SECONDS), is(true));
 List<Message> payload = capturedPayload.get();
 assertThat(payload, is(notNullValue()));
 assertThat(payload, hasSize(MESSAGES_PER_POLL));
 for (Message message : payload) {
  assertThat(message.getPayload().getValue(), is(instanceOf(String.class)));
  assertThat(message.getAttributes().getValue(), is(instanceOf(DEAOfficerAttributes.class)));
 }
}

代码示例来源:origin: mulesoft/mule

@Test
public void copyPreservesDataType() {
 Apple apple = new Apple();
 long appleSize = 111;
 Message message =
   new DefaultMessageBuilder().payload(new TypedValue(apple, fromObject(apple), OptionalLong.of(appleSize))).build();
 Message copy = new DefaultMessageBuilder(message).build();
 assertThat(copy.getPayload(), is(message.getPayload()));
 assertThat(copy.getAttributes(), is(message.getAttributes()));
 assertThat(message.getPayload().getByteLength().getAsLong(), is(appleSize));
 assertThat(copy.getPayload().getByteLength().getAsLong(), is(appleSize));
}

代码示例来源:origin: mulesoft/mule

@Test
public void createNewMessageViaMessageInterface() {
 Message message = Message.builder().value(TEST_PAYLOAD).build();
 assertThat(message.getPayload().getValue(), is(TEST_PAYLOAD));
 assertThat(message.getPayload().getDataType(), is(STRING));
 assertThat(message.getAttributes().getValue(), is(nullValue()));
}

代码示例来源:origin: mulesoft/mule

@Test
public void createMessageViaMessageInterfaceFromCopy() {
 Message messageCopy = InternalMessage.builder(createTestMessage()).value(true).attributesValue(BASE_ATTRIBUTES).build();
 assertThat(messageCopy.getPayload().getValue(), is(true));
 assertThat(messageCopy.getPayload().getDataType(), is(assignableTo(BOOLEAN)));
 assertThat(messageCopy.getAttributes().getValue(), is(BASE_ATTRIBUTES));
 assertThat(messageCopy.getAttributes().getDataType(), is(BASE_ATTRIBUTES_DATATYPE));
}

代码示例来源:origin: mulesoft/mule

@Test
public void createAPIMessageViaMessageInterfaceFromCopy() {
 org.mule.runtime.api.message.Message message;
 message = org.mule.runtime.api.message.Message.builder().value(TEST_PAYLOAD).build();
 org.mule.runtime.api.message.Message messageCopy;
 messageCopy = org.mule.runtime.api.message.Message.builder(message).value(true).attributesValue(BASE_ATTRIBUTES).build();
 assertThat(messageCopy.getPayload().getValue(), is(true));
 assertThat(messageCopy.getPayload().getDataType(), is(BOOLEAN));
 assertThat(messageCopy.getAttributes().getValue(), is(BASE_ATTRIBUTES));
 assertThat(messageCopy.getAttributes().getDataType(), is(BASE_ATTRIBUTES_DATATYPE));
}

代码示例来源:origin: mulesoft/mule

@Test
public void createOperationParametersWhenEmptyFactory() {
 Map<String, Object> operationParameters = new HashMap<>();
 sourcePointcutFactories.add(mockSourceFactory(true));
 PolicyPointcutParameters sourceParameters =
   parametersManager.createSourcePointcutParameters(component, event.getMessage().getAttributes());
 when(event.getInternalParameter(POLICY_SOURCE_POINTCUT_PARAMETERS)).thenReturn(sourceParameters);
 PolicyPointcutParameters parameters =
   parametersManager.createOperationPointcutParameters(component, event, operationParameters);
 assertThat(parameters.getComponent(), is(component));
 assertThat(parameters.getSourceParameters(), is(of(sourceParameters)));
}

代码示例来源:origin: mulesoft/mule

private void assertMessage(Message message) {
  assertThat(message.getPayload().getValue(), is(""));
  assertThat(message.getAttributes().getValue(), is(attributes));
  assertThat(message.getPayload().getDataType().getType().equals(String.class), is(true));
 }
}

代码示例来源:origin: mulesoft/mule

@Test
public void throwExceptionWhenMoreThanOneSourceFactorySupportsIdentifier() {
 sourcePointcutFactories.add(mockSourceFactory(true));
 sourcePointcutFactories.add(mockSourceFactory(true));
 expectedException.expect(MuleRuntimeException.class);
 parametersManager.createSourcePointcutParameters(component, event.getMessage().getAttributes());
}

代码示例来源:origin: mulesoft/mule

@Test
public void createSourceParametersWhenEmptyFactory() {
 PolicyPointcutParameters parameters =
   parametersManager.createSourcePointcutParameters(component, event.getMessage().getAttributes());
 Map singletonMap = singletonMap(POLICY_SOURCE_POINTCUT_PARAMETERS, parameters);
 when(event.getInternalParameters()).thenReturn(singletonMap);
 assertThat(parameters.getComponent(), is(component));
 assertThat(parameters.getSourceParameters(), empty());
}

代码示例来源:origin: mulesoft/mule

@Test
public void operationReturnsOperationResultWithPayloadAndAttributes() throws Exception {
 Object payload = "hello world!";
 Object attributes = mock(Object.class);
 when(operationExecutor.execute(any(ExecutionContext.class)))
   .thenReturn(just(builder().output(payload).attributes(attributes).build()));
 Message message = messageProcessor.process(event).getMessage();
 assertThat(message, is(notNullValue()));
 assertThat(message.getPayload().getValue(), is(sameInstance(payload)));
 assertThat(message.getAttributes().getValue(), is(sameInstance(attributes)));
 assertThat(message.getPayload().getDataType().getType().equals(String.class), is(true));
}

代码示例来源:origin: mulesoft/mule

@Test
public void operationReturnsOperationResultThatOnlySpecifiesPayload() throws Exception {
 Object payload = "hello world!";
 when(operationExecutor.execute(any(ExecutionContext.class))).thenReturn(just(builder().output(payload).build()));
 event =
   CoreEvent.builder(event).message(Message.builder().value("").attributesValue(mock(Object.class)).build()).build();
 Message message = messageProcessor.process(event).getMessage();
 assertThat(message, is(notNullValue()));
 assertThat(message.getPayload().getValue(), is(sameInstance(payload)));
 assertThat(message.getAttributes().getValue(), is(nullValue()));
 assertThat(message.getPayload().getDataType().getType().equals(String.class), is(true));
}

代码示例来源:origin: mulesoft/mule

@Test
public void voidRouter() throws Exception {
 CoreEvent internalEvent = flowRunner("voidRouter").withPayload("message").withAttributes("other").run();
 assertThat(internalEvent.getMessage().getPayload().getValue(), is("message"));
 assertThat(internalEvent.getMessage().getAttributes().getValue(), is("other"));
 assertThat(internalEvent.getVariables().get("newAttributes"), is(nullValue()));
}

代码示例来源:origin: mulesoft/mule

@Test
public void operationReturnsOperationResultThatOnlySpecifiesPayload() throws Exception {
 Object payload = "hello world!";
 CoreEvent result = delegate.asReturnValue(Result.builder().output(payload).build(), operationContext);
 Message message = getOutputMessage(result);
 assertThat(message.getPayload().getValue(), is(sameInstance(payload)));
 assertThat(message.getAttributes().getValue(), is(nullValue()));
 assertThat(message.getPayload().getDataType().getType().equals(String.class), is(true));
}

代码示例来源:origin: mulesoft/mule

@Test
public void operationReturnsOperationResultThatOnlySpecifiesPayloadAndAttributes() throws Exception {
 Object payload = "hello world!";
 Object newAttributes = mock(Object.class);
 CoreEvent result =
   delegate.asReturnValue(Result.builder().output(payload).attributes(newAttributes).build(), operationContext);
 Message message = getOutputMessage(result);
 assertThat(message.getPayload().getValue(), is(sameInstance(payload)));
 assertThat(message.getAttributes().getValue(), is(sameInstance(newAttributes)));
 assertThat(message.getPayload().getDataType().getType().equals(String.class), is(true));
}

代码示例来源:origin: mulesoft/mule

@Test
public void operationReturnsOperationResultButKeepsAttributes() throws Exception {
 Object payload = new Object();
 MediaType mediaType = ANY.withCharset(getDefaultEncoding(muleContext));
 CoreEvent result =
   delegate.asReturnValue(Result.builder().output(payload).mediaType(mediaType).build(), operationContext);
 Message message = getOutputMessage(result);
 assertThat(message.getPayload().getValue(), is(sameInstance(payload)));
 assertThat(message.getAttributes().getValue(), is(nullValue()));
 assertThat(message.getPayload().getDataType().getMediaType(), equalTo(mediaType));
}

相关文章

微信公众号

最新文章

更多