}
@Override
public Object doMarshal(Exchange exchange, Object inputObject, OutputStream stream, String soapAction) throws IOException {
Body body = new Body();
Header header = new Header();
Throwable exception = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, Throwable.class);
if (exception == null) {
exception = exchange.getIn().getHeader(Exchange.EXCEPTION_CAUGHT, Throwable.class);
}
final List<JAXBElement<?>> bodyContent;
List<JAXBElement<?>> headerContent = new ArrayList<JAXBElement<?>>();
if (exception != null) {
bodyContent = new ArrayList<JAXBElement<?>>();
bodyContent.add(createFaultFromException(exception));
} else {
bodyContent = getDataFormat().createContentFromObject(inputObject, soapAction, headerContent);
}
for (JAXBElement<?> elem : bodyContent) {
body.getAny().add(elem);
}
for (JAXBElement<?> elem : headerContent) {
header.getAny().add(elem);
}
Envelope envelope = new Envelope();
if (headerContent.size() > 0) {
envelope.setHeader(header);
}