You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commons-dev@ws.apache.org by ve...@apache.org on 2009/07/19 21:09:45 UTC
svn commit: r795595 - in
/webservices/commons/trunk/modules/axiom/modules/axiom-api/src:
main/java/org/apache/axiom/om/impl/builder/
main/java/org/apache/axiom/soap/impl/builder/
test/java/org/apache/axiom/util/stax/xop/
Author: veithen
Date: Sun Jul 19 19:09:44 2009
New Revision: 795595
URL: http://svn.apache.org/viewvc?rev=795595&view=rev
Log:
WSCOMMONS-485: For XOP/MTOM builders, wrap the underlying parser in an XOPDecodingStreamReader (and remove the decoding logic from the builder), so that the sequence of events produced by OMStAXWrapper for XOP:Include is always the same, regardless of the caching state.
With this fix, all the XOP processing is now done inside Axiom and code interacting with Axiom through StAX (XMLStreamReader/XMLStreamWriter) should no longer have to worry about XOP:Include.
The change has been successfully regression tested with Axis2 trunk.
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/OMAttachmentAccessorMimePartProvider.java
- copied, changed from r795448, webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/xop/OMAttachmentAccessorMimePartProvider.java
Removed:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/xop/OMAttachmentAccessorMimePartProvider.java
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXBuilder.java
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/XOPAwareStAXOMBuilder.java
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/soap/impl/builder/MTOMStAXSOAPModelBuilder.java
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/xop/XOPDecodingStreamReaderTest.java
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/xop/XOPEncodingStreamReaderTest.java
Copied: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/OMAttachmentAccessorMimePartProvider.java (from r795448, webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/xop/OMAttachmentAccessorMimePartProvider.java)
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/OMAttachmentAccessorMimePartProvider.java?p2=webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/OMAttachmentAccessorMimePartProvider.java&p1=webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/xop/OMAttachmentAccessorMimePartProvider.java&r1=795448&r2=795595&rev=795595&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/xop/OMAttachmentAccessorMimePartProvider.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/OMAttachmentAccessorMimePartProvider.java Sun Jul 19 19:09:44 2009
@@ -17,14 +17,14 @@
* under the License.
*/
-package org.apache.axiom.util.stax.xop;
+package org.apache.axiom.om.impl.builder;
import java.io.IOException;
import javax.activation.DataHandler;
-import javax.xml.stream.XMLStreamException;
import org.apache.axiom.om.OMAttachmentAccessor;
+import org.apache.axiom.util.stax.xop.MimePartProvider;
/**
* Adapts an {@link OMAttachmentAccessor} instance to the {@link MimePartProvider} interface.
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXBuilder.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXBuilder.java?rev=795595&r1=795594&r2=795595&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXBuilder.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXBuilder.java Sun Jul 19 19:09:44 2009
@@ -268,8 +268,11 @@
throw new OMException(ex);
}
}
- OMText text = omfactory.createOMText(dataHandlerObject, true);
- text.setBinary(true);
+ OMText text = omfactory.createOMText(dataHandlerObject, dataHandlerReader.isOptimized());
+ String contentID = dataHandlerReader.getContentID();
+ if (contentID != null) {
+ text.setContentID(contentID);
+ }
omContainer.addChild(text);
return text;
} else {
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/XOPAwareStAXOMBuilder.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/XOPAwareStAXOMBuilder.java?rev=795595&r1=795594&r2=795595&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/XOPAwareStAXOMBuilder.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/XOPAwareStAXOMBuilder.java Sun Jul 19 19:09:44 2009
@@ -23,26 +23,20 @@
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMException;
import org.apache.axiom.om.OMFactory;
-import org.apache.axiom.om.OMNode;
-import org.apache.axiom.om.OMText;
-import org.apache.axiom.om.impl.MTOMConstants;
-import org.apache.axiom.om.impl.OMContainerEx;
-import org.apache.axiom.om.impl.OMNodeEx;
-import org.apache.axiom.om.util.ElementHelper;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+import org.apache.axiom.om.util.StAXUtils;
+import org.apache.axiom.util.stax.xop.XOPDecodingStreamReader;
import javax.activation.DataHandler;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
+
+import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
public class XOPAwareStAXOMBuilder
extends StAXOMBuilder implements XOPBuilder {
- private static final Log log = LogFactory.getLog(XOPAwareStAXOMBuilder.class);
-
/** <code>Attachments</code> handles deferred parsing of incoming MIME Messages. */
Attachments attachments;
@@ -54,7 +48,8 @@
*/
public XOPAwareStAXOMBuilder(OMFactory ombuilderFactory,
XMLStreamReader parser, Attachments attachments) {
- super(ombuilderFactory, parser);
+ super(ombuilderFactory, new XOPDecodingStreamReader(parser,
+ new OMAttachmentAccessorMimePartProvider(attachments)));
this.attachments = attachments;
}
@@ -67,7 +62,8 @@
*/
public XOPAwareStAXOMBuilder(OMFactory factory, XMLStreamReader parser,
OMElement element, Attachments attachments) {
- super(factory, parser, element);
+ super(factory, new XOPDecodingStreamReader(parser,
+ new OMAttachmentAccessorMimePartProvider(attachments)), element);
this.attachments = attachments;
}
@@ -79,7 +75,8 @@
public XOPAwareStAXOMBuilder(String filePath, Attachments attachments)
throws XMLStreamException,
FileNotFoundException {
- super(filePath);
+ super(new XOPDecodingStreamReader(StAXUtils.createXMLStreamReader(new FileInputStream(
+ filePath)), new OMAttachmentAccessorMimePartProvider(attachments)));
this.attachments = attachments;
}
@@ -89,7 +86,8 @@
*/
public XOPAwareStAXOMBuilder(InputStream inStream, Attachments attachments)
throws XMLStreamException {
- super(inStream);
+ super(new XOPDecodingStreamReader(StAXUtils.createXMLStreamReader(inStream),
+ new OMAttachmentAccessorMimePartProvider(attachments)));
this.attachments = attachments;
}
@@ -99,54 +97,11 @@
* @param parser
*/
public XOPAwareStAXOMBuilder(XMLStreamReader parser, Attachments attachments) {
- super(parser);
+ super(new XOPDecodingStreamReader(parser, new OMAttachmentAccessorMimePartProvider(
+ attachments)));
this.attachments = attachments;
}
- /**
- * Method createOMElement. Overriding the createOMElement of StAXOMBuilder to to XOP aware
- * building
- *
- * @return Returns OMNode.
- * @throws OMException
- */
- protected OMNode createOMElement() throws OMException {
-
- String elementName = parser.getLocalName();
- String namespaceURI = parser.getNamespaceURI();
- if (MTOMConstants.XOP_INCLUDE.equals(elementName)
- && MTOMConstants.XOP_NAMESPACE_URI.equals(namespaceURI)) {
- OMText node;
- String contentID = ElementHelper.getContentID(parser);
- if (log.isDebugEnabled()) {
- log.debug("Encountered xop:include for cid:" + contentID);
- }
-
- if (lastNode == null) {
- throw new OMException(
- "XOP:Include element is not supported here");
- } else if (lastNode.isComplete() & lastNode.getParent() != null) {
- node = omfactory.createOMText(contentID, (OMElement) lastNode
- .getParent(), this);
- if (log.isDebugEnabled()) {
- log.debug("Create createOMText for cid:" + contentID);
- Object dh = node.getDataHandler();
- String dhClass = (dh==null) ? "null" : dh.getClass().toString();
- log.debug("The datahandler is " + dhClass);
- }
- ((OMNodeEx) lastNode).setNextOMSibling(node);
- ((OMNodeEx) node).setPreviousOMSibling(lastNode);
- } else {
- OMContainerEx e = (OMContainerEx) lastNode;
- node = omfactory.createOMText(contentID, (OMElement) lastNode, this);
- e.setFirstChild(node);
- }
- return node;
- } else {
- return super.createOMElement();
- }
- }
-
public DataHandler getDataHandler(String blobContentID) throws OMException {
return attachments.getDataHandler(blobContentID);
}
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/soap/impl/builder/MTOMStAXSOAPModelBuilder.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/soap/impl/builder/MTOMStAXSOAPModelBuilder.java?rev=795595&r1=795594&r2=795595&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/soap/impl/builder/MTOMStAXSOAPModelBuilder.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/soap/impl/builder/MTOMStAXSOAPModelBuilder.java Sun Jul 19 19:09:44 2009
@@ -20,27 +20,17 @@
package org.apache.axiom.soap.impl.builder;
import org.apache.axiom.attachments.Attachments;
-import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMException;
-import org.apache.axiom.om.OMNode;
-import org.apache.axiom.om.OMText;
-import org.apache.axiom.om.impl.MTOMConstants;
-import org.apache.axiom.om.impl.OMContainerEx;
-import org.apache.axiom.om.impl.OMNodeEx;
+import org.apache.axiom.om.impl.builder.OMAttachmentAccessorMimePartProvider;
import org.apache.axiom.om.impl.builder.XOPBuilder;
-import org.apache.axiom.om.util.ElementHelper;
import org.apache.axiom.soap.SOAPFactory;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+import org.apache.axiom.util.stax.xop.XOPDecodingStreamReader;
import javax.activation.DataHandler;
import javax.xml.stream.XMLStreamReader;
-public class MTOMStAXSOAPModelBuilder extends StAXSOAPModelBuilder implements
- MTOMConstants, XOPBuilder {
+public class MTOMStAXSOAPModelBuilder extends StAXSOAPModelBuilder implements XOPBuilder {
- private static final Log log = LogFactory.getLog(MTOMStAXSOAPModelBuilder.class);
-
/** <code>Attachments</code> handles deferred parsing of incoming MIME Messages. */
Attachments attachments;
@@ -49,7 +39,8 @@
public MTOMStAXSOAPModelBuilder(XMLStreamReader parser,
SOAPFactory factory, Attachments attachments,
String soapVersion) {
- super(parser, factory, soapVersion);
+ super(new XOPDecodingStreamReader(parser, new OMAttachmentAccessorMimePartProvider(
+ attachments)), factory, soapVersion);
this.attachments = attachments;
}
@@ -59,56 +50,18 @@
*/
public MTOMStAXSOAPModelBuilder(XMLStreamReader reader,
Attachments attachments, String soapVersion) {
- super(reader, soapVersion);
+ super(new XOPDecodingStreamReader(reader, new OMAttachmentAccessorMimePartProvider(
+ attachments)), soapVersion);
this.attachments = attachments;
}
public MTOMStAXSOAPModelBuilder(XMLStreamReader reader,
Attachments attachments) {
- super(reader);
+ super(new XOPDecodingStreamReader(reader, new OMAttachmentAccessorMimePartProvider(
+ attachments)));
this.attachments = attachments;
}
- protected OMNode createOMElement() throws OMException {
-
- String elementName = parser.getLocalName();
- String namespaceURI = parser.getNamespaceURI();
-
- // create an OMBlob if the element is an <xop:Include>
- if (XOP_INCLUDE.equals(elementName) && XOP_NAMESPACE_URI.equals(namespaceURI)) {
- OMText node;
- String contentID = ElementHelper.getContentID(parser);
-
- if (log.isDebugEnabled()) {
- log.debug("Encountered xop:include for cid:" + contentID);
- }
-
- if (lastNode == null) {
- throw new OMException(
- "XOP:Include element is not supported here");
- } else if (lastNode.isComplete() & lastNode.getParent() != null) {
- node = omfactory.createOMText(contentID, lastNode.getParent(), this);
- ((OMNodeEx) lastNode).setNextOMSibling(node);
- ((OMNodeEx) node).setPreviousOMSibling(lastNode);
- if (log.isDebugEnabled()) {
- log.debug("Create createOMText for cid:" + contentID);
- Object dh = node.getDataHandler();
- String dhClass = (dh==null) ? "null" : dh.getClass().toString();
- log.debug("The datahandler is " + dhClass);
- }
- } else {
- OMContainerEx e = (OMContainerEx) lastNode;
- node = omfactory.createOMText(contentID, (OMElement) lastNode,
- this);
- e.setFirstChild(node);
- }
- return node;
-
- } else {
- return super.createOMElement();
- }
- }
-
/* (non-Javadoc)
* @see org.apache.axiom.soap.impl.builder.XOPBuilder#getDataHandler(java.lang.String)
*/
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/xop/XOPDecodingStreamReaderTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/xop/XOPDecodingStreamReaderTest.java?rev=795595&r1=795594&r2=795595&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/xop/XOPDecodingStreamReaderTest.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/xop/XOPDecodingStreamReaderTest.java Sun Jul 19 19:09:44 2009
@@ -27,6 +27,7 @@
import org.apache.axiom.attachments.Attachments;
import org.apache.axiom.om.AbstractTestCase;
import org.apache.axiom.om.TestConstants;
+import org.apache.axiom.om.impl.builder.OMAttachmentAccessorMimePartProvider;
import org.apache.axiom.om.util.Base64;
import org.apache.axiom.om.util.StAXUtils;
import org.apache.axiom.util.stax.XMLStreamReaderComparator;
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/xop/XOPEncodingStreamReaderTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/xop/XOPEncodingStreamReaderTest.java?rev=795595&r1=795594&r2=795595&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/xop/XOPEncodingStreamReaderTest.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/xop/XOPEncodingStreamReaderTest.java Sun Jul 19 19:09:44 2009
@@ -24,6 +24,7 @@
import org.apache.axiom.attachments.Attachments;
import org.apache.axiom.om.AbstractTestCase;
import org.apache.axiom.om.TestConstants;
+import org.apache.axiom.om.impl.builder.OMAttachmentAccessorMimePartProvider;
import org.apache.axiom.om.util.StAXUtils;
import org.apache.axiom.util.stax.XMLStreamReaderComparator;
import org.apache.axiom.util.stax.xop.ContentIDGenerator;