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/05/22 13:31:56 UTC
svn commit: r1125914 - in
/webservices/commons/trunk/modules/axiom/modules/axiom-api/src:
main/java/org/apache/axiom/attachments/Attachments.java
test/java/org/apache/axiom/attachments/AttachmentsTest.java
Author: veithen
Date: Sun May 22 11:31:56 2011
New Revision: 1125914
URL: http://svn.apache.org/viewvc?rev=1125914&view=rev
Log:
Added some sanity checks to Attachments#getSOAPPartContentType().
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/Attachments.java
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/attachments/AttachmentsTest.java
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/Attachments.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/Attachments.java?rev=1125914&r1=1125913&r2=1125914&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/Attachments.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/Attachments.java Sun May 22 11:31:56 2011
@@ -471,7 +471,14 @@ public class Attachments implements OMAt
*/
public String getSOAPPartContentType() {
if (!noStreams) {
- DataHandler soapPart = getDataHandler(getSOAPPartContentID());
+ String soapPartContentID = getSOAPPartContentID();
+ if (soapPartContentID == null) {
+ throw new OMException("Unable to determine the content ID of the SOAP part");
+ }
+ DataHandler soapPart = getDataHandler(soapPartContentID);
+ if (soapPart == null) {
+ throw new OMException("Unable to locate the SOAP part; content ID was " + soapPartContentID);
+ }
return soapPart.getContentType();
} else {
throw new OMException(
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/attachments/AttachmentsTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/attachments/AttachmentsTest.java?rev=1125914&r1=1125913&r2=1125914&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/attachments/AttachmentsTest.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/attachments/AttachmentsTest.java Sun May 22 11:31:56 2011
@@ -27,6 +27,7 @@ import javax.activation.DataHandler;
import org.apache.axiom.attachments.utils.IOUtils;
import org.apache.axiom.om.AbstractTestCase;
+import org.apache.axiom.om.OMException;
import org.apache.axiom.om.TestConstants;
import org.apache.axiom.testutils.io.IOTestUtils;
@@ -119,6 +120,24 @@ public class AttachmentsTest extends Abs
testGetSOAPPartContentID("cid:", "cid:");
}
+ /**
+ * Tests that {@link Attachments#getSOAPPartContentType()} throws a meaningful exception if it
+ * is unable to determine the content type.
+ */
+ public void testGetSOAPPartContentTypeWithContentIDMismatch() {
+ String contentType = "multipart/related; boundary=\"" + TestConstants.MTOM_MESSAGE_BOUNDARY +
+ "\"; type=\"text/xml\"; start=\"<wr...@example.org>\"";
+ Attachments attachments = new Attachments(getTestResource(TestConstants.MTOM_MESSAGE), contentType);
+ try {
+ attachments.getSOAPPartContentType();
+ fail("Expected OMException");
+ } catch (OMException ex) {
+ // OK, expected
+ } catch (Throwable ex) {
+ fail("Unexpected exception: " + ex.getClass().getName());
+ }
+ }
+
public void testGetIncomingAttachmentStreams() throws Exception {
InputStream inStream = getTestResource(TestConstants.MTOM_MESSAGE);
Attachments attachments = new Attachments(inStream, TestConstants.MTOM_MESSAGE_CONTENT_TYPE);