private DataHandler createInputStreamDH(InputStream is, String mimeType) { return new DataHandler(new InputStreamDataSource(is, mimeType)); }
public Attachment(InputStream is, MultivaluedMap<String, String> headers) { this(headers.getFirst("Content-ID"), new DataHandler(new InputStreamDataSource(is, headers.getFirst("Content-Type"))), headers); }
private DataHandler createInputStreamDH(InputStream is, String mimeType) { return new DataHandler(new InputStreamDataSource(is, mimeType)); }
public Attachment(InputStream is, MultivaluedMap<String, String> headers) { this(headers.getFirst("Content-ID"), new DataHandler(new InputStreamDataSource(is, headers.getFirst("Content-Type"))), headers); }
public Attachment(String id, InputStream is, ContentDisposition cd) { handler = new DataHandler(new InputStreamDataSource(is, "application/octet-stream")); if (cd != null) { headers.putSingle("Content-Disposition", cd.toString()); } headers.putSingle("Content-ID", id); headers.putSingle("Content-Type", "application/octet-stream"); }
public Attachment(String id, InputStream is, ContentDisposition cd) { handler = new DataHandler(new InputStreamDataSource(is, "application/octet-stream")); if (cd != null) { headers.putSingle("Content-Disposition", cd.toString()); } headers.putSingle("Content-ID", id); headers.putSingle("Content-Type", "application/octet-stream"); }
public T readFrom(Class<T> cls, Type genericType, Annotation[] annotations, MediaType type, MultivaluedMap<String, String> headers, InputStream is) throws IOException { DataSource ds = null; if (cls == FileDataSource.class) { File file = new BinaryDataProvider<File>().readFrom(File.class, File.class, annotations, type, headers, is); ds = new FileDataSource(file); } else if (cls == DataSource.class || cls == DataHandler.class) { ds = new InputStreamDataSource(is, type.toString()); } else { LOG.warning("Unsupported DataSource class: " + cls.getName()); throw ExceptionUtils.toWebApplicationException(null, null); } return cls.cast(DataSource.class.isAssignableFrom(cls) ? ds : new DataHandler(ds)); }
public T readFrom(Class<T> cls, Type genericType, Annotation[] annotations, MediaType type, MultivaluedMap<String, String> headers, InputStream is) throws IOException { DataSource ds = null; if (cls == FileDataSource.class) { File file = new BinaryDataProvider<File>().readFrom(File.class, File.class, annotations, type, headers, is); ds = new FileDataSource(file); } else if (cls == DataSource.class || cls == DataHandler.class) { ds = new InputStreamDataSource(is, type.toString()); } else { LOG.warning("Unsupported DataSource class: " + cls.getName()); throw ExceptionUtils.toWebApplicationException(null, null); } return cls.cast(DataSource.class.isAssignableFrom(cls) ? ds : new DataHandler(ds)); }
private void transferBinaryMultipartParameter(Object toMap, String parameterName, String multipartType, Message in) { org.apache.camel.Attachment dh = null; if (toMap instanceof Attachment) { dh = createCamelAttachment((Attachment) toMap); } else if (toMap instanceof DataSource) { dh = new DefaultAttachment((DataSource) toMap); } else if (toMap instanceof DataHandler) { dh = new DefaultAttachment((DataHandler) toMap); } else if (toMap instanceof InputStream) { dh = new DefaultAttachment(new InputStreamDataSource((InputStream) toMap, multipartType == null ? "application/octet-stream" : multipartType)); } if (dh != null) { in.addAttachmentObject(parameterName, dh); } }
public static org.fcrepo.server.types.mtom.gen.MIMETypedStream convertMIMETypedStreamToGenMIMETypedStreamMTOM(org.fcrepo.server.storage.types.MIMETypedStream mimeTypedStream) { if (mimeTypedStream != null) { org.fcrepo.server.types.mtom.gen.MIMETypedStream genMIMETypedStream = new org.fcrepo.server.types.mtom.gen.MIMETypedStream(); genMIMETypedStream.setMIMEType(mimeTypedStream.getMIMEType()); org.fcrepo.server.storage.types.Property[] header = mimeTypedStream.header; org.fcrepo.server.types.mtom.gen.MIMETypedStream.Header head = new org.fcrepo.server.types.mtom.gen.MIMETypedStream.Header(); if (header != null) { for (org.fcrepo.server.storage.types.Property property : header) { head.getProperty() .add(convertPropertyToGenProperty(property)); } } genMIMETypedStream.setHeader(head); InputStreamDataSource ds = new InputStreamDataSource(mimeTypedStream.getStream(), mimeTypedStream.getMIMEType()); genMIMETypedStream .setStream(new DataHandler(ds)); return genMIMETypedStream; } else { return null; } }
@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(); }
@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(); }
public static org.fcrepo.server.types.mtom.gen.MIMETypedStream convertMIMETypedStreamToGenMIMETypedStreamMTOM(org.fcrepo.server.storage.types.MIMETypedStream mimeTypedStream) { if (mimeTypedStream != null) { org.fcrepo.server.types.mtom.gen.MIMETypedStream genMIMETypedStream = new org.fcrepo.server.types.mtom.gen.MIMETypedStream(); genMIMETypedStream.setMIMEType(mimeTypedStream.getMIMEType()); org.fcrepo.server.storage.types.Property[] header = mimeTypedStream.header; org.fcrepo.server.types.mtom.gen.MIMETypedStream.Header head = new org.fcrepo.server.types.mtom.gen.MIMETypedStream.Header(); if (header != null) { for (org.fcrepo.server.storage.types.Property property : header) { head.getProperty() .add(convertPropertyToGenProperty(property)); } } genMIMETypedStream.setHeader(head); InputStreamDataSource ds = new InputStreamDataSource(mimeTypedStream.getStream(), mimeTypedStream.getMIMEType()); genMIMETypedStream .setStream(new DataHandler(ds)); return genMIMETypedStream; } else { return null; } }