IT 전용글/EJB

HelloClient 작성 방법 (2009 02 04 오전)

회상형인간 2009. 2. 4. 11:32

1. HelloClient.java 파일 생성. 

1-1 : 원격 홈 객체의 ref 얻기
원격 J2EE SERVER 의  Naming Service 의 Ref 얻기
  Properties prop = new Properties();
  prop.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
  prop.put(Context.PROVIDER_URL,"t3://211.183.3.212");
  Context context = new InitialContext(prop);
       //  b. JNDI NAME 으로 Lookup 해서  홈 객체의 ref얻기
  //   원격홈객체의 ref 는 CORBA 객체 타입이다.
Object homeObject = context.lookup("MyBean");

         // CORBA 객체 를 자바객체로 Narrowing 해준다.
  HelloHome home = (HelloHome)PortableRemoteObject.narrow(homeObject,HelloHome.class);

 

//#2. home.create() 메쏘드 호출
  // 원격 객체 ref 얻기
  Hello hello = home.create();
  String result = hello.greet("아나콘다");
  System.out.println("result :" + result);




#import 작업 한후 Exception을 던져준다.
import javax.rmi.PortableRemoteObject;
import javax.naming.Context;
import javax.naming.InitialContext;
import java.util.Properties;
import hello.HelloHome;
import hello.Hello;


public static void main(String[] args) throws Exception{

}


컴파일후


웹로직서버를 올린후 클라이언트를 실행하게 되면  어제 했던 작업(Deploy)  에 있는

원격 객체의 greet 메쏘드가 실행되게 된다.