Facing issue with RMI Registry.
Inititally my code was developed using java 6 or lower version but recently we have upgrade our java to java 8 and came to understand that it has some tighter Security policies.
Due to this my code is throwing a permission errors while establishing the RMI registry connection
I tried giving grant permission to port in java.policy file. Port used 1099 which default RMI Registry port.
Please find below code
package com.aurionpro.reuters;
import com.aurionpro.reuters.service.UpdateCurrencyRates;
import java.io.IOException;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.util.Properties;
public final class RMIServiceClient {
private final String hostname;
private final int port;
private final String serviceName;
private UpdateCurrencyRates currencyRates;
private Registry registry = null;
public RMIServiceClient(String appPropFileName, String productName) {
Properties properties = new Properties();
ClassLoader loader = Thread.currentThread().getContextClassLoader();
try {
properties.load(loader.getResourceAsStream(appPropFileName));
} catch (IOException var6) {
var6.printStackTrace();
}
this.hostname = properties.getProperty("rmiclient." + productName + ".registry.host");
this.port = Integer.parseInt(properties.getProperty("rmiclient." + productName + ".registry.port"));
this.serviceName = properties.getProperty("rmiclient." + productName + ".registry.serviceName");
}
public UpdateCurrencyRates getCurrencyRatesService() throws RemoteException, NotBoundException {
SecurityManager securityManager = new SecurityManager();
System.setSecurityManager(securityManager);
this.registry = LocateRegistry.getRegistry(this.hostname, this.port);
this.currencyRates = (UpdateCurrencyRates)this.registry.lookup(this.serviceName);
return this.currencyRates;
}
}
SecurityManager
? It has been marked, “deprecated, for removal” and the most recent Java version already removed the support;System.setSecurityManager(…)
will throw anUnsupportedOperationException
in Java 24. Even if it’s not deprecated in Java 8, the reasons for its deprecation apply to this version as well.