Search code examples
web-servicessoapcxfcxf-client

Apache CXF Client Error


Our application had a CXF service for which we used the following dependencies.

compile group: 'org.apache.cxf', name: 'cxf-rt-frontend-jaxws', version:'3.0.1'
compile group: 'org.apache.cxf', name: 'cxf-rt-transports-http', version:'3.0.1'
runtime group: 'org.apache.cxf', name: 'cxf-rt-bindings-soap', version:'3.0.1'
compile group: 'org.apache.cxf', name: 'cxf-rt-rs-extension-providers', version:'3.0.1'
compile 'org.apache.cxf:cxf-rt-ws-security:3.0.1'
compile 'org.apache.wss4j:wss4j-ws-security-common:2.0.1'
compile 'javax.ws.rs:jsr311-api:1.1.1'

Now I am writing a client in the same project for a different service, but getting this error

Exception in thread "main" javax.xml.ws.WebServiceException: org.apache.cxf.service.factory.ServiceConstructionException: Failed to create service.
    at org.apache.cxf.jaxws.ServiceImpl.initialize(ServiceImpl.java:163)
    at org.apache.cxf.jaxws.ServiceImpl.<init>(ServiceImpl.java:129)
    at org.apache.cxf.jaxws.spi.ProviderImpl.createServiceDelegate(ProviderImpl.java:99)
    at javax.xml.ws.Service.<init>(Service.java:77)
    at com.inflexxion.bhcds.contract.ruleexecutionservice.RuleExecutionService.<init>(RuleExecutionService.java:46)
    at com.feisystems.bham.domain.gpra.RuleExecutionWebServiceClient.main(RuleExecutionWebServiceClient.java:122)
Caused by: org.apache.cxf.service.factory.ServiceConstructionException: Failed to create service.
    at org.apache.cxf.wsdl11.WSDLServiceFactory.<init>(WSDLServiceFactory.java:87)
    at org.apache.cxf.jaxws.ServiceImpl.initializePorts(ServiceImpl.java:218)
    at org.apache.cxf.jaxws.ServiceImpl.initialize(ServiceImpl.java:161)
    ... 5 more
Caused by: javax.wsdl.WSDLException: WSDLException: faultCode=PARSER_ERROR: java.lang.RuntimeException: Cannot create a secure XMLInputFactory
    at org.apache.cxf.wsdl11.WSDLManagerImpl.loadDefinition(WSDLManagerImpl.java:221)
    at org.apache.cxf.wsdl11.WSDLManagerImpl.getDefinition(WSDLManagerImpl.java:163)
    at org.apache.cxf.wsdl11.WSDLServiceFactory.<init>(WSDLServiceFactory.java:85)
    ... 7 more
Caused by: java.lang.RuntimeException: Cannot create a secure XMLInputFactory
    at org.apache.cxf.staxutils.StaxUtils.createXMLInputFactory(StaxUtils.java:314)
    at org.apache.cxf.staxutils.StaxUtils.getXMLInputFactory(StaxUtils.java:264)
    at org.apache.cxf.staxutils.StaxUtils.createXMLStreamReader(StaxUtils.java:1516)
    at org.apache.cxf.staxutils.StaxUtils.createXMLStreamReader(StaxUtils.java:1415)
    at org.apache.cxf.wsdl11.WSDLManagerImpl.loadDefinition(WSDLManagerImpl.java:208)
    ... 9 more

When I comment out the dependency compile group: 'org.apache.cxf', name: 'cxf-rt-frontend-jaxws', version:'3.0.1' it works fine.

I however need this dependency for the existing service. Here is the dependency tree for the compile group: 'org.apache.cxf', name: 'cxf-rt-frontend-jaxws', version:'3.0.1'

