@SuppressWarnings("unchecked")
private void prepareMultipartUpload(Object[] formParms, Object[] fileParms,
String eventName) throws Exception {
NVPair[] hdrs = new NVPair[1];
Frame2HttpServletRequestSimulator request = (Frame2HttpServletRequestSimulator) getRequest();
NVPair[] opts;
opts = new NVPair[formParms.length];
for (int i = 0; i < formParms.length; i++) {
Map<String, String> parm = (HashMap<String, String>) formParms[i];
for (Entry<String, String> entry : parm.entrySet()) {
String key = entry.getKey();
String value = entry.getValue();
opts[i] = new NVPair(key, value);
}
}
NVPair[] file;
file = new NVPair[fileParms.length];
for (int i = 0; i < fileParms.length; i++) {
Map<String, String> parm = (HashMap<String, String>) fileParms[i];
for (Entry<String, String> entry : parm.entrySet()) {
String key = entry.getKey();
String value = entry.getValue();
URL configFile = getContext().getResource(value);
file[i] = new NVPair(key, configFile.getFile());
}
}
try {
byte[] data = Codecs.mpFormDataEncode(opts, file, hdrs);
String rawData = new String(data);
System.out.println(rawData);
InputStream is = new ByteArrayInputStream(data);
request.setDataInputStream(data.length, is);
request.setContentType(hdrs[0].getValue());
request.setHeader(HttpRequestProcessor.CONTENT_TYPE, hdrs[0]
.getValue());
is.close();
} catch (IOException e) {
fail();
}