0

I am trying to call a Apache CXF Service from a Plain Java code as follows

public static void main(String args[])
{
Call Apache CXF Service ....
}

I dont get any compile time error, but getting Runtime exception as follows

Exception in thread "main" 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:1457)
    at org.apache.cxf.staxutils.StaxUtils.read(StaxUtils.java:1110)
    at org.apache.cxf.bus.extension.XmlExtensionFragmentParser.getExtensions(XmlExtensionFragmentParser.java:46)
    at org.apache.cxf.bus.extension.ExtensionManagerImpl.load(ExtensionManagerImpl.java:183)
    at org.apache.cxf.bus.extension.ExtensionManagerImpl.load(ExtensionManagerImpl.java:159)
    at org.apache.cxf.bus.extension.ExtensionManagerImpl.load(ExtensionManagerImpl.java:108)
    at org.apache.cxf.bus.extension.ExtensionManagerBus.<init>(ExtensionManagerBus.java:121)
    at org.apache.cxf.bus.extension.ExtensionManagerBus.<init>(ExtensionManagerBus.java:134)
    at org.apache.cxf.bus.CXFBusFactory.createBus(CXFBusFactory.java:40)
    at org.apache.cxf.bus.CXFBusFactory.createBus(CXFBusFactory.java:36)
    at org.apache.cxf.bus.CXFBusFactory.createBus(CXFBusFactory.java:32)
    at org.apache.cxf.BusFactory.getDefaultBus(BusFactory.java:106)
    at org.apache.cxf.BusFactory.createThreadBus(BusFactory.java:243)
    at org.apache.cxf.BusFactory.getThreadDefaultBus(BusFactory.java:227)
    at org.apache.cxf.BusFactory.getThreadDefaultBus(BusFactory.java:214)
    at org.apache.cxf.jaxws.spi.ProviderImpl.createServiceDelegate(ProviderImpl.java:89)
    at javax.xml.ws.Service.<init>(Unknown Source)

The dependencies I have are as follows

cxf-rt-frontend-jaxws-2.7.12.jar
cxf-api-2.7.12.jar
woodstox-core-asl-4.4.0.jar
stax2-api-3.1.4.jar
xmlschema-core-2.1.0.jar
cxf-rt-core-2.7.12.jar
jaxb-impl-2.1.13.jar
cxf-rt-bindings-soap-2.7.12.jar
cxf-rt-databinding-jaxb-2.7.12.jar
cxf-rt-bindings-xml-2.7.12.jar
cxf-rt-frontend-simple-2.7.12.jar
cxf-rt-ws-addr-2.7.12.jar
cxf-rt-ws-policy-2.7.12.jar
cxf-rt-transports-http-2.7.12.jar

Please help me solve this error

Note:- I don't have pom.xml. I use traditional "lib" folder to place my dependent jars

RandomWanderer
  • 701
  • 2
  • 12
  • 23
  • Possible duplicate of http://stackoverflow.com/questions/20114945/cxf-web-service-client-cannot-create-a-secure-xmlinputfactory – David J. Liszewski Jul 23 '15 at 14:07
  • Possible duplicate of [CXF web service client: "Cannot create a secure XMLInputFactory"](http://stackoverflow.com/questions/20114945/cxf-web-service-client-cannot-create-a-secure-xmlinputfactory) – Toparvion Apr 04 '17 at 07:40

1 Answers1

0

I added these three lines and worked fine

Properties props = System.getProperties();
        props.setProperty("org.apache.cxf.stax.allowInsecureParser", "1");
        props.setProperty("UseSunHttpHandler", "true");
RandomWanderer
  • 701
  • 2
  • 12
  • 23