Skip to content

Commit 97746d7

Browse files
committed
SWS-198
1 parent 2faca38 commit 97746d7

File tree

2 files changed

+43
-21
lines changed

2 files changed

+43
-21
lines changed

core/src/main/java/org/springframework/ws/soap/saaj/SaajSoapMessageFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ else if (SoapVersion.SOAP_12 == version) {
8888
}
8989
else {
9090
throw new IllegalArgumentException(
91-
"Invalid version [" + version + "]. " + "Expected the SOAP_11 or SOAP_12 constant");
91+
"Invalid version [" + version + "]. Expected the SOAP_11 or SOAP_12 constant");
9292
}
9393
}
9494
else if (SoapVersion.SOAP_11 != version) {

core/src/main/java/org/springframework/ws/soap/saaj/support/SaajUtils.java

Lines changed: 42 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import javax.xml.soap.MessageFactory;
2424
import javax.xml.soap.MimeHeaders;
2525
import javax.xml.soap.Name;
26+
import javax.xml.soap.SOAPConstants;
2627
import javax.xml.soap.SOAPElement;
2728
import javax.xml.soap.SOAPEnvelope;
2829
import javax.xml.soap.SOAPException;
@@ -36,8 +37,8 @@
3637
import 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

Comments
 (0)