-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[1.x] Enable multipart/related on FileUpload (#314)
* added ability to use content-type: multipart/related * reformatted a part from the new test * added line-break on test * set field multipartRelated to be final * removed unnecessary condition * added as a contributor * small polishings due to code review * Javadoc --------- Co-authored-by: Gary Gregory <[email protected]>
- Loading branch information
1 parent
91a6840
commit feeece4
Showing
3 changed files
with
78 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -177,6 +177,10 @@ | |
<name>fangwentong</name> | ||
<email>[email protected]</email> | ||
</contributor> | ||
<contributor> | ||
<name>mufasa1976</name> | ||
<email>[email protected]</email> | ||
</contributor> | ||
</contributors> | ||
|
||
<scm> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ | |
|
||
import java.io.IOException; | ||
import java.io.UnsupportedEncodingException; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.List; | ||
|
||
import org.apache.commons.fileupload.portlet.PortletFileUploadTest; | ||
|
@@ -394,4 +395,52 @@ private void assertHeaders(final String[] pHeaderNames, final String[] pHeaderVa | |
} | ||
} | ||
} | ||
|
||
/** | ||
* Test for multipart/related without any content-disposition Header. | ||
* This kind of Content-Type is commonly used by SOAP-Requests with Attachments (MTOM) | ||
*/ | ||
@Test | ||
public void testMultipartRelated() throws FileUploadException { | ||
final String soapEnvelope = | ||
"<soap:Envelope xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope\">\r\n" + | ||
" <soap:Header></soap:Header>\r\n" + | ||
" <soap:Body>\r\n" + | ||
" <ns1:Test xmlns:ns1=\"http://www.test.org/some-test-namespace\">\r\n" + | ||
" <ns1:Attachment>\r\n" + | ||
" <xop:Include xmlns:xop=\"http://www.w3.org/2004/08/xop/include\"" + | ||
" href=\"ref-to-attachment%40some.domain.org\"/>\r\n" + | ||
" </ns1:Attachment>\r\n" + | ||
" </ns1:Test>\r\n" + | ||
" </soap:Body>\r\n" + | ||
"</soap:Envelope>"; | ||
|
||
final String content = "-----1234\r\n" + | ||
"content-type: application/xop+xml; type=\"application/soap+xml\"\r\n" + | ||
"\r\n" + | ||
soapEnvelope + "\r\n" + | ||
"-----1234\r\n" + | ||
"Content-type: text/plain\r\n" + | ||
"content-id: <[email protected]>\r\n" + | ||
"\r\n" + | ||
"some text/plain content\r\n" + | ||
"-----1234--\r\n"; | ||
|
||
final List<FileItem> fileItems = Util.parseUpload(upload, content.getBytes(StandardCharsets.US_ASCII), | ||
"multipart/related; boundary=---1234;" + | ||
" type=\"application/xop+xml\"; start-info=\"application/soap+xml\""); | ||
assertEquals(2, fileItems.size()); | ||
|
||
final FileItem part1 = fileItems.get(0); | ||
assertNull(part1.getFieldName()); | ||
assertFalse(part1.isFormField()); | ||
assertEquals(soapEnvelope, part1.getString()); | ||
|
||
final FileItem part2 = fileItems.get(1); | ||
assertNull(part2.getFieldName()); | ||
assertFalse(part2.isFormField()); | ||
assertEquals("some text/plain content", part2.getString()); | ||
assertEquals("text/plain", part2.getContentType()); | ||
assertNull(part2.getName()); | ||
} | ||
} |