When I came across this thread (lookup soap inside udf) on the XI forum, initially I thought that it would not be possible to call a Webservice from an user Defined Function. But then I started digging deep and voila I realized that SOAP Lookup's are actually possible and I was wrong! Various blogs on SDN have already discussed options like DB LookUp and RFC Lookup, but there was not much on SOAP Lookup's and maybe one reason why I made that initial mistake of thinking that SOAP Lookup's were not possible.
Sample Business Case:
We need to get the latest Currency Conversion Rate for converting one Currency to another in your mapping. One solution is to do this by making a call to a Webservice that can provide the conversion rate. We can perform Currency Conversion using Value Mapping and many other options, but for the current scenario, let us assume that we need to make a call to a web service from XI and get the corresponding conversion value back. Here we are looking at avoiding a BPM and invoking the web service from Message Mapping using the receiver SOAP adapter.
Solution: This is possible using SOAP Lookup. In my solution, I am using the freely available Currency Converter Webservice (http://www.webservicex.net/CurrencyConvertor.asmx). The Webservice takes the From Currency and To Currency as its input. In our case let us consider that we are getting these inputs from our Source and then need to get the Conversion rate from the Webservice.
UDF:
1.The UDF takes 2 inputs, the From Currency (USD - US Dollar ) and To Currency (INR - Indian Rupee) and returns the Corresponding Conversion rate.
2. Construct the Source / the SOAP request XML inside the UDF by passing the Import parameters as input to the UDF.
3. Use the LookUp API to trigger the SOAP call and get the SOAP response.
4. Parse the SOAP response to get the Conversion Rate.
5. Create a SOAP Communication Channel in the Integration Directory with the correct SOAP URL and SOAP action and proxy settings if any.
Source Code:
import javax.xml.transform.stream.StreamResult;
import com.sap.aii.mapping.lookup.*;
import javax.xml.transform.dom.DOMSource;
import javax.xml.parsers.*;
import org.xml.sax.*;
import org.w3c.dom.*;
import javax.xml.transform.*;
AbstractTrace trace = container.getTrace();
String conversionRate = "";
try {
/*Pass the Business System and Communication Channel as input to the getChannel().
BS_SOAPLOOKUP – Business System*CC_Webservice_SOAP_CURRENCY_CONVERTOR – Receiver SOAP Adapter */
Channel channel = LookupService.getChannel("BS_SOAPLOOKUP","CC_Webservice_SOAP_CURRENCY_CONVERTOR");
SystemAccessor accessor = LookupService.getSystemAccessor(channel);
/* Construct the SOAP Request Message using the InputParameters
FromCurrency , ToCurrency are the Input Parameters.*/
String SOAPxml ="";
InputStream inputStream = new ByteArrayInputStream(SOAPxml.getBytes());
XmlPayload payload = LookupService.getXmlPayload(inputStream);
Payload SOAPOutPayload = null;
/*The SOAP call is made here and the response obtained is in the SOAPOutPayload.*/
SOAPOutPayload = accessor.call(payload);
/* Parse the SOAPPayload to get the SOAP Response back.
The conversion rate is available under the Field Name ConversionRateResult */
InputStream inp = SOAPOutPayload.getContent();
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
/* Create DOM structure from input XML */
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse(inp);
/* ConversionRate is available in the TAG ConversionRateResult in the Response XML */
NodeList list = document.getElementsByTagName("ConversionRateResult");
Node node = list.item(0);
if (node != null) {
node = node.getFirstChild();
if (node != null) {
conversionRate = node.getNodeValue();
}
}
}
catch (Exception e){
trace.addWarning("Error" + e);
}
return conversionRate;
SOAP Adapter Configuration
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
14 | |
11 | |
8 | |
7 | |
5 | |
4 | |
4 | |
4 | |
3 |