use of org.apache.cxf.jaxrs.ext.multipart.Attachment in project tomee by apache.
the class MultipartProvider method getAttachmentCollection.
private Object getAttachmentCollection(Type t, List<Attachment> infos, Annotation[] anns) throws IOException {
Class<?> actual = getActualType(t, 0);
if (Attachment.class.isAssignableFrom(actual)) {
return infos;
}
Collection<Object> objects = new ArrayList<>();
for (Attachment a : infos) {
objects.add(fromAttachment(a, actual, actual, anns));
}
return objects;
}
use of org.apache.cxf.jaxrs.ext.multipart.Attachment in project tomee by apache.
the class MultipartProvider method getAttachments.
private List<Attachment> getAttachments(List<?> objects, String rootMediaType) throws IOException {
List<Attachment> handlers = new ArrayList<>(objects.size());
for (int i = 0; i < objects.size(); i++) {
Object value = objects.get(i);
Attachment handler = createDataHandler(value, value.getClass(), new Annotation[] {}, rootMediaType, rootMediaType, i);
handlers.add(handler);
}
return handlers;
}
use of org.apache.cxf.jaxrs.ext.multipart.Attachment in project tomee by apache.
the class MultipartProvider method createDataHandler.
private <T> Attachment createDataHandler(T obj, Class<T> cls, Type genericType, Annotation[] anns, String mimeType, String mainMediaType, int id) throws IOException {
final DataHandler dh;
if (InputStream.class.isAssignableFrom(obj.getClass())) {
dh = createInputStreamDH((InputStream) obj, mimeType);
} else if (DataHandler.class.isAssignableFrom(obj.getClass())) {
dh = (DataHandler) obj;
} else if (DataSource.class.isAssignableFrom(obj.getClass())) {
dh = new DataHandler((DataSource) obj);
} else if (File.class.isAssignableFrom(obj.getClass())) {
File f = (File) obj;
ContentDisposition cd = mainMediaType.startsWith(MediaType.MULTIPART_FORM_DATA) ? new ContentDisposition("form-data;name=file;filename=" + f.getName()) : null;
return new Attachment(AttachmentUtil.BODY_ATTACHMENT_ID, Files.newInputStream(f.toPath()), cd);
} else if (Attachment.class.isAssignableFrom(obj.getClass())) {
Attachment att = (Attachment) obj;
if (att.getObject() == null) {
return att;
}
dh = getHandlerForObject(att.getObject(), att.getObject().getClass(), new Annotation[] {}, att.getContentType().toString(), id);
return new Attachment(att.getContentId(), dh, att.getHeaders());
} else if (byte[].class.isAssignableFrom(obj.getClass())) {
ByteDataSource source = new ByteDataSource((byte[]) obj);
source.setContentType(mimeType);
dh = new DataHandler(source);
} else {
dh = getHandlerForObject(obj, cls, genericType, anns, mimeType);
}
String contentId = getContentId(anns, id);
MultivaluedMap<String, String> headers = new MetadataMap<>();
headers.putSingle("Content-Type", mimeType);
return new Attachment(contentId, dh, headers);
}
use of org.apache.cxf.jaxrs.ext.multipart.Attachment in project tomee by apache.
the class ClientProxyImpl method handleMultipart.
protected List<Attachment> handleMultipart(MultivaluedMap<ParameterType, Parameter> map, OperationResourceInfo ori, Object[] params) {
List<Parameter> fm = getParameters(map, ParameterType.REQUEST_BODY);
List<Attachment> atts = new ArrayList<>(fm.size());
fm.forEach(p -> {
Multipart part = getMultipart(ori, p.getIndex());
if (part != null) {
Object partObject = params[p.getIndex()];
if (partObject != null) {
atts.add(new Attachment(part.value(), part.type(), partObject));
}
}
});
return atts;
}
use of org.apache.cxf.jaxrs.ext.multipart.Attachment in project ddf by codice.
the class AbstractCatalogService method createMetacard.
@Override
public BinaryContent createMetacard(MultipartBody multipartBody, String transformerParam) throws CatalogServiceException {
LOGGER.trace("ENTERING: createMetacard");
String contentUri = multipartBody.getAttachmentObject("contentUri", String.class);
LOGGER.debug("contentUri = {}", contentUri);
InputStream stream = null;
String contentType = null;
Attachment contentPart = multipartBody.getAttachment(FILE_ATTACHMENT_CONTENT_ID);
if (contentPart != null) {
// Content-Type: application/json;id=geojson
if (contentPart.getContentType() != null) {
contentType = contentPart.getContentType().toString();
}
// at the beginning
try {
stream = contentPart.getDataHandler().getInputStream();
if (stream != null && stream.available() == 0) {
stream.reset();
}
} catch (IOException e) {
LOGGER.info("IOException reading stream from file attachment in multipart body", e);
}
} else {
LOGGER.debug(NO_FILE_CONTENTS_ATT_FOUND);
}
return createMetacard(stream, contentType, transformerParam);
}
Aggregations