org.switchyard.Message类的使用及代码示例

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

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

Message介绍

[英]A Message represents an individual input or output of a service, the content of which is interpreted by service implementation logic. A Message does not carry context specific to a service invocation, which means that it can be copied and reused across service invocations.

There are two distinct parts to a message:

  • Content : the main body, or payload, of the message. There is only one body per message instance. The message body is mutable, so message processing logic can access the content, change it (transform, enrich, etc.), and then set it back on the message.
  • Attachments : provide the ability to associate content with a message separate from the main body, allowing it to be parsed independently. One example would be a binary image that is referenced by the main body of the message. The attachment may be too large to be processed in certain services or the service implementation may not be able to parse/interpret it.
    [中]消息表示服务的单个输入或输出,其内容由服务实现逻辑解释。消息不包含特定于服务调用的上下文,这意味着它可以跨服务调用进行复制和重用。
    消息有两个不同的部分:
    *内容:消息的主体或有效载荷。每个消息实例只有一个正文。消息体是可变的,因此消息处理逻辑可以访问内容、更改内容(转换、充实等),然后将其设置回消息。
    *附件:提供将内容与独立于正文的消息相关联的能力,允许对其进行独立解析。一个例子是由消息主体引用的二进制图像。附件可能太大,无法在某些服务中处理,或者服务实现可能无法解析/解释它。

代码示例

代码示例来源:origin: jboss-switchyard/core

@Test
public void testContent() throws Exception {
  final String message = "Hello There!";
  _message.setContent(message);
  Assert.assertEquals(message, _message.getContent());
  // the following tests to make sure casting to same type works
  String content = _message.getContent(String.class);
  Assert.assertEquals(message, content);
}

代码示例来源:origin: org.switchyard.components/switchyard-component-camel-switchyard

/**
 * Map from a camel exchange to a SwitchYard exchange.
 * @param camelExchange the camel exchange
 * @param syExchange the switchyard exchange
 * @param phase ExchangePhase.IN to target camelExchange.getIn(), ExchangePhase.OUT to 
 * target camelExchange.getIn().
 * @return the 
 */
public static org.switchyard.Message mapCamelToSwitchYard(
    org.apache.camel.Exchange camelExchange,
    org.switchyard.Exchange syExchange,
    ExchangePhase phase) {
  
  // Associate the correct Camel message with the SY exchange
  org.switchyard.Message message = syExchange.createMessage();
  org.apache.camel.Message camelMessage =
      mapCamelPropertiesToSwitchYard(camelExchange, message.getContext(), phase);
  message.setContent(camelMessage.getBody());
  
  for (String attachmentName : camelMessage.getAttachmentNames()) {
    message.addAttachment(attachmentName, new HandlerDataSource(camelMessage.getAttachment(attachmentName)));
  }
  
  return message;
}

代码示例来源:origin: org.switchyard.components/switchyard-component-bean

/**
 * {@inheritDoc}
 */
@Override
public Map<String, DataSource> getAttachmentMap() {
  return getMessage().getAttachmentMap();
}

代码示例来源:origin: jboss-switchyard/core

@Test
public void testRemoveAttachment() throws Exception {
  _message.addAttachment("attach1", new DummyDS("attach1", "text/xml"));
  Assert.assertNotNull(_message.getAttachment("attach1"));
  _message.removeAttachment("attach1");
  Assert.assertNull(_message.getAttachment("attach1"));
  
}

代码示例来源:origin: org.switchyard/switchyard-test

@Override
  public Throwable getCause() {
    if (Throwable.class.isAssignableFrom(_faultMessage.getContent().getClass())) {
      return _faultMessage.getContent(Throwable.class);
    } else {
      return super.getCause();
    }
  }
}

代码示例来源:origin: org.switchyard/switchyard-transform

exchange.setUnitOfWork(uow);
uow.start();
exchange.getIn().setBody(message.getContent());
copyProperties(message.getContext(), exchange);
  message.setContent(exchange.getIn().getBody(QNameUtil.toJavaMessageType(getTo())));
} else {
  message.setContent(exchange.getIn().getBody());

代码示例来源:origin: org.switchyard.components/switchyard-component-camel-switchyard

/**
 * Maps a SwitchYard exchange to a Camel exchange.  Keep in mind that the camel message created
 * during mapping is *not* associate with the exchange.  You need to call setIn() or setOut() 
 * with the returned reference depending on your use case.
 * @param syExchange switchyard exchange
 * @param camelExchange camel exchange
 * @return mapped camel message
 */
public static DefaultMessage mapSwitchYardToCamel(
    org.switchyard.Exchange syExchange,
    org.apache.camel.Exchange camelExchange) {
  
  DefaultMessage camelMessage = new SwitchYardMessage();
  camelMessage.setBody(syExchange.getMessage().getContent());
  
  mapSwitchYardPropertiesToCamel(syExchange.getContext(), camelExchange, camelMessage);
  
  for (String attachmentName : syExchange.getMessage().getAttachmentMap().keySet()) {
    camelMessage.addAttachment(attachmentName, 
        new DataHandler(syExchange.getMessage().getAttachment(attachmentName)));
  }
  
  return camelMessage;
}

代码示例来源:origin: org.switchyard.components/switchyard-component-bean

/**
 * {@inheritDoc}
 */
@Override
public Message setContent(Object content) {
  return getMessage().setContent(content);
}

代码示例来源:origin: org.switchyard.components/switchyard-component-common-camel

message.setContent(content);
    message.addAttachment(entry.getKey(), entry.getValue().getDataSource());

代码示例来源:origin: org.switchyard.components/switchyard-component-bean

/**
 * {@inheritDoc}
 */
@Override
public Context getContext() {
  return getMessage().getContext();
}

代码示例来源:origin: org.switchyard.components/switchyard-component-common-camel

/**
   * {@inheritDoc}
   */
  @Override
  public CamelBindingData decompose(Exchange exchange, CamelBindingData target) throws Exception {
    Message sourceMessage = exchange.getMessage();
    getContextMapper().mapTo(exchange.getContext(), target);

    org.apache.camel.Message targetMessage = target.getMessage();

    if (!sourceMessage.getAttachmentMap().isEmpty()) {
      for (Entry<String, DataSource> entry : sourceMessage.getAttachmentMap().entrySet()) {
        targetMessage.addAttachment(entry.getKey(), new DataHandler(entry.getValue()));
      }
    }

    ServiceOperation operation = exchange.getContract().getProviderOperation();
    target.getMessage().getExchange().setProperty(OPERATION_NAME, operation.getName());
    target.getMessage().getExchange().setProperty(FAULT_TYPE, operation.getFaultType());
    target.getMessage().getExchange().setProperty(SERVICE_NAME, exchange.getProvider().getName());

    targetMessage.setBody(sourceMessage.getContent());
    return target;
  }
}

