【问题标题】:SOAP path resolution for dependent XSD-file not understood无法理解相关 XSD 文件的 SOAP 路径解析
【发布时间】:2020-03-03 17:32:15
【问题描述】:

我有两个 XSD 文件,一个导入到另一个。检索 WSDL(通过 SoapUI)时,找不到导入的 xsd 文件。

Error loading [http://localhost:8294/authentication/shared-environment.xsd]:
org.apache.xmlbeans.XmlException: org.apache.xmlbeans.XmlException: error: 
Unexpected end of file after null

这两个 xsd 文件位于同一个文件夹中:

src/main/resources
 - auth-attributes.xsd
 - shared-environment.xsd

“auth-attributes.xsd”如下所示:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
    targetNamespace="http://dto.shared.auth.appl.com"
    xmlns:Q1="http://dto.shared.auth.appl.com"
    xmlns:Q3="http://dto.common.appl.com" elementFormDefault="qualified">

    <xs:import namespace="http://dto.common.appl.com"
        schemaLocation="shared-environment.xsd" />
.........
.........
.........

WS-Adapter 是这样定义的:

@EnableWs
@Configuration
public class BackendServerConfig extends WsConfigurerAdapter {
    @Bean 
    ServletWebServerFactory servletWebServerFactory(){
        return new TomcatServletWebServerFactory();
    }

    @Bean
    public ServletRegistrationBean<MessageDispatcherServlet> messageDispatcherServlet(ApplicationContext applicationContext) {
        MessageDispatcherServlet servlet = new MessageDispatcherServlet();
        servlet.setApplicationContext(applicationContext);
        servlet.setTransformWsdlLocations(true);
        return new ServletRegistrationBean<MessageDispatcherServlet>(servlet, "/authentication/*");
    }

    @Bean(name = "authentication")
    public DefaultWsdl11Definition defaultWsdl11Definition(XsdSchema authenticationSchema) {
        DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition();
        wsdl11Definition.setPortTypeName("SharePort");
        wsdl11Definition.setLocationUri("/authentication");
        wsdl11Definition.setTargetNamespace("http://dto.shared.auth.timetracker.appl.com");
        wsdl11Definition.setSchema(authenticationSchema);
        return wsdl11Definition;
    }

    @Bean
    public XsdSchema authenticationSchema() {
        return new SimpleXsdSchema(new ClassPathResource("auth-attributes.xsd"));
    }

我对 WSDL 不是很熟悉。从 XSD 生成 JAXB 源代码很好,但 WSDL 解析失败。我似乎不需要一种方法来告诉 WSDL 构建机制在哪里检索导入的 XSD。

【问题讨论】:

  • 已将导入的 XSD "shared-environment.xsd" 放到网络服务器上,并通过以下方式引用它:dto.common.app.com" schemaLocation="http:/// XSD/shared-environment.xsd" /> 这行得通。但不喜欢这种“解决方案”。希望在项目中保留定义。

标签: soap xsd jaxb wsdl


【解决方案1】:

“DefaultWsdl11Definition”有方法 setSchemaCollection() 来注册多个 XSD 定义。我使用这种方法而不是 setSchema - 这有帮助 - 至少有点。错误消息已消失,Soap 请求已正确回答。

仅当将新项目“添加”到 SoapUI 时,客户端不会自动创建请求 - 无论出于何种原因 - 这仅适用于从网络服务器“导入”。

WS-Configuration 现在看起来像这样:

@EnableWs
@Configuration
public class BackendServerConfig extends WsConfigurerAdapter {
    @Bean 
    ServletWebServerFactory servletWebServerFactory(){
        return new TomcatServletWebServerFactory();
    }

    @Bean
    public ServletRegistrationBean<MessageDispatcherServlet> messageDispatcherServlet(ApplicationContext applicationContext) {
        MessageDispatcherServlet servlet = new MessageDispatcherServlet();
        servlet.setApplicationContext(applicationContext);
        servlet.setTransformWsdlLocations(true);
        return new ServletRegistrationBean<MessageDispatcherServlet>(servlet, "/authentication/*");
    }

    @Bean(name = "authentication")
    public DefaultWsdl11Definition defaultWsdl11Definition(XsdSchema authenticationSchema) {
        DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition();
        wsdl11Definition.setPortTypeName("SharePort");
        wsdl11Definition.setLocationUri("/authentication");
        wsdl11Definition.setTargetNamespace("http://dto.shared.auth.app.com");

        wsdl11Definition.setSchemaCollection(schemaCollection());

        return wsdl11Definition;
    }

    private XsdSchemaCollection schemaCollection() {
        CommonsXsdSchemaCollection commonsXsdSchemaCollection = new CommonsXsdSchemaCollection(
                new ClassPathResource("auth-attributes.xsd"),
                new ClassPathResource("shared-environment.xsd"));
        commonsXsdSchemaCollection.setInline(true);
        return commonsXsdSchemaCollection;
    }

【讨论】:

    猜你喜欢
    • 2017-12-15
    • 1970-01-01
    • 1970-01-01
    • 2017-02-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-17
    • 1970-01-01
    • 2018-07-17
    相关资源
    最近更新 更多