use of org.glassfish.jersey.media.multipart.FormDataMultiPart in project jersey by jersey.
the class FormDataMultiPartReaderWriterTest method tempFileDeletedAfterExceptionInMethod.
/**
* JERSEY-2846 reproducer. Make sure that temporary file created by MIMEPull deleted after an unsuccessful request.
*/
@Test
public void tempFileDeletedAfterExceptionInMethod() throws Exception {
final FormDataMultiPart multipart = new FormDataMultiPart();
final FormDataBodyPart bodypart = new FormDataBodyPart(FormDataContentDisposition.name("file").fileName("file").build(), "CONTENT");
multipart.bodyPart(bodypart);
final Response response = target().path("FileResource").path("ExceptionInMethod").request().post(Entity.entity(multipart, MediaType.MULTIPART_FORM_DATA));
// Make sure that the temp file has been removed.
final String pathname = response.readEntity(String.class);
// Wait a second to make sure the file doesn't exist.
Thread.sleep(1000);
assertThat("Temporary file, " + pathname + ", on the server has not been removed", new File(pathname).exists(), is(false));
}
use of org.glassfish.jersey.media.multipart.FormDataMultiPart in project jersey by jersey.
the class FormDataMultiPartReaderWriterTest method tempFileDeletedAfterSuccessfulProcessing.
/**
* JERSEY-2846 reproducer. Make sure that temporary file created by MIMEPull deleted after a successful request.
*/
@Test
public void tempFileDeletedAfterSuccessfulProcessing() throws Exception {
final FormDataMultiPart multipart = new FormDataMultiPart();
final FormDataBodyPart bodypart = new FormDataBodyPart(FormDataContentDisposition.name("file").fileName("file").build(), "CONTENT");
multipart.bodyPart(bodypart);
final Response response = target().path("FileResource").path("SuccessfulMethod").request().post(Entity.entity(multipart, MediaType.MULTIPART_FORM_DATA));
// Make sure that the temp file has been removed.
final String pathname = response.readEntity(String.class);
// Wait a second to make sure the file doesn't exist.
Thread.sleep(1000);
assertThat("Temporary file, " + pathname + ", on the server has not been removed", new File(pathname).exists(), is(false));
}
use of org.glassfish.jersey.media.multipart.FormDataMultiPart in project jersey by jersey.
the class MultipartTest method testSpecificListAsParameter.
/**
* Test that injection of a list (specific type) works.
*/
@Test
public void testSpecificListAsParameter() throws Exception {
final MyObject object = new MyObject("object");
final List<MyObject> list = Arrays.asList(new MyObject("list1"), new MyObject("list2"));
final FormDataMultiPart mp = new FormDataMultiPart();
mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("object").fileName("object").build(), object, MediaType.APPLICATION_JSON_TYPE));
mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("list").fileName("list").build(), list, MediaType.APPLICATION_JSON_TYPE));
final Response response = target("listAsParameter").request().post(Entity.entity(mp, MediaType.MULTIPART_FORM_DATA_TYPE));
assertThat(response.readEntity(String.class), is("object_list1_list2"));
}
use of org.glassfish.jersey.media.multipart.FormDataMultiPart in project ice by JBEI.
the class IceRestClient method postSequenceFile.
public Response postSequenceFile(String url, String recordId, EntryType entryType, String sequence) {
try {
WebTarget target = client.target("https://" + url).path("/rest/file/sequence");
Invocation.Builder invocationBuilder = target.request(MediaType.APPLICATION_JSON_TYPE);
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());
return invocationBuilder.post(Entity.entity(multiPart, MediaType.MULTIPART_FORM_DATA_TYPE));
} catch (Exception e) {
Logger.error(e);
return null;
}
}
Aggregations