Search in sources :

Example 1 with XmlRpcStreamConfig

use of org.apache.xmlrpc.common.XmlRpcStreamConfig 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

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