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();
}
}
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;
}
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);
}
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());
}
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;
}
Aggregations