devxlogo

Create an RMI-JRMP-SSL Server Using the New JDK1.5.0 Classes

Create an RMI-JRMP-SSL Server Using the New JDK1.5.0 Classes

Usually, the RMI client is an RMI client only in that it specifies the true store zone for certificates. For example, you can use any certificate available to System.setProperty:

("javax.net.ssl.trustStore","SSLcert"); System.setProperty("javax.net.ssl.trustStorePassword","e1002qa2"); 

In this example, the remote interface is SumaInterface and there’s only one remote method called Suma:

import java.rmi.*;import java.rmi.server.*;import javax.rmi.ssl.SslRMIServerSocketFactory;import javax.rmi.ssl.SslRMIClientSocketFactory;public class SumaImpl extends UnicastRemoteObject implements SumaInterface{//constructorpublic SumaImpl(int port,RMIClientSocketFactory rmiC, RMIServerSocketFactory rmiS)throws RemoteException       {       //optional       super(port,rmiC,rmiS);       }         //implementing the Suma methodpublic int Suma(int a,int b)throws RemoteException{  return (a+b);    }    public static void main(String[] args)      {            SumaImpl SI=null;            System.setProperty("javax.net.ssl.keyStore","SSLcert");      System.setProperty("javax.net.ssl.keyStorePassword","e1002qa2");      RMIClientSocketFactory rmiClientSocketFactory=new SslRMIClientSocketFactory();     RMIServerSocketFactory rmiServerSockeyFactory=new SslRMIServerSocketFactory();      //create the remote object      try{         SI=new SumaImpl(0,rmiClientSocketFactory,rmiServerSockeyFactory);                }catch(java.rmi.RemoteException e)            {System.out.println(e.getMessage());}      	//registration of SI object      try{                 Naming.bind("rmi://localhost:1099/Adunare",SI);         }catch(java.rmi.AlreadyBoundException e)            {System.out.println(e.getMessage());         }catch(java.net.MalformedURLException e)                {System.out.println(e.getMessage());         }catch(java.rmi.RemoteException e)            {System.out.println(e.getMessage());}                  }}
See also  The Importance of Data Security in Hospitality
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist