SAAJ ClassCast Error with JDK 6


A project I'm working on at the moment has an authentication component which uses a webservice to do most of the work. During the development I stumbled across an issue, which while appearing to be known, is not well documented in any place, so in case anyone else hits this ....

Software Environment

The key part here is the JDK version, from what I can discern after doing some searching all 1.6 JDK's have this issue, for the example here I'm using the 1.6.0_06 JDK (services & support), as bundled with Solaris Nevada (snv_97) (services & support), either Tomcat 6 or Glassfish 3 for the app server, and Netbeans 6.5 as the IDE. Our webservice in this case was generated using wscompile as bundled with Appserver 9.1 (services & support).

Stacktrace

The stacktrace that we are getting here (from Tomcat in this case, but the appserver is not important here) is
org.apache.jasper.JasperException: java.lang.ClassCastException: 
 com.sun.xml.internal.messaging.saaj.soap.ver1_1.Message1_1Impl cannot 
 be cast to com.sun.xml.messaging.saaj.soap.MessageImpl
	org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:541)
	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:435)
	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:803)

root cause

java.lang.ClassCastException: com.sun.xml.internal.messaging.saaj.soap.ver1_1.Message1_1Impl 
 cannot be cast to com.sun.xml.messaging.saaj.soap.MessageImpl
	com.sun.xml.rpc.client.StubBase._postSendingHook(StubBase.java:231)
	com.sun.xml.rpc.client.StreamingSender._send(StreamingSender.java:324)
	.............
Whats actually going on here (and if anyone has corrections please feel free to provide them, this is not an area I've spent time reading into) is that the saaj classes that you would have used before from the webservices development packs are now present in the 1.6 jdks rt.jar, and we have a conflict between what is expected by the webservice and what we have.

Workarounds

A couple of workarounds exist, namely things I really don't like as the vary from environment to environment e.g. placing endorsed libs in place. A more generic workaround is to add an extra startup option of
-Djavax.xml.soap.MessageFactory=com.sun.xml.messaging.saaj.soap.ver1_1.SOAPMessageFactory1_1Impl
which eliminates the problem, but may have implications for other aspects of your application, so use with caution.
Comments:

Post a Comment:
Comments are closed for this entry.
About

fintanr

Search

Archives
« July 2014
MonTueWedThuFriSatSun
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
   
       
Today