on 09-14-2009 9:54 AM
Hi Experts,
I have created an custom adapter module to convert simple XML to PDF file using file adapter.I had followed following blog: http://www.sdn.sap.com/irj/scn/weblogs;jsessionid=(J2EE3417500)ID0648258750DB00688708990918350431End...
Flow is :
Target XML -> Adapter -> Our Custom Module -> CALLSAPAdapter
I had used following code to retrieve data from Adapter:
InputStream in = null;
in = (InputStream) inputModuleData.getPrincipalData();
But when i am executing the scenario, i am getting following error:
MP: exception caught with cause java.lang.ClassCastException: class com.sap.aii.adapter.xi.ms.XIMessage:service:com.sap.aii.adapter.xi.svc< >com.sap.engine.boot.loader.ResourceMultiParentClassLoader< >533ded59< >alive incompatible with class java.io.InputStream:null
Please help!
Thanks,
Mayank
try
/Fetch the PrincipalData
msg = (Message)inputModuleData.getPrincipalData();
// get the main document as XMLPayload.
XMLPayload xmlpayload = msg.getDocument();
//get the content as String.
String xmltxt = xmlpayload.getText();
then parse that string using java dom parser to get the value from particular tags like name and lastanme
try using (you should know how to use dom parser to parse the XML) declare nessasary classes reference like DocumentBuilder
InputStream inputStream = new ByteArrayInputStream(xmltxt.getBytes("UTF-8"));
Document doc = builder.parse(inputStream);
NodeList list = doc.getElementsByTagName("name");
String name=list.item(0).getFirstChild().getNodeValue();
list = doc.getElementsByTagName("lastname");
String lastname= list.item(0).getFirstChild().getNodeValue();
Edited by: Kubra fatima on Sep 15, 2009 11:31 AM
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
As i am trying to create an PDF file, my code for adding PDF document is:
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
// creation of a document-object
com.lowagie.text.Document document = new com.lowagie.text.Document();
PdfWriter.getInstance(document,oos);
<logic to write to the document>
document.close();
inputModuleData.setPrincipalData(oos);
Do i have to change anything in it, in order to avoid classcastexception.
Thanks,
Mayank
Hello Mayank,
InputStream in = null;
in = (InputStream) inputModuleData.getPrincipalData();
You need to assing the content returned by getPrincipalData() to reference of Message class. Assigning it to Stream class results the type cast Exception.
try this
Message msg=(Message) inputModuleData.getPrincipalData();
Regards,
Prasanna
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Explaination:
you are not properly casting
inputmoduledata.getPrincipalData();
it returns object class type
cast from object class type to Mesage class type
msg = (Message) obj;
calling getDocument(); method of Message class
XMLPayload xp = msg.getDocument();
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
InputStream in = null;
in = (InputStream) inputModuleData.getPrincipalData();
change your code as
Object obj = null;
Message msg = null;
obj = inputModuleData.getPrincipalData();
msg = (Message) obj;
XMLPayload xp = msg.getDocument();
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
84 | |
25 | |
12 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.