SOAP разрешение пути для зависимого XSD-файла не понято - PullRequest
0 голосов
/ 03 марта 2020

У меня есть два 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

The " auth-attribute.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-адаптер определяется следующим образом:

@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. Генерация JAXB-источника из XSD в порядке, но разрешение WSDL не удается. Кажется, мне не нужен метод, чтобы сообщить механизму построения WSDL, где получить импортированные XSD.

1 Ответ

0 голосов
/ 04 марта 2020

«DefaultWsdl11Definition» получил метод setSchemaCollection () для регистрации нескольких XSD-определений. Я использовал этот метод вместо setSchema - это помогло - хотя бы немного. Сообщение об ошибке исчезло, и Soap -запросы отвечают правильно.

Только при добавлении нового проекта в SoapUI клиент не создает автоматически запросы - по какой-либо причине - это работает только с "import" с веб-сервера.

Теперь 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;
    }
...