cancel
Showing results for 
Search instead for 
Did you mean: 

ClassCastException in custom adapter module

former_member204873
Contributor
0 Kudos

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

Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
0 Kudos

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

former_member204873
Contributor
0 Kudos

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

prasannakrishna_mynam
Contributor
0 Kudos

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

Former Member
0 Kudos

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();

former_member204873
Contributor
0 Kudos

hi fatima,

Suppose if i have a payload like:

<record>

<name>xyz</name>

<lastname>xyz</lastname>

</record>

This is the payload generated after mapping i.e (target side) and i want to read value of name and lastname from the payload, how to read required values in process method?

Former Member
0 Kudos

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();