use of org.apache.ws.commons.serialize.XMLWriter in project camel by apache.
the class XmlRpcDataFormat method getXMLWriter.
protected XMLWriter getXMLWriter(Exchange exchange, OutputStream outputStream) throws XmlRpcException {
XMLWriter writer = new CharSetXMLWriter();
String encoding = IOHelper.getCharsetName(exchange);
writer.setEncoding(encoding);
writer.setIndenting(false);
writer.setFlushing(true);
try {
writer.setWriter(new BufferedWriter(new OutputStreamWriter(outputStream, encoding)));
} catch (UnsupportedEncodingException e) {
throw new XmlRpcException("Unsupported encoding: " + encoding, e);
}
return writer;
}
use of org.apache.ws.commons.serialize.XMLWriter in project camel by apache.
the class XmlRpcDataFormat method marshal.
@Override
public void marshal(Exchange exchange, Object graph, OutputStream stream) throws Exception {
// need to check the object type
XMLWriter control = getXMLWriter(exchange, stream);
XmlRpcWriter writer = new XmlRpcWriter(xmlRpcStreamRequestConfig, control, typeFactory);
XmlRpcRequest request = null;
if (isRequest || graph instanceof XmlRpcRequest) {
request = exchange.getContext().getTypeConverter().mandatoryConvertTo(XmlRpcRequest.class, exchange, graph);
}
if (request != null) {
writer.writeRequest(xmlRpcStreamRequestConfig, request);
} else {
// write the result here directly
// TODO write the fault message here
writer.write(xmlRpcStreamRequestConfig, graph);
}
}
Aggregations