org.mule.runtime.api.message.Message类的使用及代码示例

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

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

Message介绍

[英]Represents a message. The Message is comprised of the payload, (a value and its DataType) and Attributesassociated with the content.
[中]表示一条消息。消息由有效载荷(值及其数据类型)和与内容相关的属性组成。

代码示例

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

@Test
public void testOnlyPayload() {
 Message message = of(TEST_PAYLOAD);
 assertThat(message.getPayload().getValue(), is(TEST_PAYLOAD));
}

代码示例来源: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

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

@Override
protected boolean matchesSafely(Message message) {
 final Object payload = message.getPayload().getValue();
 if (payload instanceof String || payload instanceof CursorStreamProvider || payload instanceof InputStream) {
  // Save the String since we may consume the payload here
  incomingValue = getString(payload);
 } else {
  incomingValue = payload;
 }
 return matcher.matches(incomingValue);
}

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

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

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

@Before
public void setUpTest() throws Exception {
 message = of("");
 event = createTestEvent(message);
 when(mockMuleContext.getConfiguration()).thenReturn(mock(MuleConfiguration.class));
 when(mockMuleContext.getExpressionManager()).thenReturn(mockExpressionManager);
 typedValue = new TypedValue<>(EXPRESSION_VALUE, STRING);
 mockSession = mock(ExpressionManagerSession.class);
 when(mockExpressionManager.openSession(any(), any(), any())).thenReturn(mockSession);
 when(mockSession.evaluate(eq(EXPRESSION), eq(STRING))).thenReturn(typedValue);
 removeVariableProcessor.setMuleContext(mockMuleContext);
}

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

@Benchmark
public CoreEvent deepCopyEventWith50VariablesProperties() {
 return CoreEvent.builder(eventWith50VariablesProperties)
   .message(Message.builder(eventWith50VariablesProperties.getMessage()).build()).build();
}

代码示例来源: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

@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

@Override
public CoreEvent process(CoreEvent event) throws MuleException {
 payloads.add(event.getMessage().getPayload().getValue());
 if (count.incrementAndGet() % 3 == 0) {
  throw new DefaultMuleException("Mule Exception!");
 }
 return null;
}

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

@Override
public CoreEvent process(CoreEvent event) throws MuleException {
 if (event != null && event.getMessage() != null) {
  return CoreEvent.builder(event)
    .message(Message.builder(event.getMessage()).value(event.getMessage().getPayload().getValue() + ":" + label)
      .build())
    .build();
 }
 return event;
}

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

@Override
 public void before(ComponentLocation location, Map<String, ProcessorParameterValue> parameters, InterceptionEvent event) {
  event.message(Message.of(TEST_PAYLOAD));
 }
});

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

@Benchmark
public CoreEvent deepCopyEventWith100VariablesProperties() {
 return CoreEvent.builder(eventWith100VariablesProperties)
   .message(Message.builder(eventWith100VariablesProperties.getMessage()).build()).build();
}

代码示例来源: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

@Test
public void nullPayload() {
 Message message = of(null);
 assertThat(message.getPayload().getDataType().getType(), equalTo(Object.class));
}

代码示例来源: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 mutatePayloadSameTypeConserveTypeAndMimeType() {
 Message message = createTestMessage();
 Message copy = new DefaultMessageBuilder(message).value(NEW_PAYLOAD).build();
 assertThat(copy.getPayload().getValue(), equalTo(NEW_PAYLOAD));
 assertThat(copy.getPayload().getDataType().getType(), equalTo(String.class));
 assertThat(copy.getPayload().getDataType().getMediaType(), is(TEXT));
}

代码示例来源: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 usesCustomEncodingWithNoProperty() throws Exception {
 Message message = Message.builder().value(TEST_PAYLOAD).mediaType(ANY.withCharset(CUSTOM_ENCODING)).build();
 assertThat(message.getPayload().getDataType().getMediaType().getCharset().get(), equalTo(CUSTOM_ENCODING));
 assertCustomEncoding(message);
}

相关文章