use of org.glassfish.jersey.media.multipart.MultiPart in project jersey by jersey.
the class MultiPartTest method testMultiPartResource.
@Test
public void testMultiPartResource() throws Exception {
final ResourceConfig resourceConfig = new ResourceConfig(MultiPartResource.class).register(new MultiPartFeature());
final HttpServer server = GrizzlyHttpServerFactory.createHttpServer(baseUri, resourceConfig);
Client c = ClientBuilder.newClient(new ClientConfig().register(MultiPartFeature.class));
final Response response = c.target(baseUri).path("/multipart-simple").request().buildGet().invoke();
MultiPart result = response.readEntity(MultiPart.class);
System.out.println("RESULT = " + result);
checkEntity("This is the only segment", (BodyPartEntity) result.getBodyParts().get(0).getEntity());
server.shutdownNow();
}
use of org.glassfish.jersey.media.multipart.MultiPart in project jersey by jersey.
the class MultiPartReaderServerSide method readMultiPart.
protected MultiPart readMultiPart(final Class<MultiPart> type, final Type genericType, final Annotation[] annotations, final MediaType mediaType, final MultivaluedMap<String, String> headers, final InputStream stream) throws IOException, MIMEParsingException {
final MultiPart multiPart = super.readMultiPart(type, genericType, annotations, mediaType, headers, stream);
closeableServiceProvider.get().add(multiPart);
return multiPart;
}
use of org.glassfish.jersey.media.multipart.MultiPart in project jersey by jersey.
the class MultiPartHeaderModificationTest method testLogMessage.
@Test
public void testLogMessage() {
final WebTarget target = target().path("multipart/ten");
MultiPartBean bean = new MultiPartBean("myname", "myvalue");
MultiPart entity = new MultiPart().bodyPart(bean, new MediaType("x-application", "x-format")).bodyPart("", MediaType.APPLICATION_OCTET_STREAM_TYPE);
final String UNSENT_HEADER_CHANGES = "Unsent header changes";
try {
target.request("text/plain").put(Entity.entity(entity, "multipart/mixed"), String.class);
assertFalse("BadRequestException can not be thrown just in case JERSEY-2341 is not fixed.", messageLogged);
LogRecord logRecord = findLogRecord(UNSENT_HEADER_CHANGES);
assertNull(logRecord);
} catch (BadRequestException brex) {
assertTrue("BadRequestException can be thrown just in case JERSEY-2341 is not fixed.", messageLogged);
LogRecord logRecord = findLogRecord(UNSENT_HEADER_CHANGES);
assertNotNull("Missing LogRecord for message '" + UNSENT_HEADER_CHANGES + "'.", logRecord);
assertThat(logRecord.getMessage(), containsString("MIME-Version"));
assertThat(logRecord.getMessage(), containsString("Content-Type"));
}
}
use of org.glassfish.jersey.media.multipart.MultiPart in project jersey by jersey.
the class MultiPartReaderWriterTest method testFour.
@Test
public void testFour() {
final WebTarget target = target().path("multipart/four");
final MultiPartBean bean = new MultiPartBean("myname", "myvalue");
final MultiPart entity = new MultiPart().bodyPart("This is the first segment", new MediaType("text", "plain")).bodyPart(bean, new MediaType("x-application", "x-format"));
final String response = target.request("text/plain").put(Entity.entity(entity, "multipart/mixed"), String.class);
if (!response.startsWith("SUCCESS:")) {
fail("Response is '" + response + "'");
}
}
use of org.glassfish.jersey.media.multipart.MultiPart in project jersey by jersey.
the class MultiPartReaderWriterTest method testOne.
@Test
public void testOne() {
final WebTarget target = target().path("multipart/one");
try {
final MultiPart result = target.request("multipart/mixed").get(MultiPart.class);
checkMediaType(new MediaType("multipart", "mixed"), result.getMediaType());
assertEquals(1, result.getBodyParts().size());
final BodyPart part = result.getBodyParts().get(0);
checkMediaType(new MediaType("text", "plain"), part.getMediaType());
checkEntity("This is the only segment", (BodyPartEntity) part.getEntity());
result.getParameterizedHeaders();
result.cleanup();
} catch (final IOException | ParseException e) {
e.printStackTrace(System.out);
fail("Caught exception: " + e);
}
}
Aggregations