I want to call a remote java service via RMI call from within a java service.
I have a Hello server that I can call from a java client running in a command window. Now I want to call the same java service from a java client running under IS.
Following is my code. It fails at the call to Naming.lookup with the following message (note, rmiregistry is running and the Hello service is bound to it):
Could not run ‘helloClient’.
java.lang.reflect.InvocationTargetException: HelloInterface
/**helloClient java service for the “Hello, world!” example. */
try {
System.out.println (“Starting HelloClient”);
String host = “ladson-hp”;
HelloInterface hello;
hello =(HelloInterface) Naming.lookup (“//” + host + “/Hello”);
System.out.println (hello.say());
}
catch (Exception e) {
System.out.println ("HelloClient exception: " + e);
}
Richard,
Are all of the required classes for HelloInterface in the IS classpath? I would assume so since your java service compiles.
When the HelloServer is started and registered does the lookup name match the string being assembled in your code (e.g. “//ladson-hp/Hello”)?
Mark
I am able to run the same java client code from a dos window, indicating that the server is running and the registry is accurate. When running under IS the java code seems to have a problem with reflection, maybe because there is an additional layer of code (that is, IS) underneath the lookup call.
Is this a simple example that you could share? How is your HelloClient connecting to the RMI registry server? I would think you would need a port number in addition to the host name, but its hard to tell without looking at the code.
Mark
I have uploaded Hello.zip which contains the following java files:
Hello.java (server)
HelloClient.java (client)
HelloInterface.java
HelloServer.java
Also included are two batch files:
compileHello.bat
runHelloClient.bat
Simply unzip the files into a directory. Start a DOS window and run the first batch file (compiles all java, runs rmic, starts rmiregistry, and runs the server)
Then start another DOS window and run the second batch file (runs the client)
The server should deliver the message “Hello World” to the client. That is the behavior I am trying to emulate under IS.
BTW, the port defaults to 1099.
Hello.zip (6 KB)
I want to import the class HelloInterface.class into my java service, but I don’t know where to put the class file on the file system. Given the java service name is
IRS_RMI.java1:HelloClient
and the dependent class is
HelloInterface.class
Where do I place the HelloInterface.class class file?
C:\webMethods6\IntegrationServer\lib ???
C:\webMethods6\IntegrationServer\packages\IRS_RMI\lib ???
other ???
Here is what I deduce re placement of class files to support java services.
-
All subordinate class files must be placed in a jar (or zip) file. One cannot import a freestanding class that does not reside in a jar/zip
-
Place the jar in the following folder to make it available server-wide (you must restart IS before the jar is recognized)
C:\webMethods6\IntegrationServer\lib\jars
- Place the jar/zip in the following folder to make it available to a given package (say JavaclassExample)
C:\webMethods6\IntegrationServer\packages\JavaclassExample\code\jars
You need not re-start IS to make the jar/zip available.
- Here is how you reference the class in various contexts.
a. JavaclassExample (package name)
javaclassExample (top level folder name)
javaFolder (second level folder name)
javaService (java service name)
b. javaFolder.MyClass (import reference)
c. String myVariable = MyClass.myMethod(“World”); (code within java svc)
d. myFolder\MyClass.class (contents of jar/zip file)
Here is my java service:
System.out.println(“starting javaService”);
String myVariable = MyClass.myMethod(“World”);
System.out.println("myMethod returned " + myVariable);
System.out.println(“stopping javaService”);
Here is my external supporting class:
import java.io.*;
import java.lang.String;
public class MyClass
{
public static String myMethod(String str)
{
System.out.println(“MyClass.myMethod started with input=” + str);
return str.toUpperCase();
}
}
Richard,
You can import a class for your java services but your classes need to use a package declaration. I think the package name should be the name of any folders above your java service (e.g. folder.subfolder.subfolder), but I always have to experiement to get this right. Take a look at the package declaration in the java source generated from your java service for a hint.
HTH,
Mark