@Override public void writeTo(OutputStream os) throws IOException { // no body no write if (getBodySources().size() == 0) { return; } Source body = getBodySources().get(0); if (body instanceof StreamCache) { ((StreamCache) body).writeTo(os); } else { StreamResult sr = new StreamResult(os); try { xml.toResult(body, sr); } catch (TransformerException e) { throw new IOException("Transformation failed", e); } } }