use of org.apache.cxf.jaxrs.interceptor.AttachmentOutputInterceptor in project cxf by apache.
the class MessageContextImpl method convertToAttachments.
private void convertToAttachments(Object value) {
List<?> handlers = (List<?>) value;
List<org.apache.cxf.message.Attachment> atts = new ArrayList<org.apache.cxf.message.Attachment>();
for (int i = 1; i < handlers.size(); i++) {
Attachment handler = (Attachment) handlers.get(i);
AttachmentImpl att = new AttachmentImpl(handler.getContentId(), handler.getDataHandler());
for (String key : handler.getHeaders().keySet()) {
att.setHeader(key, handler.getHeader(key));
}
att.setXOP(false);
atts.add(att);
}
Message outMessage = getOutMessage();
outMessage.setAttachments(atts);
outMessage.put(AttachmentOutInterceptor.WRITE_ATTACHMENTS, "true");
Attachment root = (Attachment) handlers.get(0);
String rootContentType = root.getContentType().toString();
MultivaluedMap<String, String> rootHeaders = new MetadataMap<String, String>(root.getHeaders());
if (!AttachmentUtil.isMtomEnabled(outMessage)) {
rootHeaders.putSingle(Message.CONTENT_TYPE, rootContentType);
}
String messageContentType = outMessage.get(Message.CONTENT_TYPE).toString();
int index = messageContentType.indexOf(";type");
if (index > 0) {
messageContentType = messageContentType.substring(0, index).trim();
}
AttachmentOutputInterceptor attInterceptor = new AttachmentOutputInterceptor(messageContentType, rootHeaders);
outMessage.put(Message.CONTENT_TYPE, rootContentType);
Map<String, List<String>> allHeaders = CastUtils.cast((Map<?, ?>) outMessage.get(Message.PROTOCOL_HEADERS));
if (allHeaders != null) {
allHeaders.remove(Message.CONTENT_TYPE);
}
attInterceptor.handleMessage(outMessage);
}
Aggregations