public String DynamicHeader(String var1, String var2, String var3, String var4, String var5, Container container) throws StreamTransformationException{
DynamicConfiguration conf = (DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
DynamicConfigurationKey key1 = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/REST","XHeaderName1");
conf.put(key1, var1);
DynamicConfigurationKey key2 = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/REST","XHeaderName2");
conf.put(key2, var2);
DynamicConfigurationKey key3 = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/REST","XHeaderName3");
conf.put(key3, var3);
DynamicConfigurationKey key4 = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/REST","XHeaderName4");
conf.put(key4, var4);
DynamicConfigurationKey key5 = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/REST","XHeaderName5");
conf.put(key5, var5);
return "";
}
package com.pi.browseplan;
import org.json.*; // import jar file attached in the blog
import com.sap.aii.mapping.api.*;
import java.io.*;
import java.util.Map;
public class ParseXMLStructure extends AbstractTransformation {
public void transform(TransformationInput in, TransformationOutput out) throws StreamTransformationException {
try {
InputStream inputstream = in.getInputPayload().getInputStream(); String sourcexml = ""; String targetxml =""; String line="";
BufferedReader br = new BufferedReader( new InputStreamReader(inputstream));
while ((line = br.readLine()) != null)
sourcexml +=line+"\n";
br.close();
// convert the xml Structure to JSON
JSONObject xmlJSONObj = XML.toJSONObject(sourcexml);
String jsonstring = xmlJSONObj.toString(0);
//formatting to convert string in required structure
//Required structure:transid=d&Action=d&BrowsePlanCategory=d&OperatorAlias=dd&RegionAlias=d
jsonstring =jsonstring.replaceAll("\\{", "").replaceAll("\\}","");
jsonstring=jsonstring.replace("\"", "");
jsonstring=jsonstring.replace(":", "=");
jsonstring=jsonstring.replace(",","&");
//If you are getting the response in correct format .you may need to do some changes here as per your //structure.
for(int i=0;i<jsonstring.length();i++)
{
char value=jsonstring.charAt(i);
if(value == '&')
{
jsonstring = jsonstring.substring(i+1,jsonstring.length());
break;
}
}
targetxml=jsonstring.trim();
out.getOutputPayload().getOutputStream().write(targetxml.getBytes());
}
catch (Exception exception) {
getTrace().addDebugMessage(exception.getMessage());
throw new StreamTransformationException(exception.toString());
}
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
8 | |
5 | |
5 | |
4 | |
4 | |
4 | |
4 | |
4 | |
3 | |
3 |