本文整理了Java中org.springframework.integration.support.AbstractIntegrationMessageBuilder
类的一些代码示例,展示了AbstractIntegrationMessageBuilder
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。AbstractIntegrationMessageBuilder
类的具体详情如下:
包路径:org.springframework.integration.support.AbstractIntegrationMessageBuilder
类名称:AbstractIntegrationMessageBuilder
暂无
代码示例来源:origin: spring-projects/spring-integration
@Override
public Message<?> fromSyslog(Message<?> message) throws Exception {
Map<String, ?> map = this.transformer.doTransform(message);
Map<String, Object> out = new HashMap<String, Object>();
for (Entry<String, ?> entry : map.entrySet()) {
String key = entry.getKey();
if (!SYSLOG_PAYLOAD_ENTRIES.contains(key)) {
out.put(SyslogHeaders.PREFIX + entry.getKey(), entry.getValue());
}
}
return getMessageBuilderFactory().withPayload(this.asMap ? map : message.getPayload())
.copyHeaders(out)
.build();
}
代码示例来源:origin: spring-projects/spring-integration
private Message<?> createServiceUnavailableResponse() {
if (logger.isDebugEnabled()) {
logger.debug("Endpoint is stopped; returning status " + HttpStatus.SERVICE_UNAVAILABLE);
}
return this.getMessageBuilderFactory().withPayload("Endpoint is stopped")
.setHeader(org.springframework.integration.http.HttpHeaders.STATUS_CODE, HttpStatus.SERVICE_UNAVAILABLE)
.build();
}
代码示例来源:origin: spring-projects/spring-integration
private Message<?> buildMessage(Map<String, Object> headers, Object messageOrPayload,
EvaluationContext methodInvocationEvaluationContext) {
AbstractIntegrationMessageBuilder<?> builder =
(messageOrPayload instanceof Message)
? this.messageBuilderFactory.fromMessage((Message<?>) messageOrPayload)
: this.messageBuilderFactory.withPayload(messageOrPayload);
builder.copyHeadersIfAbsent(headers);
// Explicit headers in XML override any @Header annotations...
if (!CollectionUtils.isEmpty(GatewayMethodInboundMessageMapper.this.headerExpressions)) {
Map<String, Object> evaluatedHeaders = evaluateHeaders(methodInvocationEvaluationContext,
GatewayMethodInboundMessageMapper.this.headerExpressions);
builder.copyHeaders(evaluatedHeaders);
}
// ...whereas global (default) headers do not...
if (!CollectionUtils.isEmpty(GatewayMethodInboundMessageMapper.this.globalHeaderExpressions)) {
Map<String, Object> evaluatedHeaders = evaluateHeaders(methodInvocationEvaluationContext,
GatewayMethodInboundMessageMapper.this.globalHeaderExpressions);
builder.copyHeadersIfAbsent(evaluatedHeaders);
}
if (GatewayMethodInboundMessageMapper.this.headers != null) {
builder.copyHeadersIfAbsent(GatewayMethodInboundMessageMapper.this.headers);
}
return builder.build();
}
代码示例来源:origin: spring-projects/spring-integration
@Override
public Message<?> toMessage(Object object, @Nullable Map<String, Object> headers) throws Exception {
if (object instanceof Message<?>) {
return (Message<?>) object;
}
return object != null
? this.messageBuilderFactory.withPayload(object).copyHeadersIfAbsent(headers).build()
: null;
}
代码示例来源:origin: spring-projects/spring-integration
public AbstractIntegrationMessageBuilder<T> pushSequenceDetails(Object correlationId, int sequenceNumber,
int sequenceSize) {
Object incomingCorrelationId = this.getCorrelationId();
List<List<Object>> incomingSequenceDetails = getSequenceDetails();
if (incomingCorrelationId != null) {
if (incomingSequenceDetails == null) {
incomingSequenceDetails = new ArrayList<>();
}
else {
incomingSequenceDetails = new ArrayList<>(incomingSequenceDetails);
}
incomingSequenceDetails.add(Arrays.asList(incomingCorrelationId,
getSequenceNumber(), getSequenceSize()));
incomingSequenceDetails = Collections.unmodifiableList(incomingSequenceDetails);
}
if (incomingSequenceDetails != null) {
setHeader(IntegrationMessageHeaderAccessor.SEQUENCE_DETAILS, incomingSequenceDetails);
}
return setCorrelationId(correlationId)
.setSequenceNumber(sequenceNumber)
.setSequenceSize(sequenceSize);
}
代码示例来源:origin: spring-projects/spring-integration
@Override
public Message<?> transform(Message<?> message) {
AbstractIntegrationMessageBuilder<?> builder = this.getMessageBuilderFactory().fromMessage(message);
if (this.patternMatch) {
builder.removeHeaders(this.headersToRemove);
}
else {
for (String headerToRemove : this.headersToRemove) {
builder.removeHeader(headerToRemove);
}
}
return builder.build();
}
代码示例来源:origin: spring-projects/spring-integration
private void publish(Object object) {
Message<?> message = null;
if (object instanceof Message) {
message = (Message<?>) object;
}
else {
message = getMessageBuilderFactory().withPayload(object).build();
}
sendMessage(message);
}
}
代码示例来源:origin: spring-projects/spring-integration
.copyHeadersIfAbsent(headers);
messageBuilder = this.getMessageBuilderFactory().withPayload(payload).copyHeaders(headers);
messageBuilder.setHeader(org.springframework.integration.http.HttpHeaders.REQUEST_METHOD,
method.toString());
.setHeader(org.springframework.integration.http.HttpHeaders.REQUEST_URL,
httpEntity.getUrl().toString())
.setHeader(org.springframework.integration.http.HttpHeaders.USER_PRINCIPAL,
servletRequest.getUserPrincipal())
.build();
if (getStatusCodeExpression() != null) {
reply = getMessageBuilderFactory().withPayload(e.getMessage())
.setHeader(org.springframework.integration.http.HttpHeaders.STATUS_CODE,
evaluateHttpStatus(httpEntity))
.build();
.setHeader(org.springframework.integration.http.HttpHeaders.STATUS_CODE,
HttpStatus.INTERNAL_SERVER_ERROR)
.build();
代码示例来源:origin: spring-projects/spring-integration
protected Message<?> buildReturnedMessage(org.springframework.amqp.core.Message message,
int replyCode, String replyText, String exchange, String routingKey, MessageConverter converter) {
Object returnedObject = converter.fromMessage(message);
AbstractIntegrationMessageBuilder<?> builder = (returnedObject instanceof Message)
? this.getMessageBuilderFactory().fromMessage((Message<?>) returnedObject)
: this.getMessageBuilderFactory().withPayload(returnedObject);
Map<String, ?> headers = getHeaderMapper().toHeadersFromReply(message.getMessageProperties());
if (this.errorMessageStrategy == null) {
builder.copyHeadersIfAbsent(headers)
.setHeader(AmqpHeaders.RETURN_REPLY_CODE, replyCode)
.setHeader(AmqpHeaders.RETURN_REPLY_TEXT, replyText)
.setHeader(AmqpHeaders.RETURN_EXCHANGE, exchange)
.setHeader(AmqpHeaders.RETURN_ROUTING_KEY, routingKey);
}
Message<?> returnedMessage = builder.build();
if (this.errorMessageStrategy != null) {
returnedMessage = this.errorMessageStrategy.buildErrorMessage(new ReturnedAmqpMessageException(
returnedMessage, message, replyCode, replyText, exchange, routingKey), null);
}
return returnedMessage;
}
代码示例来源:origin: spring-projects/spring-integration
public AbstractIntegrationMessageBuilder<T> setSequenceNumber(Integer sequenceNumber) {
return setHeader(IntegrationMessageHeaderAccessor.SEQUENCE_NUMBER, sequenceNumber);
}
代码示例来源:origin: spring-projects/spring-integration
@Override
protected Object doTransform(Message<?> message) throws Exception {
if (this.targetClass != null) {
return this.jsonObjectMapper.fromJson(message.getPayload(), this.targetClass);
}
else {
Object result = this.jsonObjectMapper.fromJson(message.getPayload(), message.getHeaders());
AbstractIntegrationMessageBuilder<Object> messageBuilder = this.getMessageBuilderFactory().withPayload(result)
.copyHeaders(message.getHeaders())
.removeHeaders(JsonHeaders.HEADERS.toArray(new String[3]));
return messageBuilder.build();
}
}
代码示例来源:origin: spring-projects/spring-integration
@Override
public final Message<?> transform(Message<?> message) {
try {
Assert.notNull(message, "Message must not be null");
Object payload = message.getPayload();
Assert.notNull(payload, "Message payload must not be null");
Assert.isInstanceOf(File.class, payload, "Message payload must be of type [java.io.File]");
File file = (File) payload;
T result = this.transformFile(file);
Message<?> transformedMessage = getMessageBuilderFactory().withPayload(result)
.copyHeaders(message.getHeaders())
.setHeaderIfAbsent(FileHeaders.ORIGINAL_FILE, file)
.setHeaderIfAbsent(FileHeaders.FILENAME, file.getName())
.build();
if (this.deleteFiles) {
if (!file.delete() && this.logger.isWarnEnabled()) {
this.logger.warn("failed to delete File '" + file + "'");
}
}
return transformedMessage;
}
catch (Exception e) {
throw new MessagingException(message, "failed to transform File Message", e);
}
}
代码示例来源:origin: spring-projects/spring-integration
@Override
protected Object handleRequestMessage(Message<?> requestMessage) {
PollableChannel gatherResultChannel = new QueueChannel();
Object gatherResultChannelName = this.replyChannelRegistry.channelToChannelName(gatherResultChannel);
Message<?> scatterMessage = getMessageBuilderFactory()
.fromMessage(requestMessage)
.setHeader(GATHER_RESULT_CHANNEL, gatherResultChannelName)
.setReplyChannel(this.gatherChannel)
.build();
this.messagingTemplate.send(this.scatterChannel, scatterMessage);
Message<?> gatherResult = gatherResultChannel.receive(this.gatherTimeout);
if (gatherResult != null) {
return getMessageBuilderFactory()
.fromMessage(gatherResult)
.removeHeader(GATHER_RESULT_CHANNEL)
.setHeader(MessageHeaders.REPLY_CHANNEL, requestMessage.getHeaders().getReplyChannel())
.build();
}
return null;
}
代码示例来源:origin: spring-projects/spring-integration
protected void fromSoapHeaders(MessageContext messageContext, AbstractIntegrationMessageBuilder<?> builder) {
WebServiceMessage request = messageContext.getRequest();
String[] propertyNames = messageContext.getPropertyNames();
if (propertyNames != null) {
for (String propertyName : propertyNames) {
builder.setHeader(propertyName, messageContext.getProperty(propertyName));
}
}
if (request instanceof SoapMessage) {
SoapMessage soapMessage = (SoapMessage) request;
Map<String, ?> headers = this.headerMapper.toHeadersFromRequest(soapMessage);
if (!CollectionUtils.isEmpty(headers)) {
builder.copyHeaders(headers);
}
}
}
代码示例来源:origin: spring-projects/spring-integration
getMessageBuilderFactory()
.fromMessage((Message<Object>) payload)
.copyHeadersIfAbsent(headers);
getMessageBuilderFactory()
.withPayload(payload)
.copyHeaders(headers);
messageBuilder.setHeader(org.springframework.integration.http.HttpHeaders.REQUEST_URL,
request.getURI().toString());
HttpMethod httpMethod = request.getMethod();
if (httpMethod != null) {
messageBuilder.setHeader(org.springframework.integration.http.HttpHeaders.REQUEST_METHOD,
httpMethod.toString());
.map(principal ->
messageBuilder
.setHeader(org.springframework.integration.http.HttpHeaders.USER_PRINCIPAL, principal))
.defaultIfEmpty(messageBuilder)
.map(AbstractIntegrationMessageBuilder::build)
代码示例来源:origin: spring-projects/spring-integration
Message<?> message1 = MutableMessageBuilder.withPayload("test")
.setCorrelationId(1)
.setSequenceNumber(1)
.setSequenceSize(2)
.copyHeadersIfAbsent(headers1)
.build();
Map<String, Object> headers2 = new HashMap<>();
headers2.put("k1", "bar");
assertNotNull(result);
assertTrue(result instanceof AbstractIntegrationMessageBuilder<?>);
Message<?> resultMessage = ((AbstractIntegrationMessageBuilder<?>) result).build();
assertNull(resultMessage.getHeaders().get("k1"));
assertNull(resultMessage.getHeaders().get("k2"));
message2 = MutableMessageBuilder.withPayload("test")
.setCorrelationId(1)
.setSequenceNumber(2)
.setSequenceSize(2)
.copyHeadersIfAbsent(headers2)
.build();
messages = Arrays.asList(message1, message2);
group = new SimpleMessageGroup(messages, 1);
result = processor.processMessageGroup(group);
resultMessage = ((AbstractIntegrationMessageBuilder<?>) result).build();
assertNull(resultMessage.getHeaders().get("k1"));
assertNull(resultMessage.getHeaders().get("k2"));
代码示例来源:origin: spring-projects/spring-integration
@Override
public final Message<?> transform(Message<?> message) {
Object result = this.messageProcessor.processMessage(message);
if (result == null) {
return null;
}
if (result instanceof Message<?>) {
return (Message<?>) result;
}
MessageHeaders requestHeaders = message.getHeaders();
return getMessageBuilderFactory()
.withPayload(result)
.filterAndCopyHeadersIfAbsent(requestHeaders,
this.selectiveHeaderPropagation ? this.notPropagatedHeaders : null)
.build();
}
代码示例来源:origin: spring-projects/spring-integration
public AbstractIntegrationMessageBuilder<T> popSequenceDetails() {
List<List<Object>> incomingSequenceDetails = getSequenceDetails();
if (incomingSequenceDetails == null) {
return this;
}
else {
incomingSequenceDetails = new ArrayList<>(incomingSequenceDetails);
}
List<Object> sequenceDetails = incomingSequenceDetails.remove(incomingSequenceDetails.size() - 1);
Assert.state(sequenceDetails.size() == 3, "Wrong sequence details (not created by MessageBuilder?): "
+ sequenceDetails);
setCorrelationId(sequenceDetails.get(0));
Integer sequenceNumber = (Integer) sequenceDetails.get(1);
Integer sequenceSize = (Integer) sequenceDetails.get(2);
if (sequenceNumber != null) {
setSequenceNumber(sequenceNumber);
}
if (sequenceSize != null) {
setSequenceSize(sequenceSize);
}
if (!incomingSequenceDetails.isEmpty()) {
setHeader(IntegrationMessageHeaderAccessor.SEQUENCE_DETAILS, incomingSequenceDetails);
}
else {
removeHeader(IntegrationMessageHeaderAccessor.SEQUENCE_DETAILS);
}
return this;
}
代码示例来源:origin: spring-projects/spring-integration
private void processMapArgument(Object messageOrPayload, boolean foundPayloadAnnotation,
Map<String, Object> headersToPopulate, Map<?, ?> argumentValue) {
if (messageOrPayload instanceof Map && !foundPayloadAnnotation) {
if (GatewayMethodInboundMessageMapper.this.payloadExpression == null) {
throw new MessagingException("Ambiguous method parameters; found more than one " +
"Map-typed parameter and neither one contains a @Payload annotation");
}
}
copyHeaders(argumentValue, headersToPopulate);
}
代码示例来源:origin: spring-projects/spring-integration
messageBuilder = getMessageBuilderFactory()
.withPayload(result)
.copyHeaders(message.getHeaders());
result = messageBuilder.popSequenceDetails();
内容来源于网络,如有侵权,请联系作者删除!