We have a suite of document-literal (aka message) SOAP services exposed via Apache Axis 1.2. We have been experimenting with XFire as an alternative, lighter weight SOAP engine, following a general trend at my current client toward streaming XML using StAX. To this end, we use the org.codehaus.xfire.service.binding.MessageBindingProvider with our ObjectServiceFactory instance and then defined our common endpoint interface as:
public interface XFireMessageEndpoint {
public XMLStreamReader execute(XMLStreamReader xmlReader, MessageContext context) throws XFireFault;
}
However, the MessageBindingProvider.writeParameter() method only recognizes a return type of org.codehaus.yom.Element - many of our response payloads originate from other XML-emitting services in the SOA environment, so we wanted to just pass the stream through to the XFire engine, without converting it to some sort of document object first. This could be achieved by replacing the current MessageBindingProvider.writeParameter() implementation with (for example):
if (value instanceof Element)
{
StaxSerializer serializer = new StaxSerializer();
try
{
serializer.writeElement((Element) value, writer);
}
catch (XMLStreamException e)
{
throw new XFireRuntimeException("Couldn't write to stream.", e);
}
}
// Patch begins!
else if (value instanceof XMLStreamReader)
{
try
{
STAXUtils.copy((XMLStreamReader) value, writer);
}
catch (XMLStreamException e)
{ throw new XFireRuntimeException("Couldn't write to stream.", e); } }
}
// Patch ends!
else
{
logger.warn("Unknown type for serialization: " + p.getTypeClass());
}