Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to deploy ejb on sun application

 
hassan ali
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1847
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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().
 
hassan ali
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you

i have tried this port but nothing happend problem still there
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic