Author: veithen Date: Tue Dec 16 08:43:25 2008 New Revision: 727083 URL: http://svn.apache.org/viewvc?rev=727083&view=rev Log: WSCOMMONS-329: Applied patch provided by Michael Kaye (with some minor modifications in the tests). This solves a problem with the code in getSOAPPartContentID that strips the "cid:" prefix from the "start" parameter.
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-tests/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=727083&r1=727082&r2=727083&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 Tue Dec 16 08:43:25 2008 @@ -440,8 +440,9 @@ .length() - 1)); } } - // Strips off the "cid" part from content-id - if ("cid".equalsIgnoreCase(rootContentID.substring(0, 3))) { + // Strips off the "cid:" part from content-id + if (rootContentID.length() > 4 + && "cid:".equalsIgnoreCase(rootContentID.substring(0, 4))) { rootContentID = rootContentID.substring(4); } return rootContentID; Modified: webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/attachments/AttachmentsTest.java URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/attachments/AttachmentsTest.java?rev=727083&r1=727082&r2=727083&view=diff ============================================================================== --- webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/attachments/AttachmentsTest.java (original) +++ webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/attachments/AttachmentsTest.java Tue Dec 16 08:43:25 2008 @@ -348,4 +348,46 @@ } return byteStream.toByteArray(); } + + private void testGetSOAPPartContentID(String contentTypeStartParam, String contentId) + throws Exception { + // It doesn't actually matter what the stream *is* it just needs to exist + String contentType = "multipart/related; boundary=\"" + boundary + + "\"; type=\"text/xml\"; start=\"" + contentTypeStartParam + "\""; + InputStream inStream = new FileInputStream(getTestResourceFile(inMimeFileName)); + Attachments attachments = new Attachments(inStream, contentType); + assertEquals("Did not obtain correct content ID", contentId, + attachments.getSOAPPartContentID()); + } + + public void testGetSOAPPartContentIDWithoutBrackets() throws Exception { + testGetSOAPPartContentID("my-content...@localhost", "my-content...@localhost"); + } + + public void testGetSOAPPartContentIDWithBrackets() throws Exception { + testGetSOAPPartContentID("<my-content...@localhost>", "my-content...@localhost"); + } + + // Not sure when exactly somebody uses the "cid:" prefix in the start parameter, but + // this is how the code currently works. + public void testGetSOAPPartContentIDWithCidPrefix() throws Exception { + testGetSOAPPartContentID("cid:my-content-id@localhost", "my-content...@localhost"); + } + + // Regression test for WSCOMMONS-329 + public void testGetSOAPPartContentIDWithCidPrefix2() throws Exception { + testGetSOAPPartContentID("<cid-73...@192.168.0.1>", "cid-73...@192.168.0.1"); + } + + public void testGetSOAPPartContentIDShort() throws Exception { + testGetSOAPPartContentID("bbb", "bbb"); + } + + public void testGetSOAPPartContentIDShortWithBrackets() throws Exception { + testGetSOAPPartContentID("<b>", "b"); + } + + public void testGetSOAPPartContentIDBorderline() throws Exception { + testGetSOAPPartContentID("cid:", "cid:"); + } }