Java - Spring Ws - 在XSD文件中加载相对包含(Tomcat 8) [英] Java - Spring Ws - Loading Relative Includes in XSD files (Tomcat 8)

查看:713
本文介绍了Java - Spring Ws - 在XSD文件中加载相对包含(Tomcat 8)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个Spring Web服务,它使用以下代码从一组XSD文件创建动态WSDL:

I created a Spring web service which creates a dynamic WSDL from a collection of XSD files using the following code:

Resource[] schema = {
            new ClassPathResource(
                    "schema/service/XCPD.SupportMaterials.v9/schema/HL7V3/NE2008/coreschemas/NarrativeBlock.xsd"),
            new ClassPathResource(
                    "schema/service/XCPD.SupportMaterials.v9/schema/HL7V3/NE2008/coreschemas/datatypes-base.xsd"),
            new ClassPathResource(
                    "schema/service/XCPD.SupportMaterials.v9/schema/HL7V3/NE2008/coreschemas/infrastructureRoot.xsd"),
            new ClassPathResource(
                    "schema/service/XCPD.SupportMaterials.v9/schema/HL7V3/NE2008/multicacheschemas/PRPA_IN201305UV02.xsd"),
            new ClassPathResource(
                    "schema/service/XCPD.SupportMaterials.v9/schema/HL7V3/NE2008/multicacheschemas/PRPA_IN201306UV02.xsd"),
            new ClassPathResource(
                    "schema/service/XCPD.SupportMaterials.v9/schema/IHE/XCPD_PLQ.xsd"),
            new ClassPathResource(
                    "schema/service/XCPD.SupportMaterials.v9/schema/HL7V3/XCPD_PRPA.xsd") };
    CommonsXsdSchemaCollection collection = new CommonsXsdSchemaCollection(
            schema);
    collection.setInline(true);
    return collection;

用于创建动态WSDL的XSD文件包括使用include语句的其他各种模式文件,如下所示:

The XSD files used to create the dynamic WSDL include other various schema files using include statements like the following:

<xs:include schemaLocation="../coreschemas/voc.xsd"/>
<xs:include schemaLocation="../coreschemas/datatypes.xsd"/>

当我在Tomcat 8容器中运行代码时,收到以下异常:

When I run the code in a Tomcat 8 container, I receive the following exception:

Caused by: java.lang.IllegalArgumentException: The resource path [/../coreschemas/infrastructureRoot.xsd] has been normalized to [null] which is not valid

Spring的URI解析器在路径前面加上/,即使这样被引用的文件是相对路径(不是绝对路径),并且在导入模式时失败。

Spring's URI resolver prepends the "/" in front of the path, even though this file being referenced is a relative path (not an absolute path) and fails when importing the schema.

应该注意的是,这个应用程序在Tomcat 7上运行正常。当尝试将其迁移到Tomcat 8时,问题就出现了。

It should be noted that this application ran fine on Tomcat 7. When trying to migrate it to Tomcat 8, the issues are arising.

Tomcat 8确实改变了现在加载Web资源的方式。 来自Java CodeRanch的更多信息 ...

Tomcat 8 did change the way how web resources are now being loaded. More Information from Java CodeRanch...

任何方式长话短说,有没有办法强制Spring,URI解析器应该正确处理相关文件?如果我查看解析器Spring使用的collectionBaseURI属性(ClasspathUriResolver),则此值为null。有没有办法设置这个基本URI?

Any ways long story short, is there a way to force Spring that the URI resolver should treat relative files correctly? If I look at the "collectionBaseURI" property on the resolver Spring uses (ClasspathUriResolver), this value is null. Is there a way to set this base URI as well?

编辑我可以通过将所有相对路径转换为模式的绝对路径来解决此问题...但是我不想在数百个文件中应用此修复。

EDIT I can fix this issue by converting all relative paths to absolute paths to schemas... however I don't want to apply this fix across hundreds of files.

推荐答案

如果有人遇到这个烦人的话问题, ClasspathUriResolver 是罪魁祸首,在相对路径包含前加上/。我将其切换为使用默认的URI解析器(在 org.apache.ws.commons.schema.resolver.DefaultURIResolver 中),它在Tomcat 8上运行正常。 / p>

In case anyone runs into this annoying issue, the ClasspathUriResolver was the culprit, prepending a "/" on relative path includes. I switched it over to use a default URI Resolver (in org.apache.ws.commons.schema.resolver.DefaultURIResolver) and it runs fine without issue on Tomcat 8.

CommonsXsdSchemaCollection collection = new CommonsXsdSchemaCollection(schema);
collection.setUriResolver(new DefaultURIResolver());
collection.setInline(true);
return collection;

这篇关于Java - Spring Ws - 在XSD文件中加载相对包含(Tomcat 8)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