use of org.apache.cxf.io.CachedOutputStream in project cxf by apache.
the class FormUtils method restoreForm.
public static void restoreForm(FormEncodingProvider<Form> provider, Form form, Message message) throws Exception {
CachedOutputStream os = new CachedOutputStream();
writeForm(provider, form, os);
message.setContent(InputStream.class, os.getInputStream());
}
use of org.apache.cxf.io.CachedOutputStream in project cxf by apache.
the class MessageModeOutInterceptor method handleMessage.
public void handleMessage(Message message) throws Fault {
BindingOperationInfo bop = message.getExchange().getBindingOperationInfo();
if (bop != null && !bindingName.equals(bop.getBinding().getName())) {
return;
}
if (saajOut != null) {
doSoap(message);
} else if (DataSource.class.isAssignableFrom(type)) {
// datasource stuff, must check if multi-source
MessageContentsList list = (MessageContentsList) message.getContent(List.class);
DataSource ds = (DataSource) list.get(0);
String ct = ds.getContentType();
if (ct.toLowerCase().contains("multipart/related")) {
Message msg = new MessageImpl();
msg.setExchange(message.getExchange());
msg.put(Message.CONTENT_TYPE, ct);
try {
msg.setContent(InputStream.class, ds.getInputStream());
AttachmentDeserializer deser = new AttachmentDeserializer(msg);
deser.initializeAttachments();
} catch (IOException ex) {
throw new Fault(ex);
}
message.setAttachments(msg.getAttachments());
final InputStream in = msg.getContent(InputStream.class);
final String ct2 = (String) msg.get(Message.CONTENT_TYPE);
list.set(0, new DataSource() {
public String getContentType() {
return ct2;
}
public InputStream getInputStream() throws IOException {
return in;
}
public String getName() {
return ct2;
}
public OutputStream getOutputStream() throws IOException {
return null;
}
});
} else if (!ct.toLowerCase().contains("xml")) {
// not XML based, need to stream out directly. This is a bit tricky as
// we don't want the stax stuff triggering and such
OutputStream out = message.getContent(OutputStream.class);
message.put(Message.CONTENT_TYPE, ct);
try {
InputStream in = ds.getInputStream();
IOUtils.copy(in, out);
in.close();
out.flush();
out.close();
} catch (IOException e) {
throw new Fault(e);
}
list.remove(0);
out = new CachedOutputStream();
message.setContent(OutputStream.class, out);
XMLStreamWriter writer = StaxUtils.createXMLStreamWriter(out);
message.setContent(XMLStreamWriter.class, writer);
}
} else if (ServiceUtils.isSchemaValidationEnabled(SchemaValidationType.OUT, message) && Source.class.isAssignableFrom(type)) {
// if schema validation is on, we'll end up converting to a DOMSource anyway,
// let's convert and check for a fault
MessageContentsList list = (MessageContentsList) message.getContent(List.class);
Source ds = (Source) list.get(0);
if (!(ds instanceof DOMSource)) {
try {
ds = new DOMSource(StaxUtils.read(ds));
} catch (XMLStreamException e) {
throw new Fault(e);
}
list.set(0, ds);
validatePossibleFault(message, bop, ((DOMSource) ds).getNode());
}
}
}
use of org.apache.cxf.io.CachedOutputStream in project cxf by apache.
the class AttachmentDeserializer method cache.
private void cache(DelegatingInputStream input) throws IOException {
if (loaded.contains(input)) {
return;
}
loaded.add(input);
InputStream origIn = input.getInputStream();
try (CachedOutputStream out = new CachedOutputStream()) {
AttachmentUtil.setStreamedAttachmentProperties(message, out);
IOUtils.copy(input, out);
input.setInputStream(out.getInputStream());
origIn.close();
}
}
use of org.apache.cxf.io.CachedOutputStream in project cxf by apache.
the class AttachmentDataSource method cache.
public void cache(Message message) throws IOException {
if (cache == null) {
cache = new CachedOutputStream();
AttachmentUtil.setStreamedAttachmentProperties(message, cache);
try {
IOUtils.copyAndCloseInput(ins, cache);
cache.lockOutputStream();
if (delegate != null) {
delegate.setInputStream(cache.getInputStream());
}
} catch (CacheSizeExceededException | IOException cee) {
cache.close();
cache = null;
throw cee;
} finally {
ins = null;
}
}
}
use of org.apache.cxf.io.CachedOutputStream in project cxf by apache.
the class XSLTOutInterceptor method transformOS.
protected void transformOS(Message message, OutputStream out) {
CachedOutputStream wrapper = new CachedOutputStream();
CachedOutputStreamCallback callback = new XSLTCachedOutputStreamCallback(getXSLTTemplate(), out);
wrapper.registerCallback(callback);
message.setContent(OutputStream.class, wrapper);
}
Aggregations