Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

How can i access to Remote Object (EJB remote) on a different host

  Asked By: Jody    Date: Feb 03    Category: Java    Views: 3010
  

i want to composite JNDI and RMI in ejb3
assuming the server is running on host tt.MYHOST(192.168.1.13)

my java client object wants to access to this address

how can i do this.

my web app is glassfish
i've red something about "java -Dorg.omg......" is it necessary to set ? or not? in client system or in server ?
would you write me an example code please?

Share: 

 

7 Answers Found

 
Answer #1    Answered By: Rachael Ferguson     Answered On: Feb 03

In EJB 3.0 you could use annotation for Remote access  and xml descriptor too.
if your requirement is that access from another machines to this business logic you have to set an Interface over your implementation and use @Remote annotation for it and in your implementation you have to set JNDI for it. you could use jboss seam (Web Beans JSR-299) to solve your problems in easy way.

 
Answer #2    Answered By: Muhammad Evans     Answered On: Feb 03

I know that JNDI is my solution, and i know that i can use annotation for Remote access  or descrioptor.
but assume that you created your componets on your server  and everything is working good. now you want to access this components from another machine.

Main question:
how can you import or access the components from the client machine? for example your componet (test.jar (TestBean.class)) and it's on your server and now you want to call this bean file,but you're working on a different machine. your JVM (Client machine) will not recognize the test.jar or TestBean.class:D. you see this is my main problem. how can i compile my client java file in client machine?
how can i set my classpath in client machine?
what should i do?

 
Answer #3    Answered By: Kian Evans     Answered On: Feb 03

if you use application client
you can run it with applclient application bundled with glassfish to run it ans using benefits of Java EE 5 Application client container.
if you have netbeans, you can create an Enterprise application then you have three sub projects:
1) EJB project
2) Web project
3) Application client module

the first 2 are checked by default and you have to check the 3'rd option.
then netbeans creates an enterprise application with a client module for your.
the client is compiled as a jar, and can be deployed to a glassfish server  or runned using appclient application.

 
Answer #4    Answered By: Tomas Thompson     Answered On: Feb 03

I forget to add, if you are deploying appclient on another machine (other than ejb) and the client machine dosn't have an container clustered with server  machine, you can use both annotations or JNDI lookup
for more info see this page:

https://glassfish.dev.java.net/javaee5/ejb/EJB_FAQ.html#StandaloneRemoteEJB

 
Answer #5    Answered By: Madeeha Malik     Answered On: Feb 03

In order for a client to connect to your remote  GlassFish server  you need to add a second IIOP listener with the hostname listening at a different port (ex: 3701). You can do this via the GlassFish admin console.

Create a Java project in Eclipse that will be a standalone ejb  3.0 client application.

When deploying the previously created EJB jar on glassfish using the admin console check the option that creates the client .jar file. Then locate the *Client.jar file on the server and make your project depend on this jar.

Your client app should have code similar to below:

public class Client {

@SuppressWarnings("unchecked")
public void runTest() throws Exception {
Properties props = new Properties();

props.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.enterprise.naming.SerialInitContextFactory");
props.setProperty("org.omg.CORBA.ORBInitialHost", "");
// NOTE: IIOP is set on port 3701 but this works on port 3700
props.setProperty("org.omg.CORBA.ORBInitialPort", "3700");

InitialContext ctx = new InitialContext(props);

OrderBean bean = (OrderBean) ctx.lookup("ejb/OrderBean");

Order result = bean.findByOrderNum(9);
System.out.println(result.getDescript());
}

public static void main(String[] args) {
Client cli = new Client();
try {
cli.runTest();
} catch (Exception e) {
e.printStackTrace();
}
}
}

 
Answer #6    Answered By: Aaminah Khan     Answered On: Feb 03

I don't know much about Glassfish but this is how it goes in general. You will need to pick a solution by combining all the replies to your email. First, each app server  comes with a jndi  library. You need to put that in your client's class path and set the initial context to use app server specific classes. Probably you will find a document page on glassfish website for this. Next is to bring in interface classes for the remote  ejb; this is a rather manual step but there might be other solutions for this. That said, the rest is a typical jndi lookup. One thing that might catch you though is the ejb  name. Conventionally, each app server has a second set of deployment descriptors and in case of, for example, JBoss app server vendor deployment descriptor is the one that sets the ejb name and all that. You might also want to look into classloading issues if your client app will in anyway share a jvm with the app server.

 
Answer #7    Answered By: Anne Powell     Answered On: Feb 03

you don't need -Dorg,omg....
take a look at "Application Client" section of the Java EE 5 Tutorial
it has described how to write application clients completely.

Application Clients are new type of applications that you can use to access  EJB components much more easily.

 




Tagged: