Search in sources :

Example 1 with XMLWriter

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;
}
Also used : UnsupportedEncodingException(java.io.UnsupportedEncodingException) CharSetXMLWriter(org.apache.ws.commons.serialize.CharSetXMLWriter) OutputStreamWriter(java.io.OutputStreamWriter) CharSetXMLWriter(org.apache.ws.commons.serialize.CharSetXMLWriter) XMLWriter(org.apache.ws.commons.serialize.XMLWriter) XmlRpcException(org.apache.xmlrpc.XmlRpcException) BufferedWriter(java.io.BufferedWriter)

Example 2 with XMLWriter

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);
    }
}
Also used : XmlRpcRequest(org.apache.xmlrpc.XmlRpcRequest) CharSetXMLWriter(org.apache.ws.commons.serialize.CharSetXMLWriter) XMLWriter(org.apache.ws.commons.serialize.XMLWriter)

Aggregations

CharSetXMLWriter (org.apache.ws.commons.serialize.CharSetXMLWriter)2 XMLWriter (org.apache.ws.commons.serialize.XMLWriter)2 BufferedWriter (java.io.BufferedWriter)1 OutputStreamWriter (java.io.OutputStreamWriter)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 XmlRpcException (org.apache.xmlrpc.XmlRpcException)1 XmlRpcRequest (org.apache.xmlrpc.XmlRpcRequest)1