use of org.apache.cxf.jaxrs.ext.multipart.InputStreamDataSource in project cxf by apache.
the class DataSourceProviderTest method testWriteDataSourceWithDiffCT.
@Test
public void testWriteDataSourceWithDiffCT() throws Exception {
DataSourceProvider<DataSource> p = new DataSourceProvider<DataSource>();
p.setUseDataSourceContentType(true);
DataSource ds = new InputStreamDataSource(new ByteArrayInputStream("image".getBytes()), "image/png");
MultivaluedMap<String, Object> outHeaders = new MetadataMap<String, Object>();
try (ByteArrayOutputStream os = new ByteArrayOutputStream()) {
p.writeTo(ds, DataSource.class, DataSource.class, new Annotation[] {}, MediaType.valueOf("image/jpeg"), outHeaders, os);
assertEquals("image", os.toString());
}
assertEquals("image/png", outHeaders.getFirst("Content-Type"));
}
use of org.apache.cxf.jaxrs.ext.multipart.InputStreamDataSource in project cxf by apache.
the class JAXRSMultipartTest method testLargeHeader.
// The large Content Disposition header will be rejected here
@Test
public void testLargeHeader() throws Exception {
InputStream is1 = getClass().getResourceAsStream("/org/apache/cxf/systest/jaxrs/resources/java.jpg");
String address = "http://localhost:" + PORT + "/bookstore/books/image";
WebClient client = WebClient.create(address);
client.type("multipart/mixed").accept("multipart/mixed");
WebClient.getConfig(client).getRequestContext().put("support.type.as.multipart", "true");
StringBuilder sb = new StringBuilder();
sb.append("form-data;");
for (int i = 0; i < 10000; i++) {
sb.append("aaaaaaaaaa");
}
MultivaluedMap<String, String> headers = new MultivaluedHashMap<>();
headers.putSingle("Content-ID", "root");
headers.putSingle("Content-Type", "application/octet-stream");
headers.putSingle("Content-Disposition", sb.toString());
DataHandler handler = new DataHandler(new InputStreamDataSource(is1, "application/octet-stream"));
Attachment att = new Attachment(headers, handler, null);
Response response = client.post(att);
assertEquals(response.getStatus(), 413);
client.close();
}
use of org.apache.cxf.jaxrs.ext.multipart.InputStreamDataSource in project cxf by apache.
the class DataSourceProviderTest method testWriteDataSource.
@Test
public void testWriteDataSource() throws Exception {
DataSourceProvider<DataSource> p = new DataSourceProvider<DataSource>();
DataSource ds = new InputStreamDataSource(new ByteArrayInputStream("image".getBytes()), "image/png");
MultivaluedMap<String, Object> outHeaders = new MetadataMap<String, Object>();
try (ByteArrayOutputStream os = new ByteArrayOutputStream()) {
p.writeTo(ds, DataSource.class, DataSource.class, new Annotation[] {}, MediaType.valueOf("image/png"), outHeaders, os);
assertEquals("image", os.toString());
}
assertEquals(0, outHeaders.size());
}
use of org.apache.cxf.jaxrs.ext.multipart.InputStreamDataSource in project cxf by apache.
the class DataSourceProviderTest method testWriteDataHandler.
@Test
public void testWriteDataHandler() throws Exception {
DataSourceProvider<DataHandler> p = new DataSourceProvider<DataHandler>();
DataHandler ds = new DataHandler(new InputStreamDataSource(new ByteArrayInputStream("image".getBytes()), "image/png"));
ByteArrayOutputStream os = new ByteArrayOutputStream();
p.writeTo(ds, DataHandler.class, DataHandler.class, new Annotation[] {}, MediaType.valueOf("image/png"), new MetadataMap<String, Object>(), os);
assertEquals("image", os.toString());
}
use of org.apache.cxf.jaxrs.ext.multipart.InputStreamDataSource in project cxf by apache.
the class JAXRSMultipartTest method testLargerThanDefaultHeader.
// The Content Disposition header will be accepted here, even though it is larger than the default,
// as we have configured a larger value on the service side
@Test
public void testLargerThanDefaultHeader() throws Exception {
InputStream is1 = getClass().getResourceAsStream("/org/apache/cxf/systest/jaxrs/resources/java.jpg");
String address = "http://localhost:" + PORT + "/bookstore/books/image";
WebClient client = WebClient.create(address);
client.type("multipart/mixed").accept("multipart/mixed");
WebClient.getConfig(client).getRequestContext().put("support.type.as.multipart", "true");
StringBuilder sb = new StringBuilder();
sb.append("form-data;");
for (int i = 0; i < 35; i++) {
sb.append("aaaaaaaaaa");
}
MultivaluedMap<String, String> headers = new MultivaluedHashMap<>();
headers.putSingle("Content-ID", "root");
headers.putSingle("Content-Type", "application/octet-stream");
headers.putSingle("Content-Disposition", sb.toString());
DataHandler handler = new DataHandler(new InputStreamDataSource(is1, "application/octet-stream"));
Attachment att = new Attachment(headers, handler, null);
Response response = client.post(att);
assertEquals(response.getStatus(), 200);
client.close();
}
Aggregations