Author: ngallardo
Date: Fri Jan 11 08:10:18 2008
New Revision: 611218

URL: http://svn.apache.org/viewvc?rev=611218&view=rev
Log:
WSCOMMONS-290

Changes to provide a more compliant Content-Type for SOAP 1.2/MTOM.

Added:
    
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

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=611218&r1=611217&r2=611218&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
 Fri Jan 11 08:10:18 2008
@@ -51,6 +51,8 @@
     private boolean ignoreXMLDeclaration = false;
     private boolean autoCloseWriter = false;
 
+    public static final String ACTION_PROPERTY = "action";
+    
     HashMap map = null;  // Map of generic properties
 
 
@@ -209,7 +211,29 @@
         this.doingSWA = doingSWA;
     }
 
+    /**
+     * Generates a Content-Type value for MTOM messages.  This is a MIME 
Multipart/Related
+     * Content-Type value as defined by RFC 2387 and the XOP specification.  
The generated
+     * header will look like the following:
+     * 
+     *   Content-Type: multipart/related; boundary=[MIME BOUNDARY VALUE]; 
+     *      type="application/xop+xml"; 
+     *      start="[MESSAGE CONTENT ID]"; 
+     *      start-info="[MESSAGE CONTENT TYPE]";
+     * 
+     * @param SOAPContentType
+     * @return
+     */
     public String getContentTypeForMTOM(String SOAPContentType) {
+        // If an action was set, we need to include it within the value 
+        // for the start-info attribute.  
+        if (containsKey(ACTION_PROPERTY)) {
+            String action = (String) getProperty(ACTION_PROPERTY);
+            if (action != null && action.length() > 0) {
+                SOAPContentType = SOAPContentType + "; action=\\\"" + action + 
"\\\"";   
+            }                     
+        }
+        
         StringBuffer sb = new StringBuffer();
         sb.append("multipart/related");
         sb.append("; ");

Added: 
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=611218&view=auto
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/OMOutputFormatTest.java
 (added)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/OMOutputFormatTest.java
 Fri Jan 11 08:10:18 2008
@@ -0,0 +1,103 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.axiom.om;
+
+import org.apache.axiom.om.impl.MTOMConstants;
+import org.apache.axiom.soap.SOAP11Constants;
+import org.apache.axiom.soap.SOAP12Constants;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+import junit.framework.TestCase;
+
+public class OMOutputFormatTest extends TestCase {
+    
+    public void testAPI_getProperty() throws Exception {
+        Method m = OMOutputFormat.class.getMethod("getProperty", new Class[] 
{String.class});
+        assertTrue(m != null);
+        
+        Class returnType = m.getReturnType();
+        assertTrue(returnType == Object.class);
+    }
+    
+    public void testAPI_setProperty() throws Exception {
+        Method m = OMOutputFormat.class.getMethod("setProperty", new Class[] 
{String.class, Object.class});
+        assertTrue(m != null);
+        
+        Class returnType = m.getReturnType();
+        assertTrue(returnType == Object.class);
+    }
+    
+    public void testAPI_publicProperties() throws Exception {
+        Field f = OMOutputFormat.class.getField("ACTION_PROPERTY");
+        assertTrue(f != null);        
+    }
+
+    public void testGetContentTypeDefault() {
+        OMOutputFormat format = new OMOutputFormat();
+        String contentType = format.getContentType();
+        assertTrue(contentType.equals(SOAP11Constants.SOAP_11_CONTENT_TYPE));
+    }
+    
+    public void testGetContentTypeSOAP12() {
+        OMOutputFormat format = new OMOutputFormat();
+        format.setSOAP11(false);
+        String contentType = format.getContentType();
+        assertTrue(contentType.equals(SOAP12Constants.SOAP_12_CONTENT_TYPE));
+    }
+    
+    public void testGetContentTypeSOAP11MTOM() {
+        OMOutputFormat format = new OMOutputFormat();
+        format.setDoOptimize(true);
+        String contentType = format.getContentType();
+        
+        // This is rudimentary.  We can add a more complete test that checks
+        // sub items in the future.
+        assertTrue(contentType.contains(SOAP11Constants.SOAP_11_CONTENT_TYPE));
+        assertTrue(contentType.contains(MTOMConstants.MTOM_TYPE));
+    }
+    
+    public void testGetContentTypeSOAP12MTOM() {
+        OMOutputFormat format = new OMOutputFormat();
+        format.setDoOptimize(true);
+        format.setSOAP11(false);
+        String contentType = format.getContentType();
+        
+        // This is rudimentary.  We can add a more complete test that checks
+        // sub items in the future.
+        assertTrue(contentType.contains(SOAP12Constants.SOAP_12_CONTENT_TYPE));
+        assertTrue(contentType.contains(MTOMConstants.MTOM_TYPE));
+    }
+    
+    public void testGetContentTypeSOAP12MTOMWithAction() {
+        OMOutputFormat format = new OMOutputFormat();
+        format.setDoOptimize(true);
+        format.setSOAP11(false);
+        format.setProperty(OMOutputFormat.ACTION_PROPERTY, "testSoapAction");
+        String contentType = format.getContentType();
+        
+        // This is rudimentary.  We can add a more complete test that checks
+        // sub items in the future.
+        assertTrue(contentType.contains(SOAP12Constants.SOAP_12_CONTENT_TYPE));
+        assertTrue(contentType.contains(MTOMConstants.MTOM_TYPE));
+        assertTrue(contentType.contains("action=\\\"testSoapAction\\\""));
+    }
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to