Author: scheu
Date: Tue Mar 18 16:45:34 2008
New Revision: 638642
URL: http://svn.apache.org/viewvc?rev=638642&view=rev
Log:
WSCOMMONS-313
Contributor:Rich Scheuerle
Contributed small change to prefer doingSWA when both doOptimize and doingSWA
are set.
Also added to OMOutputFormat.toString() implementation to dump internal state.
This is helpful for
debug trace. Added a small validation test for this fix.
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMOutputFormat.java
webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/OMOutputFormatTest.java
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMOutputFormat.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMOutputFormat.java?rev=638642&r1=638641&r2=638642&view=diff
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMOutputFormat.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMOutputFormat.java
Tue Mar 18 16:45:34 2008
@@ -23,6 +23,8 @@
import org.apache.axiom.om.util.UUIDGenerator;
import org.apache.axiom.soap.SOAP11Constants;
import org.apache.axiom.soap.SOAP12Constants;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import java.util.HashMap;
@@ -35,6 +37,9 @@
* OMOutputFormat and not to change them later.
*/
public class OMOutputFormat {
+
+ private Log log = LogFactory.getLog(OMOutputFormat.class);
+
private String mimeBoundary = null;
private String rootContentId = null;
private int nextid = 0;
@@ -94,7 +99,7 @@
}
public boolean isOptimized() {
- return doOptimize;
+ return doOptimize && !doingSWA; // optimize is disabled if SWA
}
/**
@@ -104,6 +109,10 @@
*/
public String getContentType() {
+ String ct = null;
+ if (log.isDebugEnabled()) {
+ log.debug("Start getContentType: " + toString());
+ }
if (contentType == null) {
if (isSoap11) {
contentType = SOAP11Constants.SOAP_11_CONTENT_TYPE;
@@ -114,12 +123,23 @@
// If MTOM or SWA, the returned content-type is an
// appropriate multipart/related content type.
if (isOptimized()) {
- return this.getContentTypeForMTOM(contentType);
+ if (isDoingSWA()) {
+ // If both optimized and SWA, then prefer SWA
+ // for the content type
+ ct = this.getContentTypeForSwA(contentType);
+ } else {
+ // Optimized without SWA is MTOM
+ ct = this.getContentTypeForMTOM(contentType);
+ }
} else if (isDoingSWA()) {
- return this.getContentTypeForSwA(contentType);
+ ct = this.getContentTypeForSwA(contentType);
} else {
- return contentType;
+ ct = contentType;
+ }
+ if (log.isDebugEnabled()) {
+ log.debug("getContentType= {" + ct + "} " + toString());
}
+ return ct;
}
/**
@@ -275,4 +295,53 @@
public void setRootContentId(String rootContentId) {
this.rootContentId = rootContentId;
}
+
+
+ /**
+ * Use toString for logging state of the OMOutputFormat
+ */
+ public String toString() {
+ StringBuffer sb = new StringBuffer();
+ sb.append("OMOutputFormat [");
+
+ sb.append(" mimeBoundary =");
+ sb.append(mimeBoundary);
+
+ sb.append(" rootContentId=");
+ sb.append(rootContentId);
+
+ sb.append(" doOptimize=");
+ sb.append(doOptimize);
+
+ sb.append(" doingSWA=");
+ sb.append(doingSWA);
+
+ sb.append(" isSOAP11=");
+ sb.append(isSoap11);
+
+ sb.append(" charSetEncoding=");
+ sb.append(charSetEncoding);
+
+ sb.append(" xmlVersion=");
+ sb.append(xmlVersion);
+
+ sb.append(" contentType=");
+ sb.append(contentType);
+
+ sb.append(" ignoreXmlDeclaration=");
+ sb.append(ignoreXMLDeclaration);
+
+ sb.append(" autoCloseWriter=");
+ sb.append(autoCloseWriter);
+
+ // TODO Print all properties
+ sb.append(" actionProperty=");
+ sb.append(getProperty(ACTION_PROPERTY));
+
+ sb.append("]");
+ return sb.toString();
+
+ }
+
+
}
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/OMOutputFormatTest.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/OMOutputFormatTest.java?rev=638642&r1=638641&r2=638642&view=diff
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/OMOutputFormatTest.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/OMOutputFormatTest.java
Tue Mar 18 16:45:34 2008
@@ -75,6 +75,36 @@
assertTrue(contentType.indexOf(MTOMConstants.MTOM_TYPE)!=-1);
}
+ public void testGetContentTypeSOAP11SWA() {
+ OMOutputFormat format = new OMOutputFormat();
+ format.setSOAP11(true);
+ format.setDoingSWA(true);
+ String contentType = format.getContentType();
+
+ // This is rudimentary. We can add a more complete test that checks
+ // sub items in the future.
+
assertTrue(contentType.indexOf(SOAP11Constants.SOAP_11_CONTENT_TYPE)>=0);
+ assertTrue(contentType.indexOf("multipart/related")>=0);
+ assertTrue(contentType.indexOf(MTOMConstants.MTOM_TYPE) < 0);
+
+ // Sometimes the OMOutputFormat has both "optimized" and "doing swa".
+ // In such cases, the winner should be swa.
+
+ format = new OMOutputFormat();
+ format.setSOAP11(true);
+ format.setDoingSWA(true);
+ format.setDoOptimize(true);
+ contentType = format.getContentType();
+
+ // This is rudimentary. We can add a more complete test that checks
+ // sub items in the future.
+
assertTrue(contentType.indexOf(SOAP11Constants.SOAP_11_CONTENT_TYPE)>=0);
+ assertTrue(contentType.indexOf("multipart/related")>=0);
+ assertTrue(contentType.indexOf(MTOMConstants.MTOM_TYPE) < 0);
+
+
+ }
+
public void testGetContentTypeSOAP12MTOM() {
OMOutputFormat format = new OMOutputFormat();
format.setDoOptimize(true);
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]