如何在camel处理器中调用unmarshal()?

时间:2016-11-14 11:45:41

标签: java apache-camel unmarshalling

骆驼路线:

from(source)          
    .idempotentConsumer(simple("${in.header.CamelFilePath}"), redisIdempotentRepository)
    .process(pgpDecryptionProcessor)
    .to(destination);

PGPDecryptionProcessor:

public class PGPDecryptionProcessor implements Processor {

  @Autowired
  private PGPEncryptionManager pgpEncryptionManager;

  @Override
  public void process(Exchange exchange) throws Exception {
     //do something to check whether it is encrypted 
     //get corrsponding dataformat for decryption
     processDefinition.unmarshal(dataFormat);  //How do i get processDefinition here
    }
  }
} 

我需要致电ProcessDefinition.unmarshal(dataformat)。如何在进程方法中获取ProcessDefinition对象?

1 个答案:

答案 0 :(得分:2)

您可以使用ExchangeExchange.getIn().getBody(InputStream.class)作为另一个参数直接调用数据格式的解组:

dataformat.unmarshal(exchange, exachange.getIn().getBody(InputStream.class));

您不需要致电ProcessDefinition.unmarshal(); ProcessDefinition仅定义要使用的数据格式,最后当您的消息出现时,Dataformat.unmarshal()方法会被ExchangeBody InputStream调用。