Pre-Processing/Post-Processing Services with Mashups
Pre-processing and post-processing for services commonly involves tasks such as decoding encrypted data, encrypting data, decompressing or compressing data, filtering data or data scrubbing. You can handle these types of requirements with a mashup that uses scripting to invoke pre- or post-processing code.
Tip: it is a good practice to design pre- or post-processing code as its own service that can be invoked by many mashups.
Pre-processing Mashup
To implement pre-processing you must:
Write the logic to handle pre-processing as a Java class or use Java libraries, as needed.
Add the custom Java classes to the classpath for the EMML Reference Runtime Engine. Copy them to the web-apps-home/emml/WEB-INF/classes folder or add them in a JAR to the web-apps-home/emml/WEB-INF/lib folder.
Restart the EMML Engine.
Create a mashup script with the following components:
<input> variables, as needed, to receive the data to be pre-processed and an <output> variable for the result. For example:
... <operation name="getreviews"> <input name="userId" type="string" default="someone@myOrg.com" /> <input name="accessId" type="string" default="xOtPy9Sy7JCI3Y8aNqEkZBxmkPQw/ZH8"/> <output name="result" type="string"/>Add a <script> statement to call the pre-processing logic.
This example uses JavaScript scripting and shows an encryption class that decrypts the accessId input parameter. To call the pre-processing logic in JavaScript, you must use fully qualified class names starting with the Packages keyword.
... <output name="result" type="string" inputvariables="$accessId" outputvariable="$accessId"/> <script type="text/javascript"> <![CDATA[ var encrypter = new Packages.com.myOrg.services.Encrypter("My Pass Phrase!") accessId = encrypter.decrypt(accessId); ]]> </script>Invoke the service with the pre-processed data. For example:
... </script> <directinvoke endpoint="http://ecs.amazonaws.com/onca/xml?Service=AWSECommerceService" method="GET" AWSAccessKeyId="$accessId" Version="2009-01-15" Operation="ListSearch" ListType="WishList" Email="some.body@my.company.com" outputvariable="$result"/>
Post-processing Mashup
At its simplest, any mashup that invokes a service and performs an action using the result is providing service post-processing. To implement post-processing logic that is directly provided by mashup script statements, you must:
Write the logic to handle the post-processing as a Java class or use Java libraries, as needed.
Add the custom Java classes to the classpath for the EMML Reference Runtime Engine. Copy them to the web-apps-home/emml/WEB-INF/classes folder or add them in a JAR to the web-apps-home/emml/WEB-INF/lib folder.
Restart the EMML Engine.
Create a mashup script with the following components:
<variable>s , as needed, to receive the results from the service or other data to be post-processed and an <output> variable for the result. For example:
... <operation name="encryptResult"> <variable name="svcResult" type="document"/> <output name="result" type="string"/>
Invoke the service. For example:
... <output name="result" type="string"/> <directinvoke endpoint="http://ecs.amazonaws.com/onca/xml?Service=AWSECommerceService" method="GET" AWSAccessKeyId="xOtPy9Sy7JCI3Y8aNqEkZBxmkPQw/ZH8" Version="2009-01-15" Operation="ListSearch" ListType="WishList" Email="some.body@my.company.com" outputvariable="$svcResult"/> <filter /> <constructor outputvariable="$svcResult"> <ns:mylist>{$svcResult/ns:ListSearchResponse/ns:Lists/ns:List}</ns:mylist> </constructor>
Add a <script> statement to call the post-processing logic.
This example uses JavaScript scripting. It shows an encryption class that encrypts the filtered and constructed results from the service. To call the post-processing logic in JavaScript, you must use fully qualified class names starting with the Packages keyword.
... </constructor> <script type="text/javascript" inputvariables="$svcResult" outputvariable="$result"> <![CDATA[ var encrypter = new Packages.com.myOrg.services.Encrypter("My Pass Phrase!") result = encrypter.encrypt(svcResult); ]]> </script> ...
Enterprise Mashup Markup Language (EMML) Documentation is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.
