Search in sources :

Example 1 with XmlRpcResponseParser

use of org.apache.xmlrpc.parser.XmlRpcResponseParser in project camel by apache.

the class XmlRpcDataFormat method unmarshalResponse.

protected Object unmarshalResponse(Exchange exchange, InputStream stream) throws Exception {
    InputSource isource = new InputSource(stream);
    XMLReader xr = newXMLReader();
    XmlRpcResponseParser xp;
    try {
        xp = new XmlRpcResponseParser(xmlRpcStreamRequestConfig, typeFactory);
        xr.setContentHandler(xp);
        xr.parse(isource);
    } catch (SAXException e) {
        throw new XmlRpcClientException("Failed to parse server's response: " + e.getMessage(), e);
    } catch (IOException e) {
        throw new XmlRpcClientException("Failed to read server's response: " + e.getMessage(), e);
    }
    if (xp.isSuccess()) {
        return xp.getResult();
    }
    Throwable t = xp.getErrorCause();
    if (t == null) {
        throw new XmlRpcException(xp.getErrorCode(), xp.getErrorMessage());
    }
    if (t instanceof XmlRpcException) {
        throw (XmlRpcException) t;
    }
    if (t instanceof RuntimeException) {
        throw (RuntimeException) t;
    }
    throw new XmlRpcException(xp.getErrorCode(), xp.getErrorMessage(), t);
}
Also used : InputSource(org.xml.sax.InputSource) XmlRpcClientException(org.apache.xmlrpc.client.XmlRpcClientException) IOException(java.io.IOException) XMLReader(org.xml.sax.XMLReader) XmlRpcException(org.apache.xmlrpc.XmlRpcException) XmlRpcResponseParser(org.apache.xmlrpc.parser.XmlRpcResponseParser) SAXException(org.xml.sax.SAXException)

Example 2 with XmlRpcResponseParser

use of org.apache.xmlrpc.parser.XmlRpcResponseParser in project cloudstack by apache.

the class ConnectionTest method callTimeoutInSec.

@Override
public Object callTimeoutInSec(String method, List<?> params, int timeout, boolean debug) throws XmlRpcException {
    XmlRpcStreamConfig config = new XmlRpcHttpRequestConfigImpl();
    XmlRpcClient client = new XmlRpcClient();
    client.setTypeFactory(new RpcTypeFactory(client));
    XmlRpcResponseParser parser = new XmlRpcResponseParser((XmlRpcStreamRequestConfig) config, client.getTypeFactory());
    XMLReader xr = SAXParsers.newXMLReader();
    xr.setContentHandler(parser);
    try {
        String result = null;
        if (getMethodResponse(method) != null) {
            result = getMethodResponse(method);
            LOGGER.debug("methodresponse call: " + method + " - " + params);
            LOGGER.trace("methodresponse reply: " + result);
        }
        if (result == null && multiRes.size() >= 0) {
            result = getResult();
            LOGGER.debug("getresult call: " + method + " - " + params);
            LOGGER.trace("getresult reply: " + result);
        }
        xr.parse(new InputSource(new StringReader(result)));
    } catch (Exception e) {
        throw new XmlRpcException("Exception: " + e.getMessage(), e);
    }
    if (parser.getErrorCode() != 0) {
        throw new XmlRpcException("Fault received[" + parser.getErrorCode() + "]: " + parser.getErrorMessage());
    }
    return parser.getResult();
}
Also used : XmlRpcHttpRequestConfigImpl(org.apache.xmlrpc.common.XmlRpcHttpRequestConfigImpl) InputSource(org.xml.sax.InputSource) XmlRpcClient(org.apache.xmlrpc.client.XmlRpcClient) StringReader(java.io.StringReader) XmlRpcStreamConfig(org.apache.xmlrpc.common.XmlRpcStreamConfig) XMLReader(org.xml.sax.XMLReader) XmlRpcException(org.apache.xmlrpc.XmlRpcException) XmlRpcException(org.apache.xmlrpc.XmlRpcException) XmlRpcResponseParser(org.apache.xmlrpc.parser.XmlRpcResponseParser)

Aggregations

XmlRpcException (org.apache.xmlrpc.XmlRpcException)2 XmlRpcResponseParser (org.apache.xmlrpc.parser.XmlRpcResponseParser)2 InputSource (org.xml.sax.InputSource)2 XMLReader (org.xml.sax.XMLReader)2 IOException (java.io.IOException)1 StringReader (java.io.StringReader)1 XmlRpcClient (org.apache.xmlrpc.client.XmlRpcClient)1 XmlRpcClientException (org.apache.xmlrpc.client.XmlRpcClientException)1 XmlRpcHttpRequestConfigImpl (org.apache.xmlrpc.common.XmlRpcHttpRequestConfigImpl)1 XmlRpcStreamConfig (org.apache.xmlrpc.common.XmlRpcStreamConfig)1 SAXException (org.xml.sax.SAXException)1