java - XML-22103 : (Fatal Error) DOMResult can not be this kind of node

标签 java spring-boot web-services jaxb2-maven-plugin

我在请求 Web 服务期间遇到错误。

我使用了 Spring boot 3.x

      <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>jaxb2-maven-plugin</artifactId>
                <version>2.5.0</version>
                <executions>
                    <execution>
                        <id>apps</id>
                        <goals>
                            <goal>xjc</goal>
                        </goals>
                        <configuration>
                            <target>2.1</target>
                                               <episodeFileName>episode_apps</episodeFileName>
                            <xjbSources>
                                <xjbSource>src/main/resources/appstms.xjb</xjbSource>
                            </xjbSources>

                            <sources>
                                <source>src/main/resources/xsd/schema-apps.xsd</source>
                            </sources>
                            <outputDirectory>${basedir}/src/main/java</outputDirectory>
<!--
                            <outputDirectory>
                                ${project.parent.relativePath}/src/main/java/by/*/reception/electronic/docs/service/
                            </outputDirectory>-->
                            <packageName>*.reception.electronic.docs.service.generated.xml.entrypoint</packageName>

                        <!--    <outputDirectory>*.reception.electronic.docs.service.generate
                            </outputDirectory>-->

                            <clearOutputDir>false</clearOutputDir>
                        </configuration>
                    </execution>

                </executions>
            </plugin>
  • 配置


@EnableWs
@Configuration
public class WebServiceConfig {

    private static final String NAMESPACE_URI = "http://*.com/apps";


    @SuppressWarnings({"rawtypes", "unchecked"})
    @Bean(name = "apsMessage")
    public ServletRegistrationBean messageDispatcherServlet(ApplicationContext appContext){

        MessageDispatcherServlet servlet = new MessageDispatcherServlet();

        servlet.setApplicationContext(appContext);
        servlet.setTransformWsdlLocations(true);
        return new ServletRegistrationBean(servlet, "/ws/*");
    }

    @Bean
    public SaajSoapMessageFactory messageFactory() {

        SaajSoapMessageFactory messageFactory = new SaajSoapMessageFactory();
        messageFactory.setSoapVersion(SoapVersion.SOAP_12);
        return messageFactory;
    }



    /* localhost:8080/ws/appsTms.wsdl
     * */
    @Bean(name = "appsTms")
    public DefaultWsdl11Definition defaultWsdl11Definition(@Qualifier("appsTmsSchema") XsdSchema schema){

        DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition();

        wsdl11Definition.setPortTypeName("ApsPort");

        wsdl11Definition.setLocationUri("/ws");

        wsdl11Definition.setTargetNamespace(NAMESPACE_URI);

        wsdl11Definition.setSchema(schema);

        wsdl11Definition.setCreateSoap11Binding(true);
        wsdl11Definition.setCreateSoap12Binding(true);

        return wsdl11Definition;
    }

    @Bean(name = "appsTmsSchema")
    public XsdSchema moviesSchema(){

        return new SimpleXsdSchema(new ClassPathResource("xsd/schema-apps.xsd"));

    }
}

  • 和端点
@Endpoint
public class MessageEndpoint {

    private static final Logger LOGGER  = LoggerFactory.getLogger( MessageEndpoint.class );

    private static final String NAMESPACE_URI = "http://*.com";


    @PayloadRoot(namespace = NAMESPACE_URI, localPart = "Multiply")
    @ResponsePayload
    public MultiplyResponse getMultiplyResponse(@RequestPayload Multiply messageRequest) throws Exception {

        String fileName1 = messageRequest.getFileName1();

        System.out.println(fileName1);

        MultiplyResponse response = new MultiplyResponse();
        response.setReturn("");

        return response;
    }
}

当我尝试执行查询并传递 Xml 时,我什至没有到达 Web 服务端点所在的类。

我有一个错误:

08-06-2020 16:44:27.935 INFO 14660
o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'

XML-22103: (Fatal Error) DOMResult can not be this kind of node. 08-06-2020 16:44:27.936 DEBUG 14660
o.s.web.servlet.DispatcherServlet : Detected StandardServletMultipartResolver 08-06-2020 16:44:27.951 DEBUG 14660 o.s.web.servlet.DispatcherServlet : enableLoggingRequestDetails='false': request parameters and headers will be masked to prevent unsafe logging of potentially sensitive data 08-06-2020 16:44:27.951 INFO 14660
o.s.web.servlet.DispatcherServlet : Completed initialization in 15 ms 08-06-2020 16:44:27.952 DEBUG 14660
o.s.web.servlet.DispatcherServlet : "ERROR" dispatch for POST "/error", parameters={} 08-06-2020 16:44:27.955 DEBUG 14660
s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped to org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController#error(HttpServletRequest) 08-06-2020 16:44:27.976 DEBUG 14660
o.s.w.s.m.m.a.HttpEntityMethodProcessor : Using 'application/json', given [/] and supported [application/json, application/+json, application/json, application/+json] 08-06-2020 16:44:27.976 DEBUG 14660 o.s.w.s.m.m.a.HttpEntityMethodProcessor : Writing [{timestamp=Mon Jun 08 16:44:27 MSK 2020, status=500, error=Internal Server Error, message=, path=/ws (truncated)...] 08-06-2020 16:44:28.004 DEBUG 14660 o.s.web.servlet.DispatcherServlet : Exiting from "ERROR" dispatch, status 500

知道这是什么以及如何解决它吗?

最佳答案

原因如下:

相邻系统由自己的 xsd 工作,并具有与发送到 Web 服务的文档进行映射的命名空间 uri。

相邻系统是一个中介者,接收 xml 文档并发送到另一个系统进行处理。

首先,她查找 中,并且比她想象的要多,在 Web 服务(soap)中的端点特定命名空间,指向 xsd ,基于WSDL构建。

adjiong 系统可以使用:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
           xmlns:tns="http://ws.transit.ls.com"
           targetNamespace="http://ws.transit.ls.com"
           elementFormDefault="qualified">

    <xs:element name="Multiply">
....

您必须将这样的targetNamespace指向:

@Endpoint
public class MessageEndpoint {

    private static final Logger LOGGER  = LoggerFactory.getLogger( MessageEndpoint.class );

    private static final String NAMESPACE_URI = "http://ws.transit.ls.com";


    @PayloadRoot(namespace = NAMESPACE_URI, localPart = "Multiply")
    @ResponsePayload
    public MultiplyResponse getMultiplyResponse(@RequestPayload Multiply messageRequest) throws Exception {

        String fileName = messageRequest.getFileName1();

...

您还必须使用能够连接系统运行的 xsd(不得对 xsd 进行任何更改)

如果您正在创建新的 Web 服务 Soap,并首先创建一个应用程序,其他客户端将粘附您的 xsd。

但就我而言,我必须遵守禁止系统的规则。

关于java - XML-22103 : (Fatal Error) DOMResult can not be this kind of node,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62263743/

相关文章:

java - 从 Android 的 Jersey Resftul Web 服务传递和接收 JSON 对象

java - Jersey JAX-RS 客户端 XML 到 java.util.List 反序列化

java - 类和类<?>有什么区别?

java - Dagger 不会为 Android 生成 Dagger 类

java - Spring MVC REST - 根据请求内容类型返回 xml 或 json

java - Apache CXF - 向客户提供 SEI

java - Spring Boot 修改默认 JSON 响应

javascript - 从JSON响应中过滤ng-repeat

spring - 为什么 Jersey 显示在我的 Spring boot MVC 上

java - 简单的 JPA findBy 请求需要 4 分钟,而 SQL 查询需要 365 毫秒