Код: Выделить всё
Unexpected error: Connection refused to host: 10.101.37.128; nested exception is:
java.net.ConnectException: Connection refused
< /code>
Я создал магазин ключей и Truststore из руководства и этого от Oracle. Я скопировал код и внес изменения на основе моих потребностей. Что привело к приведенной выше ошибке. Код на этом этапе выглядит следующим образом:
[b] register.java[/b]
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import javax.rmi.ssl.SslRMIClientSocketFactory;
import javax.rmi.ssl.SslRMIServerSocketFactory;
public class Register {
public static void main(String[] args) throws Exception {
int port = 1040;
System.setProperty("javax.net.ssl.trustStore", "client.truststore");
System.setProperty("javax.net.ssl.trustStorePassword", "123123");
System.setProperty("javax.net.ssl.keyStore", "server.keystore");
System.setProperty("javax.net.ssl.keyStorePassword", "123123");
Registry reg = LocateRegistry.createRegistry(port, new SslRMIClientSocketFactory(),
new SslRMIServerSocketFactory());
Server server = new Server();
reg.rebind("orderingsystem", server);
System.out.println("Server running");
}
}
Код: Выделить всё
import java.rmi.*;
import java.sql.SQLException;
public interface RemoteInterface extends Remote {
public boolean loginUser() throws RemoteException, SQLException;
}
Код: Выделить всё
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.sql.SQLException;
import javax.rmi.ssl.SslRMIClientSocketFactory;
import javax.rmi.ssl.SslRMIServerSocketFactory;
public class Server extends UnicastRemoteObject implements RemoteInterface {
public Server() throws RemoteException {
super(0, new SslRMIClientSocketFactory(), new SslRMIServerSocketFactory());
}
@Override
public boolean loginUser() throws RemoteException, SQLException {
return true;
}
}
Код: Выделить всё
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
public class App {
public static void main(String[] args) {
try {
Registry registry = LocateRegistry.getRegistry("orderingsystem", 1040);
RemoteInterface obj = (RemoteInterface) registry.lookup("orderingsystem");
obj.loginUser();
} catch (Exception e) {
e.printStackTrace();
}
}
}
< /code>
Я сделал еще несколько поиска, и я нашел этот вопрос, и я соответственно обновил свой код. Тем не менее, я получаю одинаковую ошибку, только имя хоста отличается. < /P>
Unexpected error: Unknown host: orderingsystem; nested exception is:
java.net.UnknownHostException: orderingsystem
< /code>
Тогда я подумал, что это может быть: < /p>
super(0, new SslRMIClientSocketFactory(), new SslRMIServerSocketFactory(null, null, true));
< /code>
Поэтому я обновил его до < /p>
super(0, new SslRMIClientSocketFactory(), new SslRMIServerSocketFactory());
< /code>
Но это не имело значения. Другие ресурсы, которые я нашел: < /p>
Этот документ Oracle. В частности, я следовал файлам hello.java, helloclient.java и helloimpl.java. Что приведет меня к другой ошибке. < /P>
java.rmi.ConnectIOException: non-JRMP server at remote endpoint
at java.rmi/sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:252)
at java.rmi/sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:204)
at java.rmi/sun.rmi.server.UnicastRef.newCall(UnicastRef.java:344)
at java.rmi/sun.rmi.registry.RegistryImpl_Stub.lookup(RegistryImpl_Stub.java:116)
at dcoms.App.main(App.java:13)
App.javaобразно
Код: Выделить всё
import java.net.InetAddress;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
public class App {
public static void main(String[] args) {
try {
Registry registry = LocateRegistry.getRegistry(InetAddress.getLocalHost().getHostName(), 9999);
RemoteInterface obj = (RemoteInterface) registry.lookup("OrderSystem");
obj.loginUser();
} catch (Exception e) {
e.printStackTrace();
}
}
}
Код: Выделить всё
package dcoms.remote;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import javax.rmi.ssl.SslRMIClientSocketFactory;
import javax.rmi.ssl.SslRMIServerSocketFactory;
public class Register {
public static void main(String[] args) throws Exception {
int port = 9999;
System.setProperty("javax.net.ssl.keyStore", "keystore");
System.setProperty("javax.net.ssl.keyStorePassword", "123123");
System.setProperty("javax.net.ssl.trustStore", "truststore");
System.setProperty("javax.net.ssl.trustStorePassword", "123123");
Registry reg = LocateRegistry.createRegistry(port, new SslRMIClientSocketFactory(),
new SslRMIServerSocketFactory());
Server server = new Server();
reg.rebind("OrderSystem", server);
System.out.println("Server running");
}
}
Код: Выделить всё
keytool -genkeypair \
-alias server \
-keyalg RSA \
-keysize 2048 \
-keystore server.keystore \
-validity 365
keytool -exportcert \
-alias server \
-keystore server.keystore \
-file server.crt
keytool -importcert \
-alias server \
-file server.crt \
-keystore client.truststore
Код: Выделить всё
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import javax.rmi.ssl.SslRMIClientSocketFactory;
import javax.rmi.ssl.SslRMIServerSocketFactory;
public class Register {
public static void main(String[] args) throws Exception {
int port = 9999;
System.setProperty("javax.net.ssl.keyStore", "server.keystore");
System.setProperty("javax.net.ssl.keyStorePassword", "123123");
System.setProperty("javax.net.ssl.trustStore", "client.truststore");
System.setProperty("javax.net.ssl.trustStorePassword", "123123");
Registry reg = LocateRegistry.createRegistry(port, new SslRMIClientSocketFactory(),
new SslRMIServerSocketFactory());
Server server = new Server();
reg.rebind("OrderSystem", server);
System.out.println("Server running");
}
}
Код: Выделить всё
import java.rmi.*;
import java.sql.SQLException;
public interface RemoteInterface extends Remote {
public boolean loginUser() throws RemoteException, SQLException;
}
Код: Выделить всё
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.sql.SQLException;
import javax.rmi.ssl.SslRMIClientSocketFactory;
import javax.rmi.ssl.SslRMIServerSocketFactory;
public class Server extends UnicastRemoteObject implements RemoteInterface {
public Server() throws RemoteException {
super(0, new SslRMIClientSocketFactory(), new SslRMIServerSocketFactory());
}
@Override
public boolean loginUser() throws RemoteException, SQLException {
return true;
}
}
Код: Выделить всё
package dcoms;
import java.net.InetAddress;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import dcoms.remote.RemoteInterface;
public class App {
public static void main(String[] args) {
System.out.println("Starting");
try {
Registry registry = LocateRegistry.getRegistry(InetAddress.getLocalHost().getHostName(), 9999);
RemoteInterface obj = (RemoteInterface) registry.lookup("OrderSystem");
System.out.println(obj.loginUser());
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("Ended");
}
}
Подробнее здесь: https://stackoverflow.com/questions/795 ... nexception