on 06-07-2007 2:19 PM
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!
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
remove the message mapping from your interface mapping
and try onky java mapping and see the result
Regards,
michal
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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
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.
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.
User | Count |
---|---|
94 | |
11 | |
11 | |
10 | |
9 | |
8 | |
6 | |
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.