2017-07-17 11 views
1

以下の問題については、 を呼び出すことができます。入力オブジェクトをマップオブジェクトおよび呼び出しハンドラに変換するためにトランスフォーマを呼び出すと、その前に追加されたヘッダ値がハンドラにありません。 ペイロードをマップオブジェクトに変換すると、すべてのヘッダーが失われるのはなぜですか?Spring統合DSLトランス

//Adding header here setHeader("t", "t"); 
    @ResponseBody 
    public EmResponse getAuditTrail(@Valid @RequestBody NGAuditTrailEntry auditEntry) { 
     LOG.info("Audit Service Called, creating new audit " + auditEntry); 
     AuditCreationFlow.CreateAuditGateway auditGateway = applicationContext.getBean(AuditCreationFlow.CreateAuditGateway.class); 
     MessageBuilder messageBuilder = MessageBuilder.withPayload(auditEntry).setHeader("t", "t"); 
     Object response = auditGateway.createAudit(messageBuilder.build()); 
     EmResponse res = new EmResponse(); 
     LOG.info("Done with Audit creation. Response " + response); 
     return res; 
    } 

//Integration flow starts here 
     public IntegrationFlow createAuditGatewayFlow() { 
       LOG.debug("Entered to spring integration flow to create the Audit entry"); 
       return IntegrationFlows.from("auditInputChannel") 
         .handle(auditObjTransformer, "transformToEjbCompatible") 
         .handle(ejbCaller, "callEjb") 
         .get(); 
    } 

//Transforming payload object to map 
    @Component 
    public class AuditObjTransformer { 
     private final Logger LOG = LoggerFactory.getLogger(this.getClass()); 
     @Transformer 
     public Object transformToEjbCompatible(NGAuditTrailEntry ngAuditTrailEntry, Map<String, Object> headers){ 
      LOG.debug("Transforming the NGAuditTrailEntry To AuditEntry object which is EJB compatible"); 
      //@TODO - Tranformation code goes here. 

      String s = ngAuditTrailEntry.getObjectName(); 
      Map<String, String> m = new HashMap<>(); 
      m.put("x", s); 
      return m; 
     } 

//Here in this handler, not getting headers what I added in the rest service above. 

    public class EJBCaller { 
    private final Logger LOG = LoggerFactory.getLogger(this.getClass()); 
    public Object callEjb(Object payload, Map<String, Object> headers) throws EJBResponseException{ 
     LOG.debug("Calling Audit EJB to crated Audit entry."); 
     //@TODO EJB calling code goese here. 
     LOG.debug("Returned from EJB after creating Audit entry. Returned value" + payload); 
     return payload; 
    } 

トランスフォームがマップ以外の場合は、ヘッダーに問題はありません。

おかげで、 シヴァ

答えて

1
callEjb(Object payload, Map<String, Object> headers) 

ペイロードがMapある場合は、あなたが持っている​​内のペイロードと同時にheadersメソッドの引数。それは働いて作り、正確headersあなたがそれに@Headersアノテーションを使うべきであるMap引数に運ぶために

* Annotation which indicates that a method parameter should be bound to the headers of a 
* message. The annotated parameter must be assignable to {@link java.util.Map} with 
* String keys and Object values. 
+0

働いていた、あなたのビランありがとう – Sdubba

関連する問題