在Spring Boot应用程序中调用Apache CXF Client时无法创建安全的XMLInputFactory

时间:2018-07-17 04:34:08

标签: java spring spring-boot cxf pom.xml

我正在尝试在我的Spring Boot应用程序中使用服务。这个确切的客户端在netbeans和使用Spring 3 MVC的旧项目中可以正常工作,但是当我尝试调用相同的方法时,我得到了javax.wsdl.WSDLException: WSDLException: faultCode=PARSER_ERROR: java.lang.RuntimeException: Cannot create a secure XMLInputFactory

我进行了很多搜索,尝试了不同的答案,但没有运气!这些是我尝试过的关于stackoverflow的一些问题:

CXF web service client: "Cannot create a secure XMLInputFactory"

java.lang.RuntimeException: Cannot create a secure XMLInputFactory when deploying on Glassfish

Cannot create a secure XMLInputFactory

Cannot create a secure XMLInputFactory when calling Apache CXF Client from Plain Java

尽管通过VM选项以允许安全性较低的解析器对我来说不是解决方案,但我尝试过。当我添加-Dorg.apache.cxf.stax.allowInsecureParser=1时,第一行代码不会引发指定的异常,但是在第二行中,当我尝试获取端口时,将会抛出java.lang.NoSuchFieldError: QUALIFIED

呼叫服务代码:

MessageRelayService messageRelayService = new MessageRelayService();
MessageRelay msgService = messageRelayService.getMessageRelayPort();

CountResult countResult = msgService.getReceivedMessageCount(USERNAME, PASSWORD);

我的pom(为简洁起见,一些部分被省略了):

<properties>
    ...
    <java.version>1.8</java.version>
    <cxf.version>3.0.0</cxf.version>
    <swagger.version>2.6.0</swagger.version>
    <purchase.version>1.2.4</purchase.version>
    <spring-cloud.version>Camden.SR2</spring-cloud.version>
    ...
</properties>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.4.7.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

<dependencies>
    .
    .
    .
    <dependency>
        <groupId>org.apache.axis2</groupId>
        <artifactId>axis2</artifactId>
        <version>1.6.2</version>
    </dependency>

    <dependency>
        <groupId>org.apache.axis2</groupId>
        <artifactId>axis2-transport-local</artifactId>
        <version>1.6.2</version>
    </dependency>

    <dependency>
        <groupId>org.apache.axis2</groupId>
        <artifactId>axis2-transport-http</artifactId>
        <version>1.6.2</version>
    </dependency>

    <dependency>
        <groupId>org.apache.ws.commons.axiom</groupId>
        <artifactId>axiom-impl</artifactId>
        <version>1.2.13</version>
    </dependency>

    <dependency>
        <groupId>wsdl4j</groupId>
        <artifactId>wsdl4j</artifactId>
        <version>1.6.2</version>
    </dependency>
    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-frontend-jaxws</artifactId>
        <version>${cxf.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-transports-http</artifactId>
        <version>${cxf.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-transports-http-jetty</artifactId>
        <version>${cxf.version}</version>
    </dependency>
    .
    .
    .
</dependencies>
...

任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:2)

经过大量搜索并在@pringi的帮助下尝试了各种尝试,我回到了pom并发现了问题,因此我想写一个答案也许有一天会对某人有所帮助!

问题是我的pom中有一些不需要的依赖项,可以将它们删除并与cxf冲突!所以我删除了这些依赖项,瞧!

    <dependency>
        <groupId>org.apache.axis2</groupId>
        <artifactId>axis2-transport-local</artifactId>
        <version>1.6.2</version>
    </dependency>

    <dependency>
        <groupId>org.apache.axis2</groupId>
        <artifactId>axis2-transport-http</artifactId>
        <version>1.6.2</version>
    </dependency>

    <dependency>
        <groupId>org.apache.ws.commons.axiom</groupId>
        <artifactId>axiom-impl</artifactId>
        <version>1.2.13</version>
    </dependency>
    <dependency>
        <groupId>wsdl4j</groupId>
        <artifactId>wsdl4j</artifactId>
        <version>1.6.2</version>
    </dependency>

    <dependency>
        <groupId>org.apache.neethi</groupId>
        <artifactId>neethi</artifactId>
        <version>3.0.3</version>
    </dependency>

    <dependency>
        <groupId>org.apache.ws.commons.axiom</groupId>
        <artifactId>axiom-api</artifactId>
        <version>1.2.13</version>
    </dependency>

    <dependency>
        <groupId>org.apache.ws.commons.schema</groupId>
        <artifactId>XmlSchema</artifactId>
        <version>1.4.2</version>
    </dependency>

感谢所有人!