-
1. Re: Buffering values between actions
jbuechel Jan 3, 2011 8:07 AM (in response to jbuechel)I got a bit further.. A possible approach could be:
1. Saving the original request message body to another payload location (e.g. test-payload).
2. Before sending the response back to System1 the relevant value could be read from the test-payload and written to the message body of org.jboss.soa.esb.message.defaultEntry.
Step 1 is done.
How could be done step 2?
- e.g. read from test-payload and write/merge the relevant data to org.jboss.soa.esb.message.defaultEntry location using an XSLT or smooks action?
-
2. Re: Buffering values between actions
jbuechel Jan 3, 2011 1:30 PM (in response to jbuechel)I finally came up with the following solution (if somebody knows a simpler approach, please let us know):
Smooks configuration:
<?xml version="1.0" encoding="UTF-8"?><!--This freemaker configuration adds the value of the bean${ncoInstanceIdBean} to the relevant ESB message. The bean${ncoInstanceIdBean} is actually of type String and is being createdand populated withincom.frox.itsm.ncinv.consumer.ItsmResponseProcessor--><ftl:freemarker applyOnElement="ncoInstanceId"><ftl:template><!--${ncoInstanceIdBean}--></ftl:template><ftl:use><ftl:inline directive="addto" /></ftl:use></ftl:freemarker></smooks-resource-list><?xml version="1.0" encoding="UTF-8"?> <smooks-resource-list xmlns="http://www.milyn.org/xsd/smooks-1.1.xsd" xmlns:ftl="http://www.milyn.org/xsd/smooks/freemarker-1.1.xsd"> <ftl:freemarker applyOnElement="ncoInstanceId"> <ftl:template><!--${ncoInstanceIdBean}--></ftl:template> <ftl:use> <ftl:inline directive="addto" /> </ftl:use> </ftl:freemarker> </smooks-resource-list>
ESB action implementation:
public Message process(Message message) throws ActionProcessingException { try { // Get the original request from the name body ConfigTree treeOrigRequest = ConfigTree.fromXml(message.getBody() .get(Constants.NAMED_BODY_ORIGINAL_REQUEST).toString()); // Extract the ncoInstanceId String ncoInstanceId = treeOrigRequest .getFirstTextChild(NCO_INSTANCE_ID_ELEMENT_NAME); // Smook transformation using a freemaker template Smooks smooks = new Smooks(getClass().getResourceAsStream( SMOOKS_CONFIG_LOCATION)); ExecutionContext executionContext = smooks.createExecutionContext(); BeanRepository.getInstance(executionContext).addBean( NCO_INSTANCE_ID_BEAN, ncoInstanceId); StringResult result = new StringResult(); smooks.filterSource(executionContext, new StringSource(message .getBody().get().toString()), result); // Add the result to the message body message.getBody().add(result.getResult()); } catch (IOException e1) { e1.printStackTrace(); } catch (SAXException e1) { e1.printStackTrace(); } return message; }
-
3. Re: Buffering values between actions
beve Jan 4, 2011 2:39 AM (in response to jbuechel)Hi Jonas,
just a note about performance. You can safely cache and reuse the Smooks Object. Initialization of Smooks takes some time and therefore it is important that it is reused.
Regards,
/Daniel
-
4. Re: Buffering values between actions
jbuechel Jan 4, 2011 3:16 AM (in response to beve)Hi Daniel,
thanks for your hint! That makes sense..
Very appreciated!
Kind regards
Jonas