I'm using jersey-client to send post requests with multipart/form-data. Third-party server uses very old version of com.oreilly.servlet.multipart (COS) to parse it, and the problem here is how COS extracts information about content-disposition. In a nutshell: it can't parse filename field if it goes before name field.
So, it leads to inability to send file parts with jersey-client, because it places name field at the end of content-disposition (and I really believe it's ok, because according to RFC order of fields in content-disposition shouldn't matter), filename isn't parsed and without filename this third-party server doesn't recognize this part as file.
And the question is: how to set content-disposition for FileDataBodyPart preserving order of fields?
I checked source code of FormDataContentDisposition class and found that it constructs content-disposition in certain order
StringBuilder sb = new StringBuilder();
sb.append(type);
addStringParameter(sb, "filename", fileName);
addDateParameter(sb, "creation-date", creationDate);
addDateParameter(sb, "modification-date", modificationDate);
addDateParameter(sb, "read-date", readDate);
addLongParameter(sb, "size", size);
return sb;
So, workaround for this problem is to extend from this class and override this method.