1

I inherited an old (15 years) Java application that was maintained badly. Mavenizing was not done proper so I did give it a try since a lot of libraries where manually added to the classpath. Now I have a master pom that have all libraries as dependency in the pom file.

The error is as below:

Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Unknown attribute http://javax.xml.XMLConstants/property/accessExternalDTD

But now I have some parser issues while starting my webservices. The old project is using a SaxParser for XML but it also uses Spring where I see conflicts while initializing the beans.

I already upgraded to Java 8 (running also on Liberty Profile since we are bounded to IBM with an IBM JDK 8). Added jaxp-api to get the 'accessExternalDTD' attribute on the classpath. Removed xerces implementation (also excluded from xalan dependencies) but nothing did work.

[err] JAXP: find factoryId=javax.xml.parsers.DocumentBuilderFactory
[err] JAXP: found service provider by ServiceLoader, value=org.apache.xerces.jaxp.DocumentBuilderFactoryImpl
2019-01-21 11:18:35 DEBUG CalculationExecutor:186 -    0.000 CalculationExecutor.new: begin

2019-01-21 11:18:35 DEBUG Loader:50 - Trying to find [project-calculationKernel.xml] using context classloader: com.ibm.ws.classloading.internal.ThreadContextClassLoader@c5d35d81.

2019-01-21 11:18:35 DEBUG Loader:56 - Found: wsjar:file:/C:/LogFiles/Tools/wlp-webProfile8-java8-win-x86_64-18.0.0.4/wlp/usr/servers/Server18.0.0.4/apps/expanded/CreditRiskWebServicesEAR.ear/CreditRiskWebServices.war/WEB-INF/lib/RiskRatingCalculation-17.0.48-SNAPSHOT.jar!/project-calculationKernel.xml

2019-01-21 11:18:35 INFO  BaseCastorMappingMarshaller:33 - Castor version used by Castor Mapping Marshaller: 1.2  [0]

2019-01-21 11:18:35 DEBUG Loader:50 - Trying to find [castorMapping-projectConfiguration.xml] using context classloader: com.ibm.ws.classloading.internal.ThreadContextClassLoader@c5d35d81.

2019-01-21 11:18:35 DEBUG Loader:56 - Found: wsjar:file:/C:/LogFiles/Tools/wlp-webProfile8-java8-win-x86_64-18.0.0.4/wlp/usr/servers/Server18.0.0.4/apps/expanded/CreditRiskWebServicesEAR.ear/CreditRiskWebServices.war/WEB-INF/lib/CalculationKernelSE-17.0.48-SNAPSHOT.jar!/castorMapping-projectConfiguration.xml

[err] JAXP: find factoryId=javax.xml.parsers.SAXParserFactory
[err] JAXP: found service provider by ServiceLoader, value=org.apache.xerces.jaxp.SAXParserFactoryImpl
[err] JAXP: find factoryId=javax.xml.parsers.SAXParserFactory
[err] JAXP: found service provider by ServiceLoader, value=org.apache.xerces.jaxp.SAXParserFactoryImpl
2019-01-21 11:18:35 DEBUG CalculationExecutor:186 -    0.00691 CalculationExecutor.new: end

[err] JAXP: find factoryId=javax.xml.parsers.DocumentBuilderFactory
[err] JAXP: found service provider by ServiceLoader, value=org.apache.xerces.jaxp.DocumentBuilderFactoryImpl
[err] JAXP: find factoryId=javax.xml.transform.TransformerFactory
[err] Warning: external object model net.sf.saxon.dom.DOMEnvelope has been loaded, but is not an instance of net.sf.saxon.om.ExternalObjectModel
[err] Warning: external object model net.sf.saxon.dom.DOMObjectModel has been loaded, but is not an instance of net.sf.saxon.om.ExternalObjectModel
[err] JAXP: found service provider by ServiceLoader, value=net.sf.saxon.TransformerFactoryImpl
[ERROR   ] SRVE0283E: Exception caught while initializing context: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'soapRiskApprovalService' defined in ServletContext resource [/WEB-INF/applicationContext-creditRiskWebServices.xml]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Unknown attribute http://javax.xml.XMLConstants/property/accessExternalDTD
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1745)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:576)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:498)
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320)
    at org.springframework.beans.factory.support.AbstractBeanFactory$$Lambda$136.00000000124ED300.getObject(Unknown Source)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:846)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:863)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:546)
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:400)
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:291)
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:103)
    at com.ibm.ws.webcontainer.webapp.WebApp.notifyServletContextCreated(WebApp.java:2376)
    at [internal classes]
Caused by: java.lang.IllegalArgumentException: Unknown attribute http://javax.xml.XMLConstants/property/accessExternalDTD
    at net.sf.saxon.Configuration.setConfigurationProperty(Configuration.java:2185)
    at net.sf.saxon.TransformerFactoryImpl.setAttribute(TransformerFactoryImpl.java:342)
    at org.springframework.xml.transform.TransformerFactoryUtils.defaultSettings(TransformerFactoryUtils.java:56)
    at org.springframework.xml.transform.TransformerFactoryUtils.newInstance(TransformerFactoryUtils.java:32)
    at org.springframework.xml.transform.TransformerHelper.newTransformerFactory(TransformerHelper.java:88)
    at org.springframework.xml.transform.TransformerHelper.getTransformerFactory(TransformerHelper.java:104)
    at org.springframework.xml.transform.TransformerHelper.createTransformer(TransformerHelper.java:119)
    at org.springframework.xml.transform.TransformerHelper.transform(TransformerHelper.java:131)
    at org.springframework.xml.transform.TransformerObjectSupport.transform(TransformerObjectSupport.java:96)
    at org.springframework.ws.wsdl.wsdl11.provider.InliningXsdSchemaTypesProvider.getSchemaElement(InliningXsdSchemaTypesProvider.java:113)
    at org.springframework.ws.wsdl.wsdl11.provider.InliningXsdSchemaTypesProvider.addTypes(InliningXsdSchemaTypesProvider.java:101)
    at org.springframework.ws.wsdl.wsdl11.ProviderBasedWsdl4jDefinition.afterPropertiesSet(ProviderBasedWsdl4jDefinition.java:234)
    at org.springframework.ws.wsdl.wsdl11.DefaultWsdl11Definition.afterPropertiesSet(DefaultWsdl11Definition.java:183)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1804)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1741)
    ... 15 more

I googled a lot but all I couldn't find any approach that would make this old application start up. Hope that someone did encounter the same issues and could point me the way how to handle this.

Sangam Belose
  • 4,262
  • 8
  • 26
  • 48
Eddy Vos
  • 13
  • 1
  • 1
  • 4
  • Take a look to this https://stackoverflow.com/questions/54186834/spring-boot-2-1-1-to-2-1-2-error-creating-bean-with-name-payloadrootannotation – Gamby Jan 30 '19 at 16:53

3 Answers3

1

Your problem seems to be related to SWS-1049, It was introduced in spring-ws 3.0.6.RELEASE. you need to use 3.0.7.BUILD-SNAPSHOT instead.

Manish
  • 26
  • 2
  • Thanks, this did solve my issue. Now I have to wait for the 3.0.7.RELEASE since I am not allowed to use snapshot repositories in my config (company rules). – Eddy Vos Feb 19 '19 at 08:03
  • 1
    I am at version 3.0.8.RELEASE I can still reproduce this issue. Is there a known workaround/fix ? – alegria Nov 10 '21 at 20:02
1

Try to setup TransformerFactory from JDK 8. Here there is an issue in JBoss, but code snapshot should work in the same way https://stackoverflow.com/a/55304023/204950

banterCZ
  • 1,551
  • 1
  • 22
  • 37
1

I was facing the same issue with an old code where removing SaxonJ, or other dependencies wasn't an option.

I ended up following the TransformerFactory::newInstance docs by adding a system property to define the default TransformerFactory to instantiate:

-Djavax.xml.transform.TransformerFactory=com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl

NOTE: Example is using OpenJDK8, you will have to find the TransformerFactoryImpl package that you want