Search in sources :

Example 16 with XmlRpcClient

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

the class MosesTranslate method translate.

@Override
protected String translate(Language sLang, Language tLang, String text) throws Exception {
    String server = getServerUrl();
    if (server == null) {
        return OStrings.getString("MT_ENGINE_MOSES_URL_NOTFOUND");
    }
    XmlRpcClient client = getClient(new URL(server));
    Map<String, String> mosesParams = new HashMap<>();
    mosesParams.put("text", mosesPreprocess(text, sLang.getLocale()));
    Object[] xmlRpcParams = { mosesParams };
    try {
        HashMap<?, ?> response = (HashMap<?, ?>) client.execute("translate", xmlRpcParams);
        return mosesPostprocess((String) response.get("text"), tLang);
    } catch (XmlRpcException e) {
        return e.getLocalizedMessage();
    }
}
Also used : XmlRpcClient(org.apache.xmlrpc.client.XmlRpcClient) HashMap(java.util.HashMap) URL(java.net.URL) XmlRpcException(org.apache.xmlrpc.XmlRpcException)

Example 17 with XmlRpcClient

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

the class MosesTranslate method getClient.

private XmlRpcClient getClient(URL url) {
    XmlRpcClient client = new XmlRpcClient();
    XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
    config.setServerURL(url);
    client.setConfig(config);
    return client;
}
Also used : XmlRpcClient(org.apache.xmlrpc.client.XmlRpcClient) XmlRpcClientConfigImpl(org.apache.xmlrpc.client.XmlRpcClientConfigImpl)

Example 18 with XmlRpcClient

use of org.apache.xmlrpc.client.XmlRpcClient in project openems by OpenEMS.

the class OdooUtils method executeKw.

private static Object executeKw(String url, Object[] params) throws XmlRpcException, MalformedURLException {
    final XmlRpcClient client = new XmlRpcClient();
    XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
    config.setEnabledForExtensions(true);
    config.setServerURL(new URL(String.format("%s/xmlrpc/2/object", url)));
    config.setReplyTimeout(5000);
    client.setConfig(config);
    return client.execute("execute_kw", params);
}
Also used : XmlRpcClient(org.apache.xmlrpc.client.XmlRpcClient) XmlRpcClientConfigImpl(org.apache.xmlrpc.client.XmlRpcClientConfigImpl) URL(java.net.URL)

Example 19 with XmlRpcClient

use of org.apache.xmlrpc.client.XmlRpcClient in project cosmic by MissionCriticalCloud.

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<>();
    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) Answer(com.cloud.agent.api.Answer) AttachAnswer(com.cloud.storage.command.AttachAnswer) 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 20 with XmlRpcClient

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

the class Connection method setupXmlClient.

private XmlRpcClient setupXmlClient() {
    final XmlRpcClient client = new XmlRpcClient();
    URL url;
    try {
        /* TODO: should add SSL checking here! */
        String prot = "http";
        if (hostUseSsl) {
            prot = "https";
        }
        url = new URL(prot + "://" + hostIp + ":" + hostPort.toString());
        xmlClientConfig.setTimeZone(TimeZone.getTimeZone("UTC"));
        xmlClientConfig.setServerURL(url);
        /* disable, we use asyncexecute to control timeout */
        xmlClientConfig.setReplyTimeout(0);
        /* default to 60 secs */
        xmlClientConfig.setConnectionTimeout(60000);
        /* reply time is 5 mins */
        xmlClientConfig.setReplyTimeout(60 * 15000);
        if (hostUser != null && hostPass != null) {
            LOGGER.debug("Setting username " + hostUser);
            xmlClientConfig.setBasicUserName(hostUser);
            xmlClientConfig.setBasicPassword(hostPass);
        }
        xmlClientConfig.setXmlRpcServer(null);
        client.setConfig(xmlClientConfig);
        client.setTypeFactory(new RpcTypeFactory(client));
    } catch (MalformedURLException e) {
        LOGGER.info("Incorrect URL: ", e);
    }
    return client;
}
Also used : MalformedURLException(java.net.MalformedURLException) XmlRpcClient(org.apache.xmlrpc.client.XmlRpcClient) URL(java.net.URL)

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