Hi Jean-Louis,
Thanks, it's classpath problem. I can solve this problem after including the
current directory in the CLASSPATH. But I encounter another problem when
invoking the method of the EJB from the Java client.
public class OrderClient {
  public static void main(String[] args) {
    try {
      Properties prop = new Properties();
      prop.put("java.naming.factory.initial",
"org.apache.openejb.client.RemoteInitialContextFactory");
      prop.put("java.naming.provider.url",
"http://127.0.0.1:8088/openejb/ejb";);
      InitialContext icOrderSB = new InitialContext(prop);
      Object objOrderSB = icOrderSB.lookup("java:OrderSBRemoteHome");
      OrderSBHome orderSBHome =
(OrderSBHome)PortableRemoteObject.narrow(objOrderSB, OrderSBHome.class);
      OrderSB orderSB = orderSBHome.create();
      Collection cResults = orderSB.getAllAccounts();
      Iterator iterator = cResults.iterator();
      while (iterator.hasNext()) {
        Account account =
(Account)PortableRemoteObject.narrow(iterator.next(), Account.class);
        System.out.println("Account: "+account.getOwnerName());
      }
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
    }
  }
}

There is error when executing "account.getOwnerName()".
java.rmi.RemoteException: Unknown Container Exception:
java.rmi.RemoteException:
 Cannot open input stream to server: ; nested exception is:
        java.io.FileNotFoundException: http://127.0.0.1:8080/openejb/ejb;
nested
 exception is:
        java.io.FileNotFoundException: http://127.0.0.1:8080/openejb/ejb
        at
org.apache.openejb.client.EJBObjectHandler._invoke(EJBObjectHandler.j
ava:177)
        at
org.apache.openejb.client.EJBInvocationHandler.invoke(EJBInvocationHa
ndler.java:117)
        at
org.apache.openejb.client.proxy.Jdk13InvocationHandler.invoke(Jdk13In
vocationHandler.java:52)
        at $Proxy2.getOwnerName(Unknown Source)
        at clientuser.OrderClient.main(OrderClient.java:36)

I have modified the port for tomcat to "8088" but the error message shown
that it wants to access the "8080" port. Is there any configuration required
for OpenEJB to use "8088" port? Or this can be overcome programatically.
Please advise, much thanks.

SK


Jean-Louis MONTEIRO wrote:
> 
> Hi,
> 
> The remote URL depends on the mode used by OpenEJB
> - standalone ejbd
> - embedded tomcat http
> - ....
> 
> You need to set the url according to your mode. As far as i can
> understand, you are using OpenEJB embedded in Tomcat so you must use
> something like "http://127.0.0.1:8080/openejb/ejb";
> 
> Obviously, you must adjust the host and the port according to your tomcat
> configuration (connectors).
> Have a look here for more information 
> http://openejb.apache.org/3.0/clients.html
> http://openejb.apache.org/3.0/clients.html 
> 
> Then, regarding your classpath issue, can you try something like
> set CLASSPATH=.
> set CLASSPATH=clientapp\javaee-api-5.0-1.jar;%CLASSPATH%
> set CLASSPATH=clientapp\openejb-client-3.0.jar;%CLASSPATH%
> "%JAVA_HOME%\bin\javac" clientuser\OrderClient.java
> "%JAVA_HOME%\bin\java" clientuser.OrderClient
> 
> Just as a side note, in the first case, you reset the classpath before
> launching the application which is bad cause you need openejb
> dependencies.
> 
> In the second case, you forgot to add your compile classes, so it doesn't
> work.
> 
> Hope it helps.
> Jean-Louis
> 
> 
> 
> 
> 
> 
> SK Leung wrote:
>> 
>> I have created a remote Java client to access the EJB which is Tomcat
>> 6.0.14+OpenEJB 3.0.
>> 
>> The file structure is as below:
>> clientapp\clientuser\OrderClient.class
>> clientapp\openejb-client-3.0.jar
>> clientapp\javaee-api-5.0-1.jar
>> clientapp\runClient.bat
>> 
>> The Java client is with the following lines:
>> package clientuser;
>> import ...
>> public class OrderClient {
>>   public static void main(String[] args) {
>>     Properties prop = new Properties();
>>     prop.put("java.naming.factory.initial",
>>       "org.apache.openejb.client.RemoteInitialContextFactory");
>>     prop.put("java.naming.provider.url",
>> "http://127.0.0.1:8088/openejb/ejb";);
>>     InitialContext icOrderSB = new InitialContext(prop);
>>   }
>> }
>> 
>> If I have the batch file runClient.bat as
>> set
>> CLASSPATH=clientapp\javaee-api-5.0-1.jar;clientapp\openejb-client-3.0.jar
>> "E:\Program Files\Java\jdk1.6.0_16\bin\javac" clientuser\OrderClient.java
>> set CLASSPATH=
>> "E:\Program Files\Java\jdk1.6.0_16\bin\java" clientuser.OrderClient
>> 
>> I got the error message:
>> javax.naming.NoInitialContextException: Cannot instantiate class:
>> org.apache.openejb.client.RemoteInitialContextFactory [Root exception is
>> java.lang.ClassNotFoundException:
>> org.apache.openejb.client.RemoteInitialContextFactory]
>> 
>> If I have the batch file runClient.bat as
>> set
>> CLASSPATH=clientapp\javaee-api-5.0-1.jar;clientapp\openejb-client-3.0.jar
>> "E:\Program Files\Java\jdk1.6.0_16\bin\javac" clientuser\OrderClient.java
>> "E:\Program Files\Java\jdk1.6.0_16\bin\java" clientuser.OrderClient
>> 
>> I got the error message:
>> Exception in thread "main" java.lang.NoClassDefFoundError:
>> clientuser/OrderClient
>> 
>> What is going wrong? Please advise. Thanks.
>> 
>> SK
>> 
> 
> 

-- 
View this message in context: 
http://old.nabble.com/Running-Remote-Java-Client-tp26795519p26812199.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Reply via email to