Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Endpoint can't parse multipart requests with Content-Disposition: attachment #11

Open
dmolesUC opened this issue Jun 27, 2016 · 0 comments

Comments

@dmolesUC
Copy link

Posting a multipart request with Content-Disposition: attachment, as specified by e.g. Section 6.5.3 of the SWORD 2.0 Profile:

  • The client MUST supply a Content-Disposition header of type attachment on the Entry Part with a name parameter set to atom [SWORD004]
  • The client MUST supply a Content-Disposition header of type attachment on the Media Part with a name parameter set to payload and a filename parameter [SWORD004]

results in an exception with the message Attempting to store and check deposit which has no input stream.

The underlying cause appears to be Commons-Fileupload bug FILEUPLOAD-239, closed as invalid based on (IMO) a misreading of RFC 1867, which accepts only Content-Disposition: form-data. I was able to work around this by patching SwordAPIEndpoint.getPartsFromRequest() with a more liberal getFieldName() implementation.

// Create a new file upload handler
ServletFileUpload upload = new ServletFileUpload(factory) {
    // Work around WONTFIX https://issues.apache.org/jira/browse/FILEUPLOAD-239
    @Override
    protected String getFieldName(FileItemHeaders headers) {
        String contentDisposition = headers.getHeader(CONTENT_DISPOSITION);
        if (contentDisposition != null) {
            ParameterParser parser = new ParameterParser();
            parser.setLowerCaseNames(true);
            Map params = parser.parse(contentDisposition, ';');
            String fieldName = (String) params.get("name");
            if (fieldName != null) {
                return fieldName.trim();
            }
        }
        return null;
    }
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant