use of org.apache.cxf.attachment.AttachmentSerializer in project cxf by apache.
the class AttachmentOutInterceptor method handleMessage.
public void handleMessage(Message message) {
// same message
if (message.get(ATTACHMENT_OUT_CHECKED) != null && (boolean) message.get(ATTACHMENT_OUT_CHECKED)) {
return;
} else {
message.put(ATTACHMENT_OUT_CHECKED, Boolean.TRUE);
}
// Make it possible to step into this process in spite of Eclipse
// by declaring the Object.
boolean mtomEnabled = AttachmentUtil.isMtomEnabled(message);
boolean writeAtts = MessageUtils.getContextualBoolean(message, WRITE_ATTACHMENTS, false) || (message.getAttachments() != null && !message.getAttachments().isEmpty());
writeOptionalTypeParameters = MessageUtils.getContextualBoolean(message, WRITE_OPTIONAL_TYPE_PARAMETERS, true);
if (!mtomEnabled && !writeAtts) {
return;
}
if (message.getContent(OutputStream.class) == null) {
return;
}
AttachmentSerializer serializer = new AttachmentSerializer(message, getMultipartType(), writeOptionalTypeParameters(), getRootHeaders());
serializer.setXop(mtomEnabled);
String contentTransferEncoding = (String) message.getContextualProperty(org.apache.cxf.message.Message.CONTENT_TRANSFER_ENCODING);
if (contentTransferEncoding != null) {
serializer.setContentTransferEncoding(contentTransferEncoding);
}
try {
serializer.writeProlog();
} catch (IOException e) {
throw new Fault(new org.apache.cxf.common.i18n.Message("WRITE_ATTACHMENTS", BUNDLE), e);
}
message.setContent(AttachmentSerializer.class, serializer);
// Add a final interceptor to write attachements
message.getInterceptorChain().add(ending);
}
use of org.apache.cxf.attachment.AttachmentSerializer in project cxf by apache.
the class PersistenceUtils method encodeRMContent.
public static void encodeRMContent(RMMessage rmmsg, Message msg, InputStream msgContent) throws IOException {
CachedOutputStream cos = new CachedOutputStream();
if (msg.getAttachments() == null) {
rmmsg.setContentType((String) msg.get(Message.CONTENT_TYPE));
IOUtils.copyAndCloseInput(msgContent, cos);
cos.flush();
rmmsg.setContent(cos);
} else {
MessageImpl msgImpl1 = new MessageImpl();
msgImpl1.setContent(OutputStream.class, cos);
msgImpl1.setAttachments(msg.getAttachments());
msgImpl1.put(Message.CONTENT_TYPE, msg.get(Message.CONTENT_TYPE));
msgImpl1.setContent(InputStream.class, msgContent);
AttachmentSerializer serializer = new AttachmentSerializer(msgImpl1);
serializer.setXop(false);
serializer.writeProlog();
// write soap root message into cached output stream
IOUtils.copyAndCloseInput(msgContent, cos);
cos.flush();
serializer.writeAttachments();
rmmsg.setContentType((String) msgImpl1.get(Message.CONTENT_TYPE));
rmmsg.setContent(cos);
}
}
Aggregations