
Sync Interface to get the Document from OpenText via PO 7.5
ICO
Request Mapping with java mapping in the Attributes and Methods Section
public void transform(TransformationInput in, TransformationOutput out) throws StreamTransformationException {
try {
getTrace().addDebugMessage("***OTCS-Request-JavaMapping-Start");
//Get the mapping parameter from ICO
String paramChannel = in.getInputParameters().getString("lookupChannel");
String paramUserName = in.getInputParameters().getString("username");
String paramPassword = in.getInputParameters().getString("password");
String paramBoundary = in.getInputParameters().getString("boundary");
getTrace().addDebugMessage("***OTCS-Step1-LogPramFromICO-lookupChannel:" + paramChannel + "-username:"
+ paramUserName + "-password:" + paramPassword +"-boundary:" + paramBoundary);
//Creating multipart/form-data for OTCS authentication
String LINE_FEED = "\r\n";
String ContentDisposition = "Content-Disposition: form-data; name=\"";
String authReqFormData ="";
authReqFormData = LINE_FEED + paramBoundary + LINE_FEED + ContentDisposition + "username\"" + LINE_FEED
+ LINE_FEED + paramUserName + LINE_FEED + paramBoundary + LINE_FEED +ContentDisposition
+ "password\"" + LINE_FEED + LINE_FEED + paramPassword + LINE_FEED + paramBoundary + "–-" + LINE_FEED;
getTrace().addDebugMessage("***OTCS-Step2-multipart/form-data:" + authReqFormData);
//Read message header value for Receiver
String paramReceiver = in.getInputHeader().getReceiverService();
getTrace().addDebugMessage("***OTCS-Step3-ReceiverService:" + paramReceiver);
//Get the OTCS rest lookup Channel Object for authentication
Channel lookup_channel = LookupService.getChannel(paramReceiver, paramChannel);
//Call rest lookup channel, with multipart/form-data payload
SystemAccessor accessor = null;
accessor = LookupService.getSystemAccessor(lookup_channel);
InputStream authInputStream = new ByteArrayInputStream(authReqFormData.getBytes("UTF-8"));
Payload authPayload = LookupService.getXmlPayload(authInputStream);
Payload tokenOutPayload = null;
//Call lookup
getTrace().addDebugMessage("***OTCS-Step4-CallLookupChannel");
tokenOutPayload = accessor.call(authPayload);
//Parse for Lookup response for token
InputStream authOutputStream = tokenOutPayload.getContent();
DocumentBuilderFactory authfactory = DocumentBuilderFactory.newInstance();
DocumentBuilder authbuilder = authfactory.newDocumentBuilder();
Document authdocument = authbuilder.parse(authOutputStream);
NodeList nlticket = authdocument.getElementsByTagName("ticket");
String tokenTicket = "Empty";
Node node = nlticket.item(0);
if (node != null){
node = node.getFirstChild();
if (node != null){
tokenTicket = node.getNodeValue();
}
}
getTrace().addDebugMessage("***OTCS-Step5-TokenFromLookup:" + tokenTicket);
//Parse input stream and get DataID from SAP
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(in.getInputPayload().getInputStream());
String DataID = doc.getElementsByTagName("DataID").item(0).getTextContent();
getTrace().addDebugMessage("***OTCS-Step6-DataIDFromSAP: " + DataID);
//Create HTTP Header for rest call via setting DynamicConfiguration keys, that can be used in reciver channel
DynamicConfiguration conf = in.getDynamicConfiguration();
DynamicConfigurationKey keytokenTicket = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/REST","HeadertokenTicket");
DynamicConfigurationKey keyDataID = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/REST","HeaderDataID");
conf.put(keytokenTicket, tokenTicket);
conf.put(keyDataID, DataID);
String DummyPayload = "DummyPayload";
// Instantiating output stream to write at Target message
OutputStream os = out.getOutputPayload().getOutputStream();
// writing idoc to output stream
os.write(DummyPayload.getBytes("UTF-8"));
os.flush();
os.close();
getTrace().addDebugMessage("***OTCS-Request-JavaMapping-End");
}
catch (Exception e){
getTrace().addDebugMessage(e.getMessage().toString());
throw new StreamTransformationException(e.getMessage());
}
}
public void transform(TransformationInput in, TransformationOutput out) throws StreamTransformationException {
try
{
getTrace().addDebugMessage("***OTCS-Respose-JavaMapping-Start");
InputStream inputstream = in.getInputPayload().getInputStream();
OutputStream outputstream = out.getOutputPayload().getOutputStream();
//Copy Input Payload into Output xml
byte[] b = new byte[inputstream.available()];
inputstream.read(b);
//Form Output xml
String outputStart = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><ns0:MT_DocContent_Res xmlns:ns0=\"urn://XXXXXXXXXXX.com/OTCS/DocDownload\"><Content>";
String outputEnd = "</Content></ns0:MT_DocContent_Res>";
outputstream.write(outputStart.getBytes("UTF-8"));
outputstream.write(b);
outputstream.write(outputEnd.getBytes("UTF-8"));
outputstream.flush();
outputstream.close();
getTrace().addDebugMessage("***OTCS-Respose-JavaMapping-End");
}
catch (Exception e)
{
getTrace().addDebugMessage(e.getMessage().toString());
throw new StreamTransformationException(e.getMessage());
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
12 | |
9 | |
7 | |
7 | |
5 | |
5 | |
4 | |
4 | |
3 | |
3 |