Search in sources :

Example 6 with XmlRpcClient

use of org.apache.xmlrpc.client.XmlRpcClient in project maven-plugins by apache.

the class TracDownloader method getIssueList.

public List<Issue> getIssueList() throws MalformedURLException, XmlRpcException {
    // Create and configure an XML-RPC client
    XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
    try {
        config.setServerURL(new URL(getUrl() + "/login/xmlrpc"));
    } catch (MalformedURLException e) {
        throw new MalformedURLException("The Trac URL is incorrect.");
    }
    config.setBasicUserName(tracUser);
    config.setBasicPassword(tracPassword);
    XmlRpcClient client = new XmlRpcClient();
    client.setConfig(config);
    client.setTransportFactory(new XmlRpcCommonsTransportFactory(client));
    // Fetch issues
    String qstr = "";
    if (!StringUtils.isEmpty(query)) {
        qstr = query;
    }
    Object[] params = new Object[] { qstr };
    Object[] queryResult;
    ArrayList<Issue> issueList = new ArrayList<Issue>();
    try {
        queryResult = (Object[]) client.execute("ticket.query", params);
        for (Object aQueryResult : queryResult) {
            params = new Object[] { aQueryResult };
            Object[] ticketGetResult;
            ticketGetResult = (Object[]) client.execute("ticket.get", params);
            issueList.add(createIssue(ticketGetResult));
        }
    } catch (XmlRpcException e) {
        throw new XmlRpcException("XmlRpc Error.", e);
    }
    return issueList;
}
Also used : MalformedURLException(java.net.MalformedURLException) Issue(org.apache.maven.plugins.issues.Issue) XmlRpcClient(org.apache.xmlrpc.client.XmlRpcClient) ArrayList(java.util.ArrayList) XmlRpcCommonsTransportFactory(org.apache.xmlrpc.client.XmlRpcCommonsTransportFactory) XmlRpcClientConfigImpl(org.apache.xmlrpc.client.XmlRpcClientConfigImpl) URL(java.net.URL) XmlRpcException(org.apache.xmlrpc.XmlRpcException)

Example 7 with XmlRpcClient

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

the class Connection method getXmlClient.

private XmlRpcClient getXmlClient() {
    XmlRpcClient client = new XmlRpcClient();
    URL url;
    try {
        url = new URL("http://" + _ip + ":" + _port.toString());
        _config.setTimeZone(TimeZone.getTimeZone("UTC"));
        _config.setServerURL(url);
        // disable, we use asyncexecute to control timeout
        _config.setReplyTimeout(0);
        _config.setConnectionTimeout(6000);
        _config.setBasicUserName(_username);
        _config.setBasicPassword(_password);
        client.setConfig(_config);
    } catch (MalformedURLException e) {
        throw new CloudRuntimeException(e.getMessage());
    }
    return client;
}
Also used : MalformedURLException(java.net.MalformedURLException) XmlRpcClient(org.apache.xmlrpc.client.XmlRpcClient) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) URL(java.net.URL)

Example 8 with XmlRpcClient

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

the class NotAValidCommand method testMaintainCommand.

