advertisement
Login | Register   
  Include Code  Search Tips
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Partners & Affiliates
advertisement
advertisement
Tip of the Day
Average Rating: 1/5 | Rate this item | 2 users have rated this item.
Expertise: Intermediate
Language: Java
February 28, 2006
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{
//constructor
public SumaImpl(int port,RMIClientSocketFactory rmiC, RMIServerSocketFactory rmiS)
throws RemoteException
{
//optional
super(port,rmiC,rmiS);
}
//implementing the Suma method
public 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());}
}
}
Anghel Leonard
If you have a hot tip and we publish it, we'll pay you. However, due to accounting overhead we no longer pay $10 for a single tip submission. You must accumulate 10 acceptable tips to receive payment. Be sure to include a clear explanation of what the technique does and why it's useful. If it includes code, limit it to 20 lines if possible. Submit your tip here.
Please rate this item (5=best)
 1  2  3  4  5
advertisement
advertisement