代码示例来源:origin: org.switchyard/switchyard-test

@Override
public void handleMessage(final Exchange exchange) throws HandlerException {
  _messages.offer(exchange);
  
  if (_behavior == null || exchange.getContract().getProviderOperation().getExchangePattern().equals(ExchangePattern.IN_ONLY)) {
    return;
  }
  
  switch (_behavior) {
  case FORWARD_IN_TO_OUT :
    exchange.send(exchange.getMessage().copy());
    break;
  case FORWARD_IN_TO_FAULT :
    exchange.sendFault(exchange.getMessage().copy());
    break;
  case REPLY_WITH_OUT :
    exchange.send(exchange.createMessage().setContent(_replyContent));
    break;
  case REPLY_WITH_FAULT :
    exchange.sendFault(exchange.createMessage().setContent(_replyContent));
    break;
  }
}

代码示例来源:origin: jboss-switchyard/core

@Test
public void testGetAttachmentMap() throws Exception {
  _message.addAttachment("attach1", new DummyDS("attach1", "text/xml"));
  _message.addAttachment("attach2", new DummyDS("attach1", "text/xml"));
  Map<String, DataSource> attachments = _message.getAttachmentMap();
  // make sure the attachments we added are in the map
  Assert.assertTrue(attachments.containsKey("attach1"));
  Assert.assertTrue(attachments.containsKey("attach2"));
  // make sure that modifications to the map are not reflected in the message
  // (i.e.) the returned map is not a direct reference 
  attachments.remove("attach1");
  Assert.assertNotNull(_message.getAttachment("attach1"));
}

代码示例来源:origin: org.switchyard.components/switchyard-component-sca

Message invokeMsg = exchange.getMessage().copy();
exchange.getContext().mergeInto(invokeMsg.getContext());
  replyHandler.waitForOut();
  if (ex.getMessage() != null) {
    Message replyMsg = ex.getMessage().copy();
    ex.getContext().mergeInto(replyMsg.getContext());
    if (ExchangeState.FAULT.equals(ex.getState())) {
      exchange.sendFault(replyMsg);

代码示例来源:origin: jboss-switchyard/core

@Test
public void testAddAttachment() throws Exception {
  _message.addAttachment("attach1", new DummyDS("attach1", "text/xml"));
  Assert.assertNotNull(_message.getAttachment("attach1"));
}

代码示例来源:origin: org.switchyard/switchyard-test

private void addAttachments(Message message) {
  for (Map.Entry<String, DataSource> entry : _attachments.entrySet()) {
    message.addAttachment(entry.getKey(), entry.getValue());
  }
}

代码示例来源:origin: org.switchyard.components/switchyard-component-bean

/**
 * {@inheritDoc}
 */
@Override
public Message copy() {
  return getMessage().copy();
}

代码示例来源:origin: jboss-switchyard/core

@Override
  public Throwable getCause() {
    if (Throwable.class.isAssignableFrom(_faultMessage.getContent().getClass())) {
      return _faultMessage.getContent(Throwable.class);
    } else {
      return super.getCause();
    }
  }
}

代码示例来源:origin: jboss-switchyard/core

Message msg = exchange.createMessage().setContent(input);
msg.getContext().setProperty(Exchange.CONTENT_TYPE, typeName);
msg.setContent(input);
Object content = invokerHandler.getFaults().poll().getMessage().getContent();
Assert.assertTrue(content instanceof HandlerException);

代码示例来源:origin: org.switchyard.components/switchyard-component-soap

if (message.getContent() == null) {
  throw SOAPMessages.MESSAGES.unableToCreateSOAPBodyDueToNullMessageContent();
if (message.getContent() instanceof SOAPMessage) {
  return new SOAPBindingData((SOAPMessage)message.getContent());
  Node messageNode = message.getContent(Node.class);
  if (messageNode != null) {
    Node messageNodeImport = soapMessage.getSOAPBody().getOwnerDocument().importNode(messageNode, true);
      for (String name : message.getAttachmentMap().keySet()) {
        AttachmentPart apResponse = soapMessage.createAttachmentPart();
        apResponse.setDataHandler(new DataHandler(message.getAttachment(name)));
        apResponse.setContentId("<" + name + ">");
        soapMessage.addAttachmentPart(apResponse);
      && exchange.getMessage().getContent() instanceof Exception) {
    throw exchange.getMessage().getContent(Exception.class);

相关文章