@Test
public void testMaintainCommand() {
    // This test needs further work.
    final String uuid = "befc4dcd-f5c6-4015-8791-3c18622b7c7f";
    final Connection conn = Mockito.mock(Connection.class);
    final XsHost xsHost = Mockito.mock(XsHost.class);
    final XmlRpcClient client = Mockito.mock(XmlRpcClient.class);
    // final Host.Record hr = PowerMockito.mock(Host.Record.class);
    // final Host host = PowerMockito.mock(Host.class);
    final MaintainCommand maintainCommand = new MaintainCommand();
    final Map<String, Object> map = new Hashtable<String, Object>();
    map.put("Value", "Xen");
    final Map<String, Object> spiedMap = spy(map);
    final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
    assertNotNull(wrapper);
    when(citrixResourceBase.getConnection()).thenReturn(conn);
    when(citrixResourceBase.getHost()).thenReturn(xsHost);
    when(xsHost.getUuid()).thenReturn(uuid);
    when(conn.getSessionReference()).thenReturn("befc4dcd");
    try {
        final Object[] params = { Marshalling.toXMLRPC("befc4dcd"), Marshalling.toXMLRPC(uuid) };
        when(client.execute("host.get_by_uuid", new Object[] { "befc4dcd", uuid })).thenReturn(spiedMap);
        PowerMockito.when(conn, "dispatch", "host.get_by_uuid", params).thenReturn(spiedMap);
    } catch (final Exception e) {
        fail(e.getMessage());
    }
    // try {
    // PowerMockito.mockStatic(Host.class);
    // //BDDMockito.given(Host.getByUuid(conn,
    // xsHost.getUuid())).willReturn(host);
    // PowerMockito.when(Host.getByUuid(conn,
    // xsHost.getUuid())).thenReturn(host);
    // PowerMockito.verifyStatic(times(1));
    // } catch (final BadServerResponse e) {
    // fail(e.getMessage());
    // } catch (final XenAPIException e) {
    // fail(e.getMessage());
    // } catch (final XmlRpcException e) {
    // fail(e.getMessage());
    // }
    // 
    // PowerMockito.mockStatic(Types.class);
    // PowerMockito.when(Types.toHostRecord(spiedMap)).thenReturn(hr);
    // PowerMockito.verifyStatic(times(1));
    // 
    // try {
    // PowerMockito.mockStatic(Host.Record.class);
    // when(host.getRecord(conn)).thenReturn(hr);
    // verify(host, times(1)).getRecord(conn);
    // } catch (final BadServerResponse e) {
    // fail(e.getMessage());
    // } catch (final XenAPIException e) {
    // fail(e.getMessage());
    // } catch (final XmlRpcException e) {
    // fail(e.getMessage());
    // }
    final Answer answer = wrapper.execute(maintainCommand, citrixResourceBase);
    assertFalse(answer.getResult());
}
Also used : MaintainCommand(com.cloud.agent.api.MaintainCommand) RebootAnswer(com.cloud.agent.api.RebootAnswer) CreateAnswer(com.cloud.agent.api.storage.CreateAnswer) AttachAnswer(org.apache.cloudstack.storage.command.AttachAnswer) Answer(com.cloud.agent.api.Answer) XsHost(com.cloud.hypervisor.xenserver.resource.XsHost) XmlRpcClient(org.apache.xmlrpc.client.XmlRpcClient) Hashtable(java.util.Hashtable) Connection(com.xensource.xenapi.Connection) XenAPIException(com.xensource.xenapi.Types.XenAPIException) XmlRpcException(org.apache.xmlrpc.XmlRpcException) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 9 with XmlRpcClient

use of org.apache.xmlrpc.client.XmlRpcClient in project dubbo by alibaba.

the class XmlRpcProxyFactoryBean method afterPropertiesSet.

/**
 * {@inheritDoc}
 */
@Override
@SuppressWarnings("unchecked")
public void afterPropertiesSet() {
    super.afterPropertiesSet();
    // create proxy
    proxyObject = ProxyFactory.getProxy(getServiceInterface(), this);
    // create XmlRpcHttpClient
    try {
        xmlRpcClient = new XmlRpcClient();
        XmlRpcClientConfigImpl xmlRpcClientConfig = new XmlRpcClientConfigImpl();
        xmlRpcClientConfig.setServerURL(new URL(getServiceUrl()));
        xmlRpcClient.setConfig(xmlRpcClientConfig);
    } catch (MalformedURLException mue) {
        throw new RpcException(mue);
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) XmlRpcClient(org.apache.xmlrpc.client.XmlRpcClient) RpcException(org.apache.dubbo.rpc.RpcException) XmlRpcClientConfigImpl(org.apache.xmlrpc.client.XmlRpcClientConfigImpl) URL(java.net.URL)

Example 10 with XmlRpcClient

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

the class XmlRpcEndpointTest method testClientConfigurer.

@Test
public void testClientConfigurer() throws Exception {
    camelContext.start();
    XmlRpcEndpoint endpoint = (XmlRpcEndpoint) camelContext.getEndpoint("xmlrpc:http://www.example.com?clientConfigurer=#myClientConfigurer");
    XmlRpcClient client = endpoint.createClient();
    assertEquals("Get a worng maxThreads", 10, client.getMaxThreads());
    assertEquals("Get a wrong value of enabledForExtensions", true, ((XmlRpcClientConfigImpl) client.getClientConfig()).isEnabledForExtensions());
}
Also used : XmlRpcClient(org.apache.xmlrpc.client.XmlRpcClient) Test(org.junit.Test)

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