2323import javax .xml .soap .MessageFactory ;
2424import javax .xml .soap .MimeHeaders ;
2525import javax .xml .soap .Name ;
26+ import javax .xml .soap .SOAPConstants ;
2627import javax .xml .soap .SOAPElement ;
2728import javax .xml .soap .SOAPEnvelope ;
2829import javax .xml .soap .SOAPException ;
3637import org .w3c .dom .Element ;
3738
3839/**
39- * Collection of generic utility methods to work with SAAJ. Includes conversion from <code> Name</code>s to
40- * <code> QName</code> s and vice-versa, and SAAJ version checking.
40+ * Collection of generic utility methods to work with SAAJ. Includes conversion from SAAJ {@link Name} objects to {@link
41+ * QName} s and vice-versa, and SAAJ version checking.
4142 *
4243 * @author Arjen Poutsma
4344 * @see Name
@@ -57,37 +58,58 @@ public abstract class SaajUtils {
5758 private static int saajVersion = SAAJ_12 ;
5859
5960 static {
61+ if (isSaaj13 ()) {
62+ saajVersion = SAAJ_13 ;
63+ }
64+ else if (isSaaj12 ()) {
65+ saajVersion = SAAJ_12 ;
66+ }
67+ else {
68+ saajVersion = SAAJ_11 ;
69+ }
70+ }
71+
72+ private static boolean isSaaj13 () {
6073 try {
6174 ClassUtils .forName (SAAJ_13_CLASS_NAME );
62- saajVersion = SAAJ_13 ;
75+ MessageFactory .newInstance (SOAPConstants .SOAP_1_1_PROTOCOL );
76+ return true ;
6377 }
6478 catch (ClassNotFoundException ex ) {
65- if (Element .class .isAssignableFrom (SOAPElement .class ) && !isWebLogic9Implementation ()) {
66- saajVersion = SAAJ_12 ;
67- }
68- else {
69- saajVersion = SAAJ_11 ;
70- }
79+ return false ;
80+ }
81+ catch (NoSuchMethodError ex ) {
82+ return false ;
83+ }
84+ catch (SOAPException ex ) {
85+ return false ;
7186 }
7287 }
7388
7489 /**
75- * Checks whether we are dealing with a WebLogic 9 implementation of SAAJ. WebLogic 9 does implement SAAJ 1.2, but
76- * throws UnsupportedOperationExceptions when a SAAJ 1.2 method is called.
90+ * Checks whether we can find a SAAJ 1.2 implementation, being aware of the broken WebLogic 9 SAAJ implementation.
91+ * <p/>
92+ * WebLogic 9 does implement SAAJ 1.2, but throws UnsupportedOperationExceptions when a SAAJ 1.2 method is called.
7793 */
78- private static boolean isWebLogic9Implementation () {
79- try {
80- MessageFactory messageFactory = MessageFactory .newInstance ();
81- SOAPMessage message = messageFactory .createMessage ();
94+ private static boolean isSaaj12 () {
95+ if (Element .class .isAssignableFrom (SOAPElement .class )) {
96+ // see if we are dealing with WebLogic 9
8297 try {
83- message .getSOAPBody ();
98+ MessageFactory messageFactory = MessageFactory .newInstance ();
99+ SOAPMessage message = messageFactory .createMessage ();
100+ try {
101+ message .getSOAPBody ();
102+ return true ;
103+ }
104+ catch (UnsupportedOperationException ex ) {
105+ return false ;
106+ }
84107 }
85- catch (UnsupportedOperationException ex ) {
86- return true ;
108+ catch (SOAPException e ) {
109+ return false ;
87110 }
88- return false ;
89111 }
90- catch ( SOAPException e ) {
112+ else {
91113 return false ;
92114 }
93115 }
0 commit comments