Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Java
Expertise: Intermediate
Jun 24, 1999

Identify Host That Called Remote Method

When creating remote objects for use with Java's Remote Method Invocation (RMI), you'll often extend java.rmi.server.UnicastRemoteObject. When you do extend UnicastRemoteObject, it becomes easy for the remote methods to determine the host name of the caller. This can be useful for security or logging purposes, as it allows you to limit and/or record which hosts perform remote method calls. To identify the host that called a particular method, use the getClientHost() method. For example:

 
public void myRemoteMethod() {
try {
String client = getClientHost();
System.out.println("Called by " + client);
}  //  try
catch (ServerNotActiveException snae) {
		System.out.println("Server not active");
}  //  catch (ServerNotActiveException snae)
}  //  public void myRemoteMethod()

The getClientHost() method returns a String instance containing the name of the host which called the method. This allows you to easily determine where remote method calls originate from and to implement auditing or security which stores or processes that information.

Brett Spell
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap