cancel
Showing results for 
Search instead for 
Did you mean: 

Java Mapping - ClassCastException SAX

Former Member
0 Kudos

Hi experts,

I am developing a Java mapping program for a very specific situation. I chose to do that using SAX API, but I found a problem with that.

The following lines are throwing a ClassCastException during the mapping test in the Enterprise Service Builder (PI 7.1 EHP 4):


public void transform(TransformationInput in, TransformationOutput out) throws StreamTransformationException {
try {
	InputPayload inputPayload = in.getInputPayload();
	InputStream inputStream = inputPayload.getInputStream();

	OutputPayload outputPayload = out.getOutputPayload();
	OutputStream outputStream = outputPayload.getOutputStream();

	// create a TransformerHandler for producing XML output
	SAXTransformerFactory factory = (SAXTransformerFactory) SAXTransformerFactory.newInstance();
	TransformerHandler th = factory.newTransformerHandler();
	Result result = new StreamResult(outputStream);
	th.setResult(result);
// ...

I copied most of that from [this|http://www.sdn.sap.com/irj/scn/weblogs?blog=/pub/wlg/4143] [original link is broken]; article.

After some tests, I realise that the Exception occurs in this line:


SAXTransformerFactory factory = (SAXTransformerFactory) SAXTransformerFactory.newInstance();

I believe that's because the method newInstance is returning something that cannot be converted into a SAXTransformerFactory, but I could not find another way from using the TransformerHandler that not doing so.

Is there anyway to fix that problem? Do you have other samples of SAX mapping?

Thanks anyway.

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

Experts, the problem was solved using DOM.

Anyway, I will take a look at the tutorials.

Thanks anyway.

stefan_grube
Active Contributor
0 Kudos

In my opinion the code in the blog is wrong.

It should not be SAXTransformerFactory but SAXParserFactory

See tutorial of SUN:

http://download.oracle.com/docs/cd/E17409_01/javase/tutorial/jaxp/sax/parsing.html

and a different blog:

/people/sankararao.bhatta/blog/2008/07/27/java-mapping-secrets-revealed

VijayKonam
Active Contributor
0 Kudos

Check if you J2EE engine of PI system has those API classes. If not you might have to deploy those classes first or need to use DOM or something else that is available by default.

VJ