Author: scheu
Date: Tue May 4 21:00:24 2010
New Revision: 941042
URL: http://svn.apache.org/viewvc?rev=941042&view=rev
Log:
AXIS2-4702
Contributor:Rich Scheuerle
Kudos to Tom Link for informing of this problem.
Added code to properly set and reset the JAXB_ENCODING.
Added a test case to validate the code.
Modified:
axis/axis2/java/core/trunk/modules/jaxws-integration/pom.xml
axis/axis2/java/core/trunk/modules/jaxws-integration/test/org/apache/axis2/jaxws/jaxb/string/JAXBStringUTF8Tests.java
axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/datasource/jaxb/JAXBDSContext.java
axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/JAXBUtils.java
Modified: axis/axis2/java/core/trunk/modules/jaxws-integration/pom.xml
URL:
http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/jaxws-integration/pom.xml?rev=941042&r1=941041&r2=941042&view=diff
==============================================================================
--- axis/axis2/java/core/trunk/modules/jaxws-integration/pom.xml (original)
+++ axis/axis2/java/core/trunk/modules/jaxws-integration/pom.xml Tue May 4
21:00:24 2010
@@ -1410,6 +1410,8 @@
<include>**/SOAP12DispatchTest.java</include>
<include>**/OMElementDispatchTest.java</include>
<include>**/JAXBContextTest.java</include>
+ <include>**/JAXBStringUTF16Tests.java</include>
+ <include>**/JAXBStringUTF8Tests.java</include>
<include>**/StringProviderTests.java</include>
<include>**/SOAPFaultProviderTests.java</include>
Modified:
axis/axis2/java/core/trunk/modules/jaxws-integration/test/org/apache/axis2/jaxws/jaxb/string/JAXBStringUTF8Tests.java
URL:
http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/jaxws-integration/test/org/apache/axis2/jaxws/jaxb/string/JAXBStringUTF8Tests.java?rev=941042&r1=941041&r2=941042&view=diff
==============================================================================
---
axis/axis2/java/core/trunk/modules/jaxws-integration/test/org/apache/axis2/jaxws/jaxb/string/JAXBStringUTF8Tests.java
(original)
+++
axis/axis2/java/core/trunk/modules/jaxws-integration/test/org/apache/axis2/jaxws/jaxb/string/JAXBStringUTF8Tests.java
Tue May 4 21:00:24 2010
@@ -27,6 +27,16 @@ public class JAXBStringUTF8Tests extends
runTest("a simple string");
}
+ public void testSimpleStringSwitchEncoding() throws Exception {
+ String input = "a simple string";
+ String output = "a simple string";
+
+ // Run with different encodings to verify proper processing.
+ runTestWithEncoding(input, output, null); // no encoding means to use
default, UTF-8
+ runTestWithEncoding(input, output, "UTF-16"); // Make a call with
UTF-16
+ runTestWithEncoding(input, output, null); // now try again...using
default, UTF-8
+ }
+
public void testStringWithApostrophes() throws Exception {
runTest("this isn't a simple string");
}
@@ -74,16 +84,20 @@ public class JAXBStringUTF8Tests extends
}
private void runTestWithUTF8(String input, String output) {
- runTestWithEncoding(input, output);
+ runTestWithEncoding(input, output, null); // no encoding means to use
default, UTF-8
}
- private void runTestWithEncoding(String input, String output) {
+ private void runTestWithEncoding(String input, String output, String
encoding) {
TestLogger.logger.debug("Test : " + getName());
try {
JAXBStringPortType myPort = (new
JAXBStringService()).getJAXBStringPort();
BindingProvider p = (BindingProvider) myPort;
p.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
axisEndpoint);
+ if (encoding != null) {
+
p.getRequestContext().put(org.apache.axis2.Constants.Configuration.CHARACTER_SET_ENCODING,
encoding);
+ }
+
Echo request = new Echo();
request.setArg(input);
EchoResponse response = myPort.echoString(request);
@@ -94,4 +108,5 @@ public class JAXBStringUTF8Tests extends
fail();
}
}
+
}
Modified:
axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/datasource/jaxb/JAXBDSContext.java
URL:
http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/datasource/jaxb/JAXBDSContext.java?rev=941042&r1=941041&r2=941042&view=diff
==============================================================================
---
axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/datasource/jaxb/JAXBDSContext.java
(original)
+++
axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/datasource/jaxb/JAXBDSContext.java
Tue May 4 21:00:24 2010
@@ -371,12 +371,33 @@ public class JAXBDSContext {
Marshaller m = JAXBUtils.getJAXBMarshaller(jbc);
if (writer instanceof MTOMXMLStreamWriter &&
((MTOMXMLStreamWriter) writer).getOutputFormat() != null) {
String encoding = ((MTOMXMLStreamWriter)
writer).getOutputFormat().getCharSetEncoding();
- if (encoding != null && !"UTF-8".equalsIgnoreCase(encoding)) {
+
+ String marshallerEncoding = (String)
m.getProperty(Marshaller.JAXB_ENCODING);
+
+ // Make sure that the marshaller respects the encoding of the
message.
+ // This is accomplished by setting the encoding on the
Marshaller's JAXB_ENCODING property.
+ if (encoding == null && marshallerEncoding == null) {
if (log.isDebugEnabled()) {
- log.debug("Setting the Marshaller.JAXB_ENCODING to " +
encoding);
+ log.debug("The encoding and the marshaller's
JAXB_ENCODING are both set to the default (UTF-8)");
+ }
+ } else {
+ // Must set the encoding to an actual String to set it on
the Marshaller
+ if (encoding == null) {
+ encoding = "UTF-8";
+ }
+ if (!encoding.equalsIgnoreCase(marshallerEncoding)) {
+ if (log.isDebugEnabled()) {
+ log.debug("The Marshaller.JAXB_ENCODING is " +
marshallerEncoding);
+ log.debug("The Marshaller.JAXB_ENCODING is changed
to the message encoding " +
+ encoding);
+ }
+ m.setProperty(Marshaller.JAXB_ENCODING, encoding);
+ } else {
+ if (log.isDebugEnabled()) {
+ log.debug("The encoding and the marshaller's
JAXB_ENCODING are both set to:" +
+ marshallerEncoding);
+ }
}
-
- m.setProperty(Marshaller.JAXB_ENCODING, encoding);
}
}
Modified:
axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/JAXBUtils.java
URL:
http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/JAXBUtils.java?rev=941042&r1=941041&r2=941042&view=diff
==============================================================================
---
axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/JAXBUtils.java
(original)
+++
axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/JAXBUtils.java
Tue May 4 21:00:24 2010
@@ -33,6 +33,7 @@ import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.JAXBIntrospector;
import javax.xml.bind.Marshaller;
+import javax.xml.bind.PropertyException;
import javax.xml.bind.Unmarshaller;
import javax.xml.bind.annotation.XmlType;
import javax.xml.ws.Holder;
@@ -721,8 +722,9 @@ public class JAXBUtils {
}
/**
- * releaseJAXBMarshalller Do not call this method if an exception occurred
while using the
- * Marshaller. We object my be in an invalid state.
+ * releaseJAXBMarshalller
+ * Do not call this method if an exception occurred while using the
+ * Marshaller. We don't want an object in an invalid state.
*
* @param context JAXBContext
* @param marshaller Marshaller
@@ -734,8 +736,20 @@ public class JAXBUtils {
log.debug(" JAXBContext = " +
JavaUtils.getObjectIdentity(context));
}
if (ENABLE_MARSHALL_POOLING) {
- marshaller.setAttachmentMarshaller(null);
- mpool.put(context, marshaller);
+ // Make sure to clear any state or properties
+
+ try {
+ marshaller.setAttachmentMarshaller(null);
+ // Set the JAXB_ENCODING back to the default value UTF-8
+ marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
+ mpool.put(context, marshaller);
+ } catch (Throwable t) {
+ // Log the problem, and continue without pooling
+ if (log.isDebugEnabled()) {
+ log.debug("The following exception is ignored. Processing
continues " + t);
+ }
+ }
+
}
}