[jboss-svn-commits] JBossWS SVN: r721 - in branches/jbossws-1.0_Heiko/src/main/java/org/jboss/ws: soap xop

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Thu Aug 10 07:26:10 EDT 2006


Author: heiko.braun at jboss.com
Date: 2006-08-10 07:26:06 -0400 (Thu, 10 Aug 2006)
New Revision: 721

Modified:
   branches/jbossws-1.0_Heiko/src/main/java/org/jboss/ws/soap/SOAPContentElement.java
   branches/jbossws-1.0_Heiko/src/main/java/org/jboss/ws/xop/XOPContext.java
   branches/jbossws-1.0_Heiko/src/main/java/org/jboss/ws/xop/XOPMarshallerImpl.java
Log:
improved MTOM documentation

Modified: branches/jbossws-1.0_Heiko/src/main/java/org/jboss/ws/soap/SOAPContentElement.java
===================================================================
--- branches/jbossws-1.0_Heiko/src/main/java/org/jboss/ws/soap/SOAPContentElement.java	2006-08-10 10:51:21 UTC (rev 720)
+++ branches/jbossws-1.0_Heiko/src/main/java/org/jboss/ws/soap/SOAPContentElement.java	2006-08-10 11:26:06 UTC (rev 721)
@@ -235,7 +235,6 @@
             DeserializerFactoryBase deserializerFactory = getDeserializerFactory(typeMapping, javaType, xmlType);
             DeserializerSupport des = (DeserializerSupport)deserializerFactory.getDeserializer();
 
-            //String strContent = insertNamespaceDeclarations(getXMLFragment());
             String strContent = getXMLFragment();
 
             Object obj = des.deserialize(getQName(), xmlType, strContent, serContext);
@@ -815,11 +814,6 @@
       // SOAPContentElements should only be expanded when jaxxrpc handlers do require it.
       boolean domExpansionEnabled = ThreadLocalAssociation.localDomExpansion().get().booleanValue();
 
-      if(!domExpansionEnabled)
-         log.debug("*** DOMExpansion disabled ***");
-      else
-         log.debug("*** Expand to DOM called ***", new RuntimeException("Show Callee"));
-
       if (isDOMValid == false && expandingToDOM == false && domExpansionEnabled)
       {
          log.trace("BEGIN: expandToDOM");
@@ -896,7 +890,8 @@
             log.trace("END: expandToDOM");
          }
 
-         // FIXME JBWS-482, This is a workaround
+         // Either the dom-valid state, or the xml-valid state can be true
+         // Therefore we invalidate the xml content.
          invalidateXMLContent();
       }
    }
@@ -1001,6 +996,18 @@
       return null;
    }
 
+   /**
+    * When a SOAPContentElement transitions between dom-valid and xml-valid
+    * the XOP elements need to transition from XOP optimized to base64 and reverse.<p>
+    *
+    * If MTOM is disabled through a message context property we always enforce the
+    * base64 representation by expanding to DOM, the same happens when a JAXRPC handler
+    * accesses the SOAPContentElement.<p>
+    *
+    * If the element is in dom-valid state (because a handlers accessed it), upon marshalling
+    * it's needs to be decided wether or not the <code>xop:Include</code> should be restored.
+    * This as well depends upon the message context property.
+    */
    private void handleMTOMTransitions() {
 
       boolean isXOPParameter = paramMetaData != null && paramMetaData.isXOP();
@@ -1019,7 +1026,7 @@
          // When the DOM representation is valid,
          // but MTOM is enabled we need to convert the inlined
          // element back to an xop:Include element and create the attachment part
-         XOPContext.optimizeXOPData(this);
+         XOPContext.restoreXOPData(this);
       }
    }
 }

Modified: branches/jbossws-1.0_Heiko/src/main/java/org/jboss/ws/xop/XOPContext.java
===================================================================
--- branches/jbossws-1.0_Heiko/src/main/java/org/jboss/ws/xop/XOPContext.java	2006-08-10 10:51:21 UTC (rev 720)
+++ branches/jbossws-1.0_Heiko/src/main/java/org/jboss/ws/xop/XOPContext.java	2006-08-10 11:26:06 UTC (rev 721)
@@ -46,8 +46,15 @@
 
 /**
  * XOP context associated with a message context.
+ * Acts as a facade to the current soap message and supports the various
+ * XOP transitions.<p>
+ * A good starting point to understand how MTOM in JBossWS works is to take a
+ * look at the SOAPContentElement implementation.
  *
  * @see ThreadLocalAssociation
+ * @see org.jboss.ws.soap.SOAPContentElement#handleMTOMTransitions()
+ * @see XOPUnmarshallerImpl
+ * @see XOPMarshallerImpl
  *
  * @author Heiko Braun <heiko.braun at jboss.com>
  * @since May 10, 2006
@@ -55,9 +62,11 @@
  */
 public class XOPContext {
 
-   public static final String CID_PREFIX = "cid:";
    private static final String NS_XOP_JBOSSWS = "http://org.jboss.ws/xop";
 
+   /**
+    * Check if the current soap message flagged as a XOP package?
+    */
    public static boolean isXOPPackage() {
       boolean isXOP = false;
       SOAPMessageContextImpl msgContext = MessageContextAssociation.peekMessageContext();
@@ -70,7 +79,7 @@
 
    /**
     * Check if MTOM is disabled through a message context property.
-    * (<code>org.jboss.ws.mtom.enabled</code>)
+    * (<code>org.jboss.ws.mtom.enabled</code>)<br>
     * Defaults to TRUE if the property is not set.
     */
    public static boolean isMTOMEnabled()
@@ -83,7 +92,9 @@
    }
 
    /**
-    * Replace all <code>xop:Include</code> elements with it's base64 representation
+    * Replace all <code>xop:Include</code> elements with it's base64 representation.
+    * This happens when the associated SOAPContentElement transitions to state dom-valid.<br>
+    * All attachement parts will be removed.
     */
    public static void inlineXOPData(SOAPElement xopElement)
    {
@@ -104,12 +115,18 @@
       }
    }
 
