cancel
Showing results for 
Search instead for 
Did you mean: 

Internal Reference for External Definitions

Former Member
0 Kudos

Guys,

I'm implementing a schema validation mapping which requires access to the .xsd schema definition file. It's already imported in XI under External Definitions tab.

It didn't work to refer just to the string in "Source" field of the external definition. If I put the .xsd in a path and refer to this file, the mapping works OK.

I wanted to refer to the .xsd which is already imported and not have to reupload the .xsd to a folder in the file system.

Does anyone know how I can refer it? If not directly, at least someone knows which is the folder where the external definitions are located?

Regards,

Henrique.

Accepted Solutions (1)

Accepted Solutions (1)

henrique_pinto
Active Contributor
0 Kudos

Stephan,

I've tried to do as you say but I'm getting an exception.

I'm using it like:

this.getClass().getResource("/Schemas/schema.xsd").getPath();

but it gives me a java.lang.NullPointerException at that line (it's not resolving the resource name).

How is the proper way of doing it?

Regards,

Henrique.

franz_forsthofer
Employee
Employee
0 Kudos

Hello Henrique,

you can use

InputStream is = this.getClass().getClassLoader().getResourceAsStream("/Schemas/schema.xsd");

Regards Franz

henrique_pinto
Active Contributor
0 Kudos

Franz,

thank you for your reply.

I tried getResourceAsStream on Eclipse but it throws me an error because my .xsd has references to other .xsds (which need to be in the same folder to work). When I read the resource as stream, it simplely doesn't maintain the association with the included .xsds.

I use .getResource().getPath() on Eclipse and it works just fine (including the association part). But it doesn't seem to work in XI...

Any help would be welcome.

Thanks,

Henrique.

henrique_pinto
Active Contributor
0 Kudos

Guys,

initially I was working on this scenario as a test, to learn how to perform Schema Validations in XI.

In the project I'm now, though, I had a real request to perform a schema validation in XI. Maintaing the .xsd files in a single location was the prefered scenario. If not possible, at least they should be maintained in the same interface (meaning, Integration Builder). Maintaing .xsd files in IB and in a folder in File System was the worst case scenario.

Again, the .xsd files I'm using refers to other .xsd files in the same folder (through import and/or include tags in the .xsd).

For more info on Schema Validations, check: http://help.sap.com/saphelp_nw2004s/helpdata/en/c4/e1343e8c7f6329e10000000a114084/frameset.htm.

So, I did a little research on how to resolve references inside streamed inputs and finally was able to solve it.

The thing here is to create a class that implements the EntityResolver interface, and in the resolveEntity method, you use it like this:

...
public MappingEntityResolver implements EntityResolver {

  public InputSource resolveEntity (String publicId, String systemId) throws SAXException, IOEXception {
    return new InputSource(this.getClass().getResourceAsStream("/Schemas/"+systemId));
  }

}
...

For it to work, you'll need to maintain the .xsd files in the /Schemas folder inside your .jar file. Also, in the /Schemas folder, you have to maintain the same reference paths that are inside the .xsds. For example, if your top-level .xsd (the one you define in SchemaSource property) is "source.xsd" which internally imports or includes a "references/type1.xsd", in your .jar, the source.xsd file will need to be in /Schemas folder and the type1.xsd will need to be in Schemas/references folder.

In your code, then, you'll just need to set that EntityResolver in your DocumentBuilder object.

...
docBuilder.setEntityResolver(new MappingEntityResolver());
...

Also, I was able to succesfully implement this with DOM parser, but I failed to make it work with SAX Parser (actually, I failed to make any validation with SAX Parser work in XI, no matter whether it had external references or not).

Regards,

Henrique.

Answers (5)

Answers (5)

henrique_pinto
Active Contributor
0 Kudos

Thank you for your inputs.

Regards,

Henrique.

henrique_pinto
Active Contributor
0 Kudos

Any news on this? Im still not able to do that.

Former Member
0 Kudos

Hi Henrique,

in case of nested .xsd files, in XI in IR .....you will have to import all the .xsd files and then in the main .xsd file, in the source field - just give the name of the .xsd file.

Do this for all your XSD files -in the source field - just give the name of the .xsd file.

now in main .xsd file in external references, you should see the source-name pair columns filled completely.....now refer to source msg of main .xsd from msg interface and then use it in your mapping in IR.

Thanks,

Rajeev Gupta

henrique_pinto
Active Contributor
0 Kudos

Have you anchieved that in Java mappings?

My java mappings could not resolve any external references (the source fields provided correctly, as I've told before) at all, prior to PI 7.0 SP8.

As Stephan said (meaning, SAP said ), it's not supported by XI.

Regards,

Henrique.

Former Member
0 Kudos

Hi Henrique,

Sorry i have not invoked External Definition having external ref in java mapping.....

by following the above procedure which i have said, you can have the complete xsd in ED.....Then in msg mapping, take the msg of ED and do a graphical mapping for it......

Thanks,

Rajeev Gupta

bhavesh_kantilal
Active Contributor
0 Kudos

Henrique,.

We have Accessed a property File inside our Java Mapping.We made sure that the same path was available in all environments. It was the physical path of the file available on the XI server.

We made sure that the folder and the file has a 777 on the Xi server including all the other folders in the same path.

Does this info help?

Regards

Bhavesh

henrique_pinto
Active Contributor
0 Kudos

> Hi Henrique,

>

> Sorry i have not invoked External Definition having

> external ref in java mapping.....

>

> by following the above procedure which i have said,

> you can have the complete xsd in ED.....Then in msg

> mapping, take the msg of ED and do a graphical

> mapping for it......

>

> Thanks,

> Rajeev Gupta

Heya Rajeev,

thanks for your help.

As per the message mappings and message interfaces, I have the complete .xsd file correctly defined. The problem is how to use that external definition in a java mapping.

Regards,

Henrique.

henrique_pinto
Active Contributor
0 Kudos

> Henrique,.

>

> We have Accessed a property File inside our Java

> Mapping.We made sure that the same path was available

> in all environments. It was the physical path of the

> file available on the XI server.

>

> We made sure that the folder and the file has a 777

> on the Xi server including all the other folders in

> the same path.

>

> Does this info help?

>

> Regards

> Bhavesh

Hey Bhavesh,

thanks for your help.

As I had told, I have also succeded in accessing the .xsd files from file system. I wanted to access the .xsd files directly from the external definitions, since it's easier to maintain the files in a single location and that the developer won't necessarily need access to the file system.

Regards,

Henrique.

Former Member
0 Kudos

Hi Henrique,

I'm working a lot with external definitions and in general it works just fine. I'm not sure if I understood your problem correctly. Are you having troubles resolving the external references in the XSDs that you import under 'External Defintions'? If this is the case, you have to specify the 'Source' (as you already mentioned in your posting) in the XSD that is getting referenced by another XSD and this source needs to be exactly as it is stated in the 'include' statement of the referencing XSD.

E.g. if your 'main' Schema has an include statement like this

<xs:include schemaLocation="Error_Type.xsd" />

the included Schema needs to be imported as External Defintion and its source has to be named 'Error_Type.xsd'. You can always check in the External References tab whether all of the references could be resolved.

If this was not your issue, then maybe you can explain it again

regards,

Peter

henrique_pinto
Active Contributor
0 Kudos

Peter,

I'm referencing the external definition in a java mapping. So, for the java mapping, I need to refer the whole path for the .xsd file. I tried to use just the name of the file (as defined in the Source field of the External Definition) but it gave the error that Ananth pointed above.

Regards,

Henrique.

Former Member
0 Kudos

Hi Henrique,

I am sorry but your scenario is not supported. There is no way to access the data you have uploaded as External Definition from a mapping program.

The only advice I can give to you, is to put that file as resource into a jar-file, upload that jar-file as an Imported Archive and then access it as a resource from your mapping program.

However, this will mean that you have to upload the XSD twice (once as External Definition and once as part of an Imported Archive).

BTW: When you do your transformation in a java mapping, I am curious why you upload the xsd as External Definition at all. The most common use of an External Definition is to use it as source or target structure of a Message Mapping.

Greetings

Stephan

henrique_pinto
Active Contributor
0 Kudos

Stephan,

thank you for your help. I'll do as you say, and reimport them as resources of the .jar.

As for the external definitions, I am using them for message definion (message interfaces, message mappings, etc). The java mapping that I implemented is for schema validation, and that's why I need to access the .xsd.

Regards,

Henrique.

Former Member
0 Kudos

Hi Henrique,

In one of our interface we had an DTD for validating XML and we got an Error while testing the mapping. The error gave us the location in which it was looking for DTD file.

It was something like this :<b>D:\usr\sap\XXX\DVEBMGS00\j2ee\cluster\server0\XXXXXXX.dtd</b>

Regards,

Ananth

henrique_pinto
Active Contributor
0 Kudos

Ananth,

I get that error too if I just use the name of the .xsd as the complete path for the file (for example, "test.xsd"). I guess it just points to the root directory of that server. It doesn't necessarily means that the external definitions are located there. But thanks anyway. 🐵

Regards,

Henrique.

henrique_pinto
Active Contributor
0 Kudos

no one?

Henrique.