Search in sources :

Example 1 with XmlRpcClient

use of org.apache.xmlrpc.client.XmlRpcClient in project camel by apache.

the class XmlRpcEndpoint method createClient.

public XmlRpcClient createClient() throws MalformedURLException {
    XmlRpcClient client = new XmlRpcClient();
    // setup the client with the configuration from the XmlRpcEndpoint
    XmlRpcClientConfigImpl config = clientConfig.cloneMe();
    // setup the server url
    config.setServerURL(new URL(getAddress()));
    client.setConfig(config);
    if (clientConfigurer != null) {
        clientConfigurer.configureXmlRpcClient(client);
    }
    return client;
}
Also used : XmlRpcClient(org.apache.xmlrpc.client.XmlRpcClient) XmlRpcClientConfigImpl(org.apache.xmlrpc.client.XmlRpcClientConfigImpl) URL(java.net.URL)

Example 2 with XmlRpcClient

use of org.apache.xmlrpc.client.XmlRpcClient in project processdash by dtuma.

the class CCDefectTypeLookup method main.

/**
     * Run a simple, standalone test to see if our known strategies work against
     * a particular server.
     */
public static void main(String[] args) {
    URL baseUrl, url;
    try {
        baseUrl = new URL(args[0]);
        url = new URL(baseUrl, "/xmlrpc/secure");
    } catch (IOException ioe) {
        throw new RuntimeException("Malformed URL " + args[0]);
    }
    XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
    config.setServerURL(url);
    config.setBasicUserName(args[1]);
    config.setBasicPassword(args[2]);
    XmlRpcClient client = new XmlRpcClient();
    client.setConfig(config);
    try {
        execute(client, "getServerVersion");
    } catch (Exception e) {
        throw new RuntimeException("Unable to contact server " + baseUrl + " - cannot validate defect lookup strategy");
    }
    CCDefectTypeLookup lookup = getTypeLookup(client);
    String oneType = lookup.getType(1);
    if (oneType != null) {
        System.out.println("Code Collaborator defect type lookup " + "strategy succeeded against URL " + baseUrl);
        return;
    } else {
        throw new RuntimeException("Code Collaborator defect type lookup " + "strategy failed against URL " + baseUrl);
    }
}
Also used : XmlRpcClient(org.apache.xmlrpc.client.XmlRpcClient) IOException(java.io.IOException) XmlRpcClientConfigImpl(org.apache.xmlrpc.client.XmlRpcClientConfigImpl) URL(java.net.URL) IOException(java.io.IOException)

Example 3 with XmlRpcClient

use of org.apache.xmlrpc.client.XmlRpcClient in project processdash by dtuma.

the class BoundXmlRpcConnection method openConnectionImpl.

protected XmlRpcClient openConnectionImpl(boolean printException) throws ErrorDataValueException {
    String username = null;
    String password = null;
    try {
        // look up the information needed to make the connection
        String baseUrl = this.baseUrl.getValue();
        String urlSuffix = this.urlSuffix.getValue();
        username = getUsername(this.username.getValue());
        password = getPassword(this.password.getValue());
        URL url = new URL(baseUrl.trim());
        if (StringUtils.hasValue(urlSuffix))
            url = new URL(url, urlSuffix);
        XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
        config.setServerURL(url);
        config.setEnabledForExtensions(true);
        if (username != null && password != null) {
            config.setBasicUserName(username);
            config.setBasicPassword(password);
        }
        XmlRpcClient connection = new XmlRpcClient();
        connection.setConfig(config);
        if (StringUtils.hasValue(testMethodName))
            connection.execute(testMethodName, Collections.EMPTY_LIST);
        if (!validateCredentials(connection, username, password))
            throw new ErrorDataValueException(BAD_USERNAME_PASS, ErrorData.SEVERE);
        setError(null, ErrorData.NO_ERROR);
        return connection;
    } catch (MalformedURLException mue) {
        throw new ErrorDataValueException(INVALID_URL, ErrorData.SEVERE);
    } catch (XmlRpcNotAuthorizedException nae) {
        throw getBadCredentialsException(username, password);
    } catch (ErrorDataValueException edve) {
        throw edve;
    } catch (Exception e) {
        // we were unable to open a connection; return null.
        if (printException)
            e.printStackTrace();
        return null;
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) XmlRpcNotAuthorizedException(org.apache.xmlrpc.common.XmlRpcNotAuthorizedException) XmlRpcClient(org.apache.xmlrpc.client.XmlRpcClient) XmlRpcClientConfigImpl(org.apache.xmlrpc.client.XmlRpcClientConfigImpl) URL(java.net.URL) XmlRpcException(org.apache.xmlrpc.XmlRpcException) MalformedURLException(java.net.MalformedURLException) XmlRpcNotAuthorizedException(org.apache.xmlrpc.common.XmlRpcNotAuthorizedException)

Example 4 with XmlRpcClient

use of org.apache.xmlrpc.client.XmlRpcClient in project ofbiz-framework by apache.

the class XmlRpcTests method testXmlRpcRequest.

/**
 * Test Xml Rpc by java class call with a Object List
 * @throws Exception
 */
public void testXmlRpcRequest() throws Exception {
    XmlRpcClient client = this.getRpcClient(url, "admin", "ofbiz");
    Object[] params = new Object[] { 55.00, "message from xml-rpc client" };
    Map<String, Object> result = UtilGenerics.cast(client.execute("testScv", params));
    assertEquals("XML-RPC Service result success", "service done", result.get("resp"));
}
Also used : XmlRpcClient(org.apache.xmlrpc.client.XmlRpcClient)

Example 5 with XmlRpcClient

use of org.apache.xmlrpc.client.XmlRpcClient in project ovirt-engine by oVirt.

the class ExternalSchedulerBrokerImpl method runBalance.

@Override
public Optional<BalanceResult> runBalance(String balanceName, List<Guid> hostIDs, Map<String, String> propertiesMap) {
    try {
        XmlRpcClient client = new XmlRpcClient();
        client.setConfig(config);
        Object result = client.execute(BALANCE, createBalanceArgs(balanceName, hostIDs, propertiesMap));
        return Optional.of(ExternalSchedulerBrokerObjectBuilder.getBalanceResult(result));
    } catch (XmlRpcException e) {
        log.error("Error communicating with the external scheduler while balancing: {}", e.getMessage());
        log.debug("Exception", e);
        auditLogFailedToConnect();
        return Optional.empty();
    }
}
Also used : XmlRpcClient(org.apache.xmlrpc.client.XmlRpcClient) XmlRpcException(org.apache.xmlrpc.XmlRpcException)

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