简体   繁体   中英

How to use a Proxy for a XmlRpc-Request without settitng Systemproperties

I need to run a XmlRpc-Request and i must use a proxy to connect with the server.

The Connection works with the following code.

try {
    final XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
    config.setServerURL(new URL(url));
    final XmlRpcClient server = new XmlRpcClient();
    server.setConfig(config);
    Object result = null;
    System.setProperty("https.proxyHost", host);
    System.setProperty("https.proxyPort", port);
    result = server.execute("evatrRPC", params);
    return ((String) result);
}catch (final Exception exception) {
    throw new RuntimeException("JavaClient: " + exception);
}

The problem is that I am not allowed to change the system-properties. Therefor I am looking for an other way to just set a proxy for the request.

Thank you for your help

You should try to configure the transport factory of the client:

XmlRpcSun15HttpTransportFactorytransportFactory transportFactory = 
    new XmlRpcSun15HttpTransportFactory(client);

transportFactory.setProxy(proxy); // <= Proxy settings here

client.setTransportFactory(transportFactory);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM