8

I'm facing this exception when receiving an Xml and trying to parse it. The code responsible for that is well tested when running as an standalone application. However I'm now integrating it in Tomcat.

The stack trace is:

java.lang.IllegalStateException: org.xml.sax.SAXNotRecognizedException: http://javax.xml.XMLConstants/feature/secure-processing
    at com.sun.xml.internal.bind.v2.util.XmlFactory.createParserFactory(XmlFactory.java:121)
    at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.getXMLReader(UnmarshallerImpl.java:139)
    at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:157)
    at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:204)

Digging around I found this, so maybe the solution is to change the options Tomcat sets.

So the question is:

  • Which is the problem's root?
  • Best way to solve it?
  • Is a good approach to change Tomcat options? how is this done?

Update

This happens when running it with Java 8, reverting to Java 7 works ok.

Javier Mr
  • 2,130
  • 4
  • 31
  • 39
  • 1
    In my experience this can happen when there is more than one XML-parser loaded and the wrong one is used. To verify this is (not) the case, print out the class-name of the XmlFactory used in the standalone application. If it is not "com.sun.xml.internal.bind.v2.util.XmlFactory" then that could be the cause of the exception (and to solve it you'll have to specify the correct XmlFactory manually). – vanOekel May 30 '14 at 12:21
  • 2
    I have described a similar problem solution in this question: http://stackoverflow.com/questions/25644023/error-unmarshalling-xml-in-java-8-secure-processing-org-xml-sax-saxnotrecognize – mmx73 Sep 12 '14 at 11:18
  • Possible duplicate of [Error unmarshalling xml in java-8 "secure-processing org.xml.sax.SAXNotRecognizedException causing java.lang.IllegalStateException"](http://stackoverflow.com/questions/25644023/error-unmarshalling-xml-in-java-8-secure-processing-org-xml-sax-saxnotrecognize) – malat May 12 '17 at 09:40

3 Answers3

6

I had faced similar issue, this issue occurs when there is big difference in versions of xerces jar and xercesImpl jar. To solve this, I used xerces-2.9.0 and xercesImpl-2.9.1 and the issue gone.

user2974606
  • 143
  • 1
  • 12
  • I could not possibly find xerces 2.9.0 on maven repo? Here are the two dependencies that i found. : a) groupId:xerces - artifactId:xerces - version:2.4.0 and b) groupId:xerces - artifactId:xercesImpl - version:2.9.1. Am i missing anything here. Also, I face this issue with java 8 only. With java 7 or java 6, it does not exist. – MiKu Feb 26 '16 at 00:01
  • @MiKu: With java-8, latest version of xerces(i.e. 2.11.0) must work. – Darpan27 Mar 30 '17 at 18:53
5

I know this is an old question. But just updating it if it is of any help to others.. We had a similar issue recently while upgradig to java 8 with JBOSS 3.2.6. The cause of the issue was an old xercesImpl.jar. We upgraded to xercesImol-2.9.1.jar and the issue was resolved.

Nayan Sonthalia
  • 237
  • 1
  • 4
  • 22
3

Well, this worked for me: Added below to my tomcat configuration arguments: -Djavax.xml.parsers.SAXParserFactory="com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl"

Aakash Patel
  • 549
  • 5
  • 19