-   public static void optimizeXOPData(SOAPElement xopElement)
+   /**
+    * Restore previously inlined XOP elements.
+    * All base64 representations will be replaced by <code>xop:Include</code>
+    * elements and the attachment parts will be recreated. <br>
+    * This happens when a SOAPContentElement is written to an output stream.
+    */
+   public static void restoreXOPData(SOAPElement xopElement)
    {
       String contentType = xopElement.getAttributeNS(NS_XOP_JBOSSWS, "content-type");
       if(contentType != null && contentType.length()>0)
       {
-         createXOPInclude(xopElement, contentType);
+         replaceBase64Representation(xopElement, contentType);
          xopElement.removeAttribute(new NameImpl(new QName(NS_XOP_JBOSSWS, "content-type")));
       }
       else
@@ -118,12 +135,12 @@
          while(it.hasNext())
          {
             SOAPElement childElement = (SOAPElement)it.next();
-            optimizeXOPData(childElement);
+            restoreXOPData(childElement);
          }
       }
    }
 
-   private static void createXOPInclude(SOAPElement xopElement, String contentType) {
+   private static void replaceBase64Representation(SOAPElement xopElement, String contentType) {
 
       String base64 = xopElement.getValue();
       byte[] data = SimpleTypeBindings.unmarshalBase64(base64);
@@ -191,6 +208,9 @@
 
    }
 
+   /**
+    * Access an XOP attachment part by content id (CID).
+    */
    public static AttachmentPart getAttachmentByCID(String cid) throws SOAPException
    {
       SOAPMessageContextImpl msgContext = MessageContextAssociation.peekMessageContext();
@@ -207,7 +227,11 @@
       return part;
    }
 
-   public static DataHandler getDataHandler(Object o)
+   /**
+    * Create a <code>DataHandler</code> for an object.
+    * The handlers content type is based on the java type.
+    */
+   public static DataHandler createDataHandler(Object o)
    {
       DataHandler dataHandler;
 

Modified: branches/jbossws-1.0_Heiko/src/main/java/org/jboss/ws/xop/XOPMarshallerImpl.java
===================================================================
--- branches/jbossws-1.0_Heiko/src/main/java/org/jboss/ws/xop/XOPMarshallerImpl.java	2006-08-10 10:51:21 UTC (rev 720)
+++ branches/jbossws-1.0_Heiko/src/main/java/org/jboss/ws/xop/XOPMarshallerImpl.java	2006-08-10 11:26:06 UTC (rev 721)
@@ -28,15 +28,12 @@
 import org.jboss.ws.soap.SOAPMessageImpl;
 import org.jboss.ws.soap.attachment.MimeConstants;
 import org.jboss.ws.soap.attachment.ContentHandlerRegistry;
-import org.jboss.ws.jaxrpc.StubExt;
 import org.jboss.xb.binding.sunday.xop.XOPMarshaller;
 import org.jboss.xb.binding.sunday.xop.XOPObject;
 
 import javax.activation.DataHandler;
-import javax.activation.DataSource;
 import javax.xml.namespace.QName;
 import javax.xml.soap.AttachmentPart;
-import javax.xml.rpc.handler.MessageContext;
 
 /**
  * The XOPMarshallerImpl allows callbacks from the binding layer towards the
@@ -76,7 +73,7 @@
 
       String cid = soapMessage.getCidGenerator().generateFromName(xmlName.getLocalPart());
 
-      DataHandler dataHandler = XOPContext.getDataHandler(obj.getContent());
+      DataHandler dataHandler = XOPContext.createDataHandler(obj.getContent());
       obj.setContentType(dataHandler.getContentType());
 
       AttachmentPart xopPart = soapMessage.createAttachmentPart(dataHandler);




More information about the jboss-svn-commits mailing list