Search in sources :

Example 21 with XmlRpcClient

use of org.apache.xmlrpc.client.XmlRpcClient 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

XmlRpcClient (org.apache.xmlrpc.client.XmlRpcClient)21 XmlRpcException (org.apache.xmlrpc.XmlRpcException)11 URL (java.net.URL)10 XmlRpcClientConfigImpl (org.apache.xmlrpc.client.XmlRpcClientConfigImpl)7 MalformedURLException (java.net.MalformedURLException)5 Test (org.junit.Test)3 Answer (com.cloud.agent.api.Answer)2 MaintainCommand (com.cloud.agent.api.MaintainCommand)2 RebootAnswer (com.cloud.agent.api.RebootAnswer)2 CreateAnswer (com.cloud.agent.api.storage.CreateAnswer)2 XsHost (com.cloud.hypervisor.xenserver.resource.XsHost)2 Connection (com.xensource.xenapi.Connection)2 XenAPIException (com.xensource.xenapi.Types.XenAPIException)2 Hashtable (java.util.Hashtable)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 AttachAnswer (com.cloud.storage.command.AttachAnswer)1 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1 IOException (java.io.IOException)1 StringReader (java.io.StringReader)1 ArrayList (java.util.ArrayList)1