org.apache.camel.Message.addAttachment()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(5.2k)|赞(0)|评价(0)|浏览(154)

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

Message.addAttachment介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

// Note: Content Type - might need treatment!
public class AttachmentAttacher{
  public void process(Exchange exchange){
   Message in = exchange.getIn();
   byte[] file = in.getBody(byte[].class);
   String fileId = in.getHeader("CamelFileName",String.class);
   in.addAttachment(fileId, new DataHandler(file,"plain/text"));
  }
}

代码示例来源:origin: org.switchyard.quickstarts/switchyard-soap-mtom

@Override
public void process(Exchange exchange) throws Exception {
  String newFileName = "internal-resized-switchyard.jpeg";
  Image input = exchange.getIn().getBody(Image.class);
  exchange.getOut().addAttachment(newFileName, new DataHandler(input, "image/jpeg"));
  exchange.getOut().setBody(newFileName);
}

代码示例来源:origin: org.switchyard.quickstarts/switchyard-soap-mtom

@Override
public void process(Exchange exchange) throws Exception {
  String newFileName = "resized-switchyard.jpeg";
  Image input = exchange.getIn().getBody(Image.class);
  if (input == null) {
    throw new RuntimeException("Image for resize not found!");
  }
  Image img = ImageIO.read(Classes.getResourceAsStream("switchyard.jpeg"));
  exchange.getOut().addAttachment(newFileName, new DataHandler(img, "image/jpeg"));
  exchange.getOut().setBody(newFileName);
}

代码示例来源:origin: org.switchyard.quickstarts/switchyard-soap-mtom

@Override
public void process(Exchange exchange) throws Exception {
  String newFileName = "internal-switchyard.jpeg";
  Image input = exchange.getIn().getBody(Image.class);
  if (input == null) {
    throw new RuntimeException("Image for resize not found!");
  }
  ContentType type = new ContentType("image/jpeg");
  exchange.getOut().addAttachment(newFileName, new DataHandler(input, type.getBaseType()));
  exchange.getOut().setBody(newFileName);
}

代码示例来源:origin: stackoverflow.com

import javax.activation.DataHandler;
import javax.mail.util.ByteArrayDataSource;

import org.apache.camel.Exchange;
import org.apache.camel.Message;
import org.apache.camel.Processor;

public class AttachmentAttacher implements Processor {

 private final String mimetype;

 public AttachmentAttacher(String mimetype) {
  this.mimetype = mimetype;
 }

 @Override
 public void process(Exchange exchange){
  Message in = exchange.getIn();
  byte[] file = in.getBody(byte[].class);
  String fileId = in.getHeader("CamelFileName",String.class);
  in.addAttachment(fileId, new DataHandler(new     ByteArrayDataSource(file, mimetype)));
 }
}

代码示例来源:origin: org.apache.servicemix/servicemix-camel

/**
 * Copies content, headers, security subject and attachments from the JBI NormalizedMessage to the Camel Message.
 * 
 * @param from the source {@link NormalizedMessage}
 * @param to the target {@link Message}
 */
public void copyFromJbiToCamel(NormalizedMessage from, Message to) {
  to.setBody(from.getContent());
  Subject securitySubject = from.getSecuritySubject();
  if (securitySubject != null) {
    to.setHeader(SECURITY_SUBJECT, securitySubject);
  }
  Exchange exchange = to.getExchange();
  for (Object object : from.getPropertyNames()) {
    String key = object.toString();
    Object value = from.getProperty(key);
    if (!strategies.applyFilterToCamelHeaders(key, value, exchange)) { 
      to.setHeader(key, value);
    }
  }
  for (Object id : from.getAttachmentNames()) {
    to.addAttachment(id.toString(), from.getAttachment(id.toString()));
  }
}

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

/**
   * {@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.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;
  }
}

相关文章