5.2. 원격 자카르타 엔터프라이즈 빈 클라이언트 사용
5.2.1. 초기 컨텍스트 조회
초기 컨텍스트를 생성할 때 PROVIDER_URL 속성을 사용하여 원격 서버의 주소를 전달할 수 있습니다.
public class Client {
public static void main(String[] args)
throws NamingException, PrivilegedActionException, InterruptedException {
InitialContext ctx = new InitialContext(getCtxProperties());
String lookupName = "ejb:/server/HelloBean!ejb.HelloBeanRemote";
HelloBeanRemote bean = (HelloBeanRemote)ctx.lookup(lookupName);
System.out.println(bean.hello());
ctx.close();
}
public static Properties getCtxProperties() {
Properties props = new Properties();
props.put(Context.INITIAL_CONTEXT_FACTORY, WildFlyInitialContextFactory.class.getName());
props.put(Context.PROVIDER_URL, "remote+http://127.0.0.1:8080");
props.put(Context.SECURITY_PRINCIPAL, "joe");
props.put(Context.SECURITY_CREDENTIALS, "joeIsAwesome2013!");
return props;
}
}참고
조회에 사용할 초기 컨텍스트 팩토리는 org.wildfly.naming.client.WildFlyInitialContextFactory 입니다.