use of org.glassfish.jersey.media.multipart.FormDataMultiPart in project ice by JBEI.
the class IceRestClient method postSequenceFile.
public void postSequenceFile(String recordId, EntryType entryType, String sequence, String path) {
try {
final FormDataMultiPart multiPart = new FormDataMultiPart();
multiPart.field("file", IOUtils.toInputStream(sequence, "UTF-8"), MediaType.TEXT_PLAIN_TYPE);
multiPart.field("entryRecordId", recordId);
multiPart.field("entryType", entryType.name());
Invocation.Builder invocationBuilder = target.path(path).request(MediaType.APPLICATION_JSON_TYPE);
invocationBuilder.post(Entity.entity(multiPart, MediaType.MULTIPART_FORM_DATA_TYPE));
} catch (Exception e) {
Logger.error(e);
}
}
use of org.glassfish.jersey.media.multipart.FormDataMultiPart in project heron by twitter.
the class TopologyResourceTests method testSubmitMissingParams.
@Test
public void testSubmitMissingParams() throws IOException {
FormDataMultiPart form = mock(FormDataMultiPart.class);
for (final String paramKey : requiredSubmitParamKeys) {
Set<String> keySet = requiredSubmitParamKeys.stream().filter(s -> s.equals(paramKey)).collect(Collectors.toSet());
Map<String, List<FormDataBodyPart>> map = new HashMap<>();
keySet.forEach(t -> map.put(t, Collections.emptyList()));
when(form.getFields()).thenReturn(map);
Response response = resource.submit(form);
assertEquals(HTTP_422, response.getStatus());
}
}
use of org.glassfish.jersey.media.multipart.FormDataMultiPart in project Payara by payara.
the class TemplateCommandPostResource method createDataBasedOnForm.
private static ParameterMap createDataBasedOnForm(FormDataMultiPart paramForm) {
ParameterMap data = new ParameterMap();
try (FormDataMultiPart formData = assureExistence(paramForm)) {
/* data passed to the generic command running
*
* */
Map<String, List<FormDataBodyPart>> m1 = formData.getFields();
Set<String> ss = m1.keySet();
for (String fieldName : ss) {
for (FormDataBodyPart bodyPart : formData.getFields(fieldName)) {
if (bodyPart.getContentDisposition().getFileName() != null) {
// we have a file
// save it and mark it as delete on exit.
InputStream fileStream = bodyPart.getValueAs(InputStream.class);
String mimeType = bodyPart.getMediaType().toString();
// Use just the filename without complete path. File creation
// in case of remote deployment failing because fo this.
String fileName = bodyPart.getContentDisposition().getFileName();
if (fileName.contains("/")) {
fileName = Util.getName(fileName, '/');
} else {
if (fileName.contains("\\")) {
fileName = Util.getName(fileName, '\\');
}
}
File f = Util.saveFile(fileName, mimeType, fileStream);
FileUtils.deleteOnExit(f);
// put only the local path of the file in the same field.
data.add(fieldName, f.getAbsolutePath());
} else {
data.add(fieldName, bodyPart.getValue());
}
}
}
} catch (Exception ex) {
RestLogging.restLogger.log(Level.SEVERE, null, ex);
}
return data;
}
Aggregations