You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ws.apache.org by ve...@apache.org on 2011/12/06 00:37:50 UTC
svn commit: r1210713 - in /webservices/commons/trunk/modules/axiom/modules:
axiom-api/src/main/java/org/apache/axiom/om/
axiom-testsuite/src/main/java/org/apache/axiom/ts/
axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/
axiom-testutils/sr...
Author: veithen
Date: Mon Dec 5 23:37:50 2011
New Revision: 1210713
URL: http://svn.apache.org/viewvc?rev=1210713&view=rev
Log:
Some initial code for AXIOM-403.
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/TestReadAttachmentBeforeRootPartComplete.java (with props)
webservices/commons/trunk/modules/axiom/modules/axiom-testutils/src/main/java/org/apache/axiom/testutils/RandomUtils.java (with props)
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMXMLBuilderFactory.java
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/OMTestSuiteBuilder.java
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMXMLBuilderFactory.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMXMLBuilderFactory.java?rev=1210713&r1=1210712&r2=1210713&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMXMLBuilderFactory.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMXMLBuilderFactory.java Mon Dec 5 23:37:50 2011
@@ -18,9 +18,11 @@
*/
package org.apache.axiom.om;
+import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
+import javax.activation.DataHandler;
import javax.mail.internet.ContentType;
import javax.mail.internet.ParseException;
import javax.xml.stream.XMLStreamConstants;
@@ -28,6 +30,7 @@ import javax.xml.stream.XMLStreamReader;
import javax.xml.transform.Source;
import org.apache.axiom.attachments.Attachments;
+import org.apache.axiom.attachments.lifecycle.DataHandlerExt;
import org.apache.axiom.om.impl.builder.OMAttachmentAccessorMimePartProvider;
import org.apache.axiom.om.util.StAXParserConfiguration;
import org.apache.axiom.soap.SOAPFactory;
@@ -346,8 +349,7 @@ public class OMXMLBuilderFactory {
} catch (ParseException ex) {
throw new OMException(ex);
}
- InputSource rootPart = new InputSource(attachments.getRootPartInputStream());
- rootPart.setEncoding(contentType.getParameter("charset"));
+ InputSource rootPart = getRootPartInputSource(attachments, contentType);
return omFactory.getMetaFactory().createOMBuilder(configuration, omFactory,
rootPart, new OMAttachmentAccessorMimePartProvider(attachments));
}
@@ -485,9 +487,29 @@ public class OMXMLBuilderFactory {
} else {
throw new OMException("Unable to determine SOAP version");
}
- InputSource rootPart = new InputSource(attachments.getRootPartInputStream());
- rootPart.setEncoding(contentType.getParameter("charset"));
+ InputSource rootPart = getRootPartInputSource(attachments, contentType);
return metaFactory.createSOAPModelBuilder(StAXParserConfiguration.SOAP, soapFactory,
rootPart, new OMAttachmentAccessorMimePartProvider(attachments));
}
+
+ private static InputSource getRootPartInputSource(Attachments attachments, ContentType contentType) {
+ DataHandler dh = attachments.getDataHandler(attachments.getRootPartContentID());
+ if (dh == null) {
+ throw new OMException("Root part not found in MIME message");
+ }
+ InputStream in;
+ try {
+ // TODO: AXIOM-403
+// if (dh instanceof DataHandlerExt) {
+// in = ((DataHandlerExt)dh).readOnce();
+// } else {
+ in = dh.getInputStream();
+// }
+ } catch (IOException ex) {
+ throw new OMException("Unable to get input stream from root MIME part", ex);
+ }
+ InputSource rootPart = new InputSource(in);
+ rootPart.setEncoding(contentType.getParameter("charset"));
+ return rootPart;
+ }
}
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/OMTestSuiteBuilder.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/OMTestSuiteBuilder.java?rev=1210713&r1=1210712&r2=1210713&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/OMTestSuiteBuilder.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/OMTestSuiteBuilder.java Mon Dec 5 23:37:50 2011
@@ -70,6 +70,7 @@ public class OMTestSuiteBuilder extends
addTest(new org.apache.axiom.ts.om.builder.TestGetDocumentElementWithIllFormedDocument(metaFactory));
addTest(new org.apache.axiom.ts.om.builder.TestInvalidXML(metaFactory));
addTest(new org.apache.axiom.ts.om.builder.TestIOExceptionInGetText(metaFactory));
+ addTest(new org.apache.axiom.ts.om.builder.TestReadAttachmentBeforeRootPartComplete(metaFactory));
addTest(new org.apache.axiom.ts.om.builder.TestStandaloneConfiguration(metaFactory));
for (int i=0; i<conformanceFiles.length; i++) {
for (int j=0; j<containerFactories.length; j++) {
Added: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/TestReadAttachmentBeforeRootPartComplete.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/TestReadAttachmentBeforeRootPartComplete.java?rev=1210713&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/TestReadAttachmentBeforeRootPartComplete.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/TestReadAttachmentBeforeRootPartComplete.java Mon Dec 5 23:37:50 2011
@@ -0,0 +1,96 @@
+/*
+ * 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.ts.om.builder;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+
+import javax.activation.DataHandler;
+import javax.activation.DataSource;
+
+import org.apache.axiom.attachments.Attachments;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMMetaFactory;
+import org.apache.axiom.om.OMOutputFormat;
+import org.apache.axiom.om.OMText;
+import org.apache.axiom.om.OMXMLBuilderFactory;
+import org.apache.axiom.om.OMXMLParserWrapper;
+import org.apache.axiom.om.util.StAXParserConfiguration;
+import org.apache.axiom.testutils.RandomUtils;
+import org.apache.axiom.testutils.activation.RandomDataSource;
+import org.apache.axiom.ts.AxiomTestCase;
+import org.apache.axiom.testutils.io.IOTestUtils;
+
+/**
+ * Tests that the content of the root part of an XOP message is buffered, i.e. that an attachment
+ * part can be accessed before the object model for the root part has been built completely.
+ * <p>
+ * Note:
+ * <ul>
+ * <li>Axiom <= 1.2.12 reads the content of the root part into a buffer before creating the
+ * parser.
+ * <li>In Axiom 1.2.13 the root part is buffered on-demand (as described in <a
+ * href="https://issues.apache.org/jira/browse/AXIOM-403">AXIOM-403</a>) and this unit test checks
+ * that this feature is working as expected.
+ * </ul>
+ */
+public class TestReadAttachmentBeforeRootPartComplete extends AxiomTestCase {
+ public TestReadAttachmentBeforeRootPartComplete(OMMetaFactory metaFactory) {
+ super(metaFactory);
+ }
+
+ protected void runTest() throws Throwable {
+ OMFactory factory = metaFactory.getOMFactory();
+
+ // Programmatically create the message
+ OMElement orgRoot = factory.createOMElement("root", null);
+ OMElement orgChild1 = factory.createOMElement("child1", null, orgRoot);
+ DataSource ds = new RandomDataSource(54321, 4096);
+ orgChild1.addChild(factory.createOMText(new DataHandler(ds), true));
+ // Create a child with a large text content and insert it after the binary node.
+ // If we don't do this, then the root part may be buffered entirely by the parser,
+ // and the test would not be effective.
+ OMElement orgChild2 = factory.createOMElement("child2", null, orgRoot);
+ String s = RandomUtils.randomString(128*1024);
+ orgChild2.setText(s);
+
+ // Serialize the message
+ OMOutputFormat format = new OMOutputFormat();
+ format.setDoOptimize(true);
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ orgRoot.serialize(baos, format);
+
+ // Parse the message
+ OMXMLParserWrapper builder = OMXMLBuilderFactory.createOMBuilder(factory,
+ StAXParserConfiguration.NON_COALESCING,
+ new Attachments(new ByteArrayInputStream(baos.toByteArray()),
+ format.getContentType()));
+ OMElement root = builder.getDocumentElement();
+ OMElement child1 = (OMElement)root.getFirstOMChild();
+ OMText text = (OMText)child1.getFirstOMChild();
+ assertTrue(text.isBinary());
+ // Access the DataHandler
+ DataHandler dh = (DataHandler)text.getDataHandler();
+ IOTestUtils.compareStreams(ds.getInputStream(), dh.getInputStream());
+ OMElement child2 = (OMElement)child1.getNextOMSibling();
+ assertFalse(child2.isComplete());
+ assertEquals(s, child2.getText());
+ }
+}
Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/TestReadAttachmentBeforeRootPartComplete.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: webservices/commons/trunk/modules/axiom/modules/axiom-testutils/src/main/java/org/apache/axiom/testutils/RandomUtils.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testutils/src/main/java/org/apache/axiom/testutils/RandomUtils.java?rev=1210713&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testutils/src/main/java/org/apache/axiom/testutils/RandomUtils.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testutils/src/main/java/org/apache/axiom/testutils/RandomUtils.java Mon Dec 5 23:37:50 2011
@@ -0,0 +1,34 @@
+/*
+ * 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.testutils;
+
+import java.util.Random;
+
+public final class RandomUtils {
+ private RandomUtils() {}
+
+ public static String randomString(int length) {
+ Random random = new Random();
+ char[] chars = new char[length];
+ for (int i=0; i<length; i++) {
+ chars[i] = (char)(32 + random.nextInt(95));
+ }
+ return new String(chars);
+ }
+}
Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-testutils/src/main/java/org/apache/axiom/testutils/RandomUtils.java
------------------------------------------------------------------------------
svn:eol-style = native