use of org.glassfish.jersey.media.multipart.MultiPart in project jersey by jersey.
the class MultiPartReaderWriterTest method checkEleven.
private void checkEleven(final String seed, final int multiplier) throws Exception {
final StringBuilder sb = new StringBuilder(seed.length() * multiplier);
for (int i = 0; i < multiplier; i++) {
sb.append(seed);
}
final String expected = sb.toString();
final WebTarget target = target().path("multipart/eleven");
final MultiPart entity = new MultiPart().bodyPart(expected, MediaType.TEXT_PLAIN_TYPE);
final MultiPart response = target.request("multipart/mixed").put(Entity.entity(entity, "multipart/mixed"), MultiPart.class);
final String actual = response.getBodyParts().get(0).getEntityAs(String.class);
assertEquals("Length for multiplier " + multiplier, expected.length(), actual.length());
assertEquals("Content for multiplier " + multiplier, expected, actual);
response.cleanup();
}
use of org.glassfish.jersey.media.multipart.MultiPart in project jersey by jersey.
the class MultiPartResource method one.
@Path("one")
@GET
@Produces("multipart/mixed")
public Response one() {
MultiPart entity = new MultiPart();
// Exercise manually adding part(s) to the bodyParts property
BodyPart part = new BodyPart("This is the only segment", new MediaType("text", "plain"));
entity.getBodyParts().add(part);
return Response.ok(entity).type("multipart/mixed").build();
}
use of org.glassfish.jersey.media.multipart.MultiPart in project jersey by jersey.
the class MultiPartResource method eleven.
// Echo back a body part whose content may or may not exceed the size
// of the buffer threshold
@Path("eleven")
@PUT
@Consumes("multipart/mixed")
@Produces("multipart/mixed")
public Response eleven(MultiPart multiPart) throws IOException {
BodyPartEntity bpe = (BodyPartEntity) multiPart.getBodyParts().get(0).getEntity();
StringBuilder sb = new StringBuilder();
InputStream stream = bpe.getInputStream();
InputStreamReader reader = new InputStreamReader(stream);
char[] buffer = new char[2048];
while (true) {
int n = reader.read(buffer);
if (n < 0) {
break;
}
sb.append(buffer, 0, n);
}
return Response.ok(new MultiPart().bodyPart(sb.toString(), MediaType.TEXT_PLAIN_TYPE)).type(new MediaType("multipart", "mixed")).build();
}
use of org.glassfish.jersey.media.multipart.MultiPart in project kylo by Teradata.
the class AbstractNiFiTemplatesRestClient method create.
@Nonnull
@Override
public TemplateDTO create(@Nullable final String name, @Nonnull final String xml) {
// Build template body part
final FormDataBodyPart templatePart = new FormDataBodyPart("template", xml, MediaType.APPLICATION_OCTET_STREAM_TYPE);
FormDataContentDisposition.FormDataContentDispositionBuilder disposition = FormDataContentDisposition.name(templatePart.getName());
disposition.fileName((name == null) ? "import_template_" + System.currentTimeMillis() : name);
templatePart.setFormDataContentDisposition(disposition.build());
// Combine parts
MultiPart multiPart = new MultiPart();
multiPart.bodyPart(templatePart);
multiPart.setMediaType(MediaType.MULTIPART_FORM_DATA_TYPE);
// Upload template
return upload(multiPart);
}
use of org.glassfish.jersey.media.multipart.MultiPart in project streamline by hortonworks.
the class RestIntegrationTest method getMultiPart.
private MultiPart getMultiPart(ResourceTestElement resourceToTest, Object entity) {
MultiPart multiPart = new MultiPart();
BodyPart filePart = new FileDataBodyPart(resourceToTest.fileNameHeader, resourceToTest.fileToUpload);
BodyPart entityPart = new FormDataBodyPart(resourceToTest.entityNameHeader, entity, MediaType.APPLICATION_JSON_TYPE);
multiPart.bodyPart(filePart).bodyPart(entityPart);
return multiPart;
}
Aggregations