cancel
Showing results for 
Search instead for 
Did you mean: 

XML Schema validation Error

Former Member
0 Kudos

Hi,

Have a scenerio in which consecutive mapping needs to be done.The first mapping is a Java Mapping in which XML schema validation needs to be done.

If XML Schema validation is sucessful(Mapping 1),then graphical message mapping(MM_Entry) needs to be performed.

I have uploded a jar file in imported Archives which contains

1)Schema file(inputSchema.xsd): This is an XSD file which is generated in XI....XSD fomat of Source message type

2) The java Class file

Following are few lines of code for better idea:

public class SAXParser implements StreamTransformation {

public void execute(InputStream input, OutputStream output) throws StreamTransformationException {

.

.

.

SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();

InputStream mySchema = this.getClass().getClassLoader().getResourceAsStream("inputSchema.xsd");

SAXParser saxParser = saxParserFactory.newSAXParser();

saxParser.setProperty("http://java.sun.com/xml/jaxp/properties/schemaLanguage", "http://www.w3.org/2001/XMLSchema");

saxParser.setProperty("http://java.sun.com/xml/jaxp/properties/schemaSource",mySchema);

saxParser.parse(input, new HandlerBase());

.

.

.

}

}

After above step(parsing),input is copied to output and streams are closed as follows:

byte[] buf = new byte[4096];

for(int len=-1;(len=input.read(buf))!=-1;)

output.write(buf,0,len);

input.close();

output.close();

After sending correct source message from input ,i am getting following error:

Runtime exception occurred during execution of application mapping program com/sap/xi/tf/_MM_Entry_: com.sap.aii.utilxi.misc.api.BaseRuntimeException; Parsing an empty source. Root element expected!

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi,

This is because your java code is not returning the output string after validation.

If this is just for schema validation, after validating, create the copy intput stream into the output stream.

Regards

Pushkar

Former Member
0 Kudos

Hi Pushkar ,

i have already copied the details to output stream in following code

byte[] buf = new byte[4096];

for(int len=-1;(len=input.read(buf))!=-1;)

output.write(buf,0,len);

But it didnt work

MichalKrawczyk
Active Contributor
0 Kudos

Hi,

remove the message mapping from your interface mapping

and try onky java mapping and see the result

Regards,

michal

Former Member
0 Kudos

Hi Michal,

With only java mapping,i get the response message...regardless whether the source message is correct or wrong

Former Member
0 Kudos

hi Amit,

I am encountering the same error - "Root Element Expected". Did you ever get to resolve your issue? If you did, please let me know.

Thank you,

Badari

ravi_raman2
Active Contributor
0 Kudos

The issue is with this line...

InputStream mySchema = this.getClass().getClassLoader().getResourceAsStream("inputSchema.xsd");

i dont believe the class is being parsed...as thats why its failing to detect the file as a xml file or its not finding the file..Hence the missing root element..

Hope that helps

Regards

Ravi Raman

Former Member
0 Kudos

Hi,

Your problem is that once you've validated the inputStream you've read it to the end. When you then start writing it to the outputstream you start writing from the end of the stream - thus nothing is written!

What you need to do is to for instance read the content of the inputstream into a byte[] and from there into a byteinputstream. This way you can read the input several times and reset the starting position whenever needed.

Best Regards,

Daniel

henrique_pinto
Active Contributor
0 Kudos

Amit,

Daniel is right on the problem, but there is no need to rewrite the inputstream to a buffer.

Just use <i>input.reset();</i> method before the copying method and it will go back to the start byte.

Also, don't close the streams!!! You only do that when the streams are defined in your own code, but this is not the case (the streams come as parameters from calling application). Remove both <i>input.close();</i> and <i>output.close();</i> lines.

Regards,

Henrique.

Former Member
0 Kudos

Yes, but I don't believe the reset method is supported (at least not in my environment). It will just give you an IOException - thats why i mentioned the buffer.

Best Regards,

Daniel

henrique_pinto
Active Contributor
0 Kudos

Hey Daniel,

What's your XI version/SP level?

I've successfully used InputStream.reset() method in PI 7.0 SP 10.

Regards,

Henrique.

Former Member
0 Kudos

Hi Henrique,

I'm on 2004s SP 12. Whether its supported or not depends on the concrete implementation i believe - usually it is by default not supported.

Best Regards,

Daniel

henrique_pinto
Active Contributor
0 Kudos

Daniel,

As I've said, I've used it successfully in PI 7.0 SP10.

You're right about documentation, it says that by default, Java 1.4.2 mark() and reset() methods of InputStream class are not fully implemented (mark() would do nothing and reset() would always throw an IOException). And that would be the expected behavior...

...unless the SAP developers have extended the InputStream class to include actual implementatios to the mark() and reset() methods.

I'm not saying that they have, but it would be possible, wouldn't it?

It does work, after all...

Regards,

Henrique.