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

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

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

Message.builder介绍

[英]Provides a builder to create Message objects.
[中]提供用于创建消息对象的生成器。

代码示例

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

/**
 * {@inheritDoc}
 */
@Override
public Message.Builder toMessageBuilder(Map value) {
 return Message.builder().payload(new TypedValue<>(value, getDataType()));
}

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

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

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

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

代码示例来源: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 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 updatesEncodingOnTransformation() throws Exception {
 Message message = Message.builder().value(TEST_PAYLOAD).mediaType(APPLICATION_XML_DEFAULT).build();
 Transformer transformer = mock(Transformer.class);
 when(transformer.isSourceDataTypeSupported(any())).thenReturn(true);
 DataType outputDataType = DataType.builder().type(Integer.class).charset(CUSTOM_ENCODING).build();
 when(transformer.getReturnDataType()).thenReturn(outputDataType);
 when(transformer.transform(anyObject())).thenReturn(Integer.valueOf(1));
 CoreEvent muleEvent = mock(CoreEvent.class);
 Message result = transformationService.applyTransformers(message, muleEvent, singletonList(transformer));
 assertDataType(result, Integer.class, APPLICATION_XML, CUSTOM_ENCODING);
}

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

@Test
public void updatesMimeTypeOnTransformation() throws Exception {
 Message message = Message.builder().value(TEST_PAYLOAD).mediaType(ANY.withCharset(CUSTOM_ENCODING)).build();
 Transformer transformer = mock(Transformer.class);
 when(transformer.isSourceDataTypeSupported(any())).thenReturn(true);
 DataType outputDataType = DataType.builder().type(Integer.class).mediaType(APPLICATION_XML).build();
 when(transformer.getReturnDataType()).thenReturn(outputDataType);
 when(transformer.transform(any(Message.class))).thenReturn(1);
 CoreEvent muleEvent = mock(CoreEvent.class);
 Message result = transformationService.applyTransformers(message, muleEvent, singletonList(transformer));
 assertDataType(result, Integer.class, APPLICATION_XML, CUSTOM_ENCODING);
}

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

@Before
public void before() throws MuleException {
 expressionManager = muleContext.getExpressionManager();
 event = eventBuilder(muleContext).message(Message.builder().value("").attributesValue(attributes).build()).build();
 when(operationContext.getEvent()).thenReturn(event);
 when(operationContext.getMuleContext()).thenReturn(muleContext);
 when(componentModel.getModelProperty(MediaTypeModelProperty.class)).thenReturn(empty());
}

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

@Benchmark
@Threads(Threads.MAX)
public Either<SourcePolicyFailureResult, SourcePolicySuccessResult> source() {
 CoreEvent event;
 Message.Builder messageBuilder = Message.builder().value(PAYLOAD);
 CoreEvent.Builder eventBuilder =
   CoreEvent.builder(create("", "", CONNECTOR_LOCATION, NullExceptionHandler.getInstance())).message(messageBuilder.build());
 event = eventBuilder.build();
 return from(handler.process(event, sourceRpp)).block();
}

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

@Benchmark
@Threads(Threads.MAX)
public Either<SourcePolicyFailureResult, SourcePolicySuccessResult> source() {
 CoreEvent event;
 Message.Builder messageBuilder = Message.builder().value(PAYLOAD);
 CoreEvent.Builder eventBuilder =
   CoreEvent.builder(create("", "", CONNECTOR_LOCATION, NullExceptionHandler.getInstance())).message(messageBuilder.build());
 event = eventBuilder.build();
 return from(handler.process(event, sourceRpp)).block();
}

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

@Override
public void process(Object payload, Object attributes, Consumer<Result> onSuccess, BiConsumer<Throwable, Result> onError) {
 CoreEvent customEvent = CoreEvent.builder(originalEvent)
   .message(Message.builder()
     .payload(TypedValue.of(payload))
     .attributes(TypedValue.of(attributes))
     .build())
   .build();
 doProcess(customEvent, onSuccess, onError);
}

代码示例来源: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 attributesBinding() throws Exception {
 CoreEvent event = getEventWithError(empty());
 SomeAttributes attributes = new SomeAttributes();
 InternalMessage message = (InternalMessage) Message.builder().nullValue().attributesValue(attributes).build();
 when(event.getMessage()).thenReturn(message);
 TypedValue result = expressionLanguage.evaluate(ATTRIBUTES, event, BindingContext.builder().build());
 assertThat(result.getValue(), is(equalTo(attributes)));
 assertThat(result.getDataType().getType(), is((equalTo(SomeAttributes.class))));
}

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

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

@Setup
public void setup() throws Exception {
 muleContext = createMuleContextWithServices();
 muleContext.start();
 flow = createFlow(muleContext);
 registerObject(muleContext, FLOW_NAME, flow, FlowConstruct.class);
 Message.Builder messageBuilder = Message.builder().value(PAYLOAD);
 CoreEvent.Builder eventBuilder =
   CoreEvent.builder(create(flow, CONNECTOR_LOCATION)).message(messageBuilder.build());
 event = eventBuilder.build();
}

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

@Test
public void overridesDataTypeFromPreviousMessageOnCreation() throws Exception {
 Message message = Message.builder().value(1).mediaType(APPLICATION_XML_CUSTOM).build();
 assertDataType(InternalMessage.builder(message).value("TEST").build(), String.class, APPLICATION_XML, CUSTOM_ENCODING);
}

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

private CoreEvent createStreamPayloadEventWithLength(OptionalLong length) throws MuleException {
 return builder(testEvent())
   .message(Message.builder().payload(new TypedValue(new NullInputStream(length.orElse(-1l)), INPUT_STREAM, length))
     .build())
   .build();
}

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

private CoreEvent createStreamPayloadEventWithLength(OptionalLong length) throws MuleException {
 return builder(testEvent())
   .message(Message.builder().payload(new TypedValue(new NullInputStream(length.orElse(-1l)), INPUT_STREAM, length))
     .build())
   .build();
}

相关文章