+--- org.apache.cxf:cxf-rt-frontend-jaxws:3.0.1
|    +--- xml-resolver:xml-resolver:1.2
|    +--- asm:asm:3.3.1
|    +--- org.apache.cxf:cxf-core:3.0.1
|    |    +--- org.codehaus.woodstox:woodstox-core-asl:4.4.0
|    |    |    +--- javax.xml.stream:stax-api:1.0-2
|    |    |    \--- org.codehaus.woodstox:stax2-api:3.1.4
|    |    \--- org.apache.ws.xmlschema:xmlschema-core:2.1.0
|    +--- org.apache.cxf:cxf-rt-bindings-soap:3.0.1
|    |    +--- org.apache.cxf:cxf-core:3.0.1 (*)
|    |    +--- org.apache.cxf:cxf-rt-wsdl:3.0.1
|    |    |    +--- org.apache.cxf:cxf-core:3.0.1 (*)
|    |    |    +--- wsdl4j:wsdl4j:1.6.3
|    |    |    \--- asm:asm:3.3.1
|    |    \--- org.apache.cxf:cxf-rt-databinding-jaxb:3.0.1
|    |         +--- org.apache.cxf:cxf-core:3.0.1 (*)
|    |         +--- org.apache.cxf:cxf-rt-wsdl:3.0.1 (*)
|    |         +--- com.sun.xml.bind:jaxb-impl:2.1.14
|    |         |    +--- com.sun.xml.bind:jaxb-core:2.1.14
|    |         |    |    \--- javax.xml.bind:jaxb-api:2.1
|    |         |    |         +--- javax.xml.stream:stax-api:1.0-2
|    |         |    |         \--- javax.activation:activation:1.1 -> 1.1.1
|    |         |    \--- com.sun.xml.fastinfoset:FastInfoset:1.2.12
|    |         \--- com.sun.xml.bind:jaxb-core:2.1.14 (*)
|    +--- org.apache.cxf:cxf-rt-bindings-xml:3.0.1
|    |    \--- org.apache.cxf:cxf-core:3.0.1 (*)
|    +--- org.apache.cxf:cxf-rt-frontend-simple:3.0.1
|    |    +--- org.apache.cxf:cxf-core:3.0.1 (*)
|    |    +--- org.apache.cxf:cxf-rt-bindings-soap:3.0.1 (*)
|    |    \--- org.apache.cxf:cxf-rt-wsdl:3.0.1 (*)
|    \--- org.apache.cxf:cxf-rt-ws-addr:3.0.1
|         +--- org.apache.cxf:cxf-core:3.0.1 (*)
|         +--- org.apache.cxf:cxf-rt-bindings-soap:3.0.1 (*)
|         \--- org.apache.cxf:cxf-rt-ws-policy:3.0.1
|              +--- wsdl4j:wsdl4j:1.6.3
|              +--- org.apache.cxf:cxf-core:3.0.1 (*)
|              \--- org.apache.neethi:neethi:3.0.3
|                   \--- org.codehaus.woodstox:woodstox-core-asl:4.2.0 -> 4.4.0 (*)

I also tried to exclude dependencies but it dint work

compile (group: 'org.apache.cxf', name: 'cxf-rt-frontend-jaxws', version:'3.0.1')
 {
    exclude group: 'org.apache.cxf', module: 'cxf-core' // No Problem
    exclude group: 'org.apache.cxf', module: 'cxf-rt-bindings-soap'  // No Problem
    exclude group: 'org.apache.cxf', module: 'cxf-rt-bindings-xml'  // No Problem
    exclude group: 'org.apache.cxf', module: 'cxf-rt-frontend-simple'  Class Not Found Error
    exclude group: 'org.apache.cxf', module: 'cxf-rt-ws-addr'  // No Problem
    exclude group: 'org.apache.cxf', module: 'cxf-rt-transports-http'  // No Problem  

}

Solution

  • For some weird reason my code in STS/eclipse was referring to Java Web App Libraries. This ended up being a classpath problem problem.

    I must say the error message is very deceiving and can take one countless hours to fix.