// check to make sure the message body gets added back in properly MockEndpointresultEndpoint= getMockEndpoint("mock:result"); resultEndpoint.expectedMessageCount(1); resultEndpoint.message(0).body().isEqualTo(body);
// check to make sure the claim check is added to the message and // the body is removed MockEndpointtestCheckpointEndpoint= getMockEndpoint("mock:testCheckpoint"); testCheckpointEndpoint.expectedMessageCount(1); testCheckpointEndpoint.expectedHeaderReceived("claimCheck", "123"); testCheckpointEndpoint.message(0).body().isNull();
// START SNIPPET: e2 publicstaticfinalclassCheckLuggageBean { publicvoidcheckLuggage(Exchange exchange, @Body String body, @XPath("/order/@custId") String custId) { // store the message body into the data store, using the custId as // the claim check dataStore.put(custId, body); // add the claim check as a header exchange.getIn().setHeader("claimCheck", custId); // remove the body from the message exchange.getIn().setBody(null); } } // END SNIPPET: e2
// START SNIPPET: e3 publicstaticfinalclassDataEnricherBean { publicvoidaddDataBackIn(Exchange exchange, @Header("claimCheck") String claimCheck) { // query the data store using the claim check as the key and add the // data // back into the message body exchange.getIn().setBody(dataStore.get(claimCheck)); // remove the message data from the data store dataStore.remove(claimCheck); // remove the claim check header exchange.getIn().removeHeader("claimCheck"); } } // END SNIPPET: e3 }
claimCheck 方法
claimCheck 操作
使用此 EIP 时,您必须指定要使用的操作,可以是以下各项:
Get - 通过给定键获取(不删除)声明检查。
GetAndRemove - 通过给定键获取和删除声明检查。
Set - 使用给定的密钥设置一个新的(如果密钥已经存在,将覆盖)声明检查。
Push - 在堆栈上设置新的声明检查(不使用密钥)。
Pop - 从堆栈中获取最新的声明检查(不使用密钥)。
使用 Get、GetAndRemove 或 Set 操作时,您必须指定一个键。然后,这些操作将使用此密钥存储和检索数据。您可以使用它在不同的键中存储多个数据。