The response to one kind of HTTP request I send is a multipart/form-data looks something like:
--------boundary123
Content-Disposition: form-data; name=\"jso
Example code without using deprecated methods.
import com.google.common.net.MediaType;
import org.apache.commons.fileupload.RequestContext;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;
public class SimpleRequestContext implements RequestContext {
private final Charset charset;
private final MediaType contentType;
private final byte[] content;
public SimpleRequestContext(Charset charset, MediaType contentType, byte[] content) {
this.charset = charset;
this.contentType = contentType;
this.content = content;
}
public String getCharacterEncoding() {
return charset.displayName();
}
public String getContentType() {
return contentType.toString();
}
@Deprecated
public int getContentLength() {
return content.length;
}
public InputStream getInputStream() throws IOException {
return new ByteArrayInputStream(content);
}
}
{
...
Charset encoding = UTF_8;
RequestContext requestContext = new SimpleRequestContext(encoding, contentType, body.getBytes());
FileUploadBase fileUploadBase = new PortletFileUpload();
FileItemFactory fileItemFactory = new DiskFileItemFactory();
fileUploadBase.setFileItemFactory(fileItemFactory);
fileUploadBase.setHeaderEncoding(encoding.displayName());
List fileItems = fileUploadBase.parseRequest(requestContext);
...
}