aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes how to deploy ejb on sun application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "how to deploy ejb on sun application" Watch "how to deploy ejb on sun application" New topic
Author

how to deploy ejb on sun application

hassan ali
Ranch Hand

Joined: Apr 23, 2006
Posts: 127
i am facing problem with deploy my 1st EJB
i have no excperince with it at all.

i have deploy them in EJB on sun appliaction server 8.2 but how can i try to use it with it client.
when try to run client says it can not connect to ORB
please give me hand to get up

1-i have this homeobject

import javax.ejb.*;
import java.rmi.RemoteException;

/**
* This is the home interface for HelloBean. This interface
* is implemented by the EJB Server - the
* implemented object is called the Home Object, and serves
* as a factory for EJB Objects.
*
* The create() method in this Home Interface corresponds to
* the ejbCreate() method in HelloBean.
*/
public interface HelloHome extends EJBHome {

/*
* This method creates the EJB Object.
*
* then returns a reference to the newly created EJB Object.
*/
Hello create() throws RemoteException, CreateException;
}

2- this is ojb
import javax.ejb.*;
import java.rmi.RemoteException;
import java.rmi.Remote;

/**
* This is the HelloBean remote interface.
*
* This interface is what clients use to
* interact with EJB objects. The container
* vendor implements this interface. The
* implemented object is the EJB object, which
* delegates method calls to the actual EJB.
*/
public interface Hello extends EJBObject {

/**
* The hello() method returns a greeting to the client.
*/
public String hello() throws RemoteException;
}
3- this is the bean it self.

import javax.ejb.*;
import javax.naming.*;
import javax.rmi.*;

/**
* Demonstration stateless session bean.
*/
public class HelloBean implements SessionBean {

public String test;
//
// EJB-required methods
//
public void ejbCreate() {
System.out.println("ejbCreate()");
}

public void ejbRemove() {
System.out.println("ejbRemove()");
}

public void ejbActivate() {
System.out.println("ejbActivate()");
}

public void ejbPassivate() {
System.out.println("ejbPassivate()");
}

public void setSessionContext(SessionContext ctx) {
System.out.println("setSessionContext()");
}

//
// Business methods
//
public String hello() {
System.out.println("hello()");
return "Hello, World!";
}
}

4- this th client
import javax.ejb.*;
import javax.rmi.*;
import javax.naming.*;
import java.util.*;

public class HelloClient {

public static void main (String args[]) {
Hashtable props = new Hashtable();
InitialContext initCtx;

try {

props.put("java.naming.factory.initial", "com.sun.jndi.cosnaming.CNCtxFactory");
props.put("java.naming.provider.url", "iiop://localhost:1050");

initCtx = new InitialContext(props);

Object obj = initCtx.lookup("HelloHome");

HelloHome hh = (HelloHome) PortableRemoteObject.narrow(obj, HelloHome.class);
Hello h = (Hello)hh.create();

System.out.println(h.hello());

h.remove();
}
catch(Exception e) {

e.printStackTrace();
System.out.println(e.getMessage());

}
}
}
Jeroen T Wenting
Ranch Hand

Joined: Apr 21, 2006
Posts: 1847
Try another port. By default SJSAS 8.2 runs the ORB on port 3700.

Mind that if I try your code on that port I experience another problem, a null result from PortableRemoteObject.narrow().


42
hassan ali
Ranch Hand

Joined: Apr 23, 2006
Posts: 127
thank you

i have tried this port but nothing happend problem still there
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: how to deploy ejb on sun application