2012-12-09 3 views
1

Groovy에서 내 세션 빈 (Java로 작성되고 Weblogic에 배포 됨)에 대한 RMI 호출을 수행 할 수있는 코드 스 니펫을 제공 할 수 있습니까?Groovy를 사용하여 내 세션 빈에 RMI 호출

편집 한

이 내 자바 코드입니다. Groovy에서 더 쉬운 방법이 있습니까?

Properties props = new Properties(); 
props.put("java.naming.factory.initial", "weblogic.jndi.WLInitialContextFactory"); 
props.put("java.naming.provider.url",”t3://127.0.0.1:7001”); // url+port format 
props.put("java.naming.security.principal", “weblogic_username”)); 
props.put("java.naming.security.credentials", “weblogic_password”); 
try 
{ 
    String simpleName = MyRemoteClass.class.getSimpleName(); 
    String fullName = MyRemoteClass.class.getName(); 
    String name = simpleName + "#" + fullName; 
    initContext = new InitialContext(props); 
    MyRemoteClass remoteClass = (MyRemoteClass)initContext.lookup(name); 

    remoteClass.doSomething(); 
} 
catch (Throwable ex) 
{ 
} 
+1

그것은 단지 당신이 어떤 구문 설탕 혜택을 누릴 수 있습니다, 거의 같은 것입니다. 너 뭐 해봤 니? – Will

+0

@WillP 자바 코드를 추가했습니다. – hsalimi

답변

2

Groovy에서 RMI 호출을 줄이거 나 쉽게 처리 할 수있는 라이브러리에 대해 알지 못합니다. 아무도이 없다면, 당신은 문법적, 강제 암시 적 캐스팅에서 적어도 혜택을 누릴 수 있습니다 :

def props = [ 
    "java.naming.factory.initial" : "weblogic.jndi.WLInitialContextFactory", 
    "java.naming.provider.url" : "t3://127.0.0.1:7001", // url+port format 
    "java.naming.security.principal" : "weblogic_username", 
    "java.naming.security.credentials" : "weblogic_password" 
] as Properties 

try 
{ 
    def name = "${MyRemoteClass.simpleName}#${MyRemoteClass.name}" 
    initContext = new InitialContext(props) 
    MyRemoteClass remoteClass = initContext.lookup name 

    remoteClass.doSomething() 
} 
catch (t) 
{ 
    t.printStackTrace() 
} 

멋져요 :-)

+0

감사합니다. 그러나 그것은 Java입니다. 나는 더 쉬운 것을 찾고 있었다. : -) – hsalimi

+0

"자바 야"란 무엇을 의미합니까? – Will

+1

내가 언급 한 코드보다 더 쉬운 것을 찾고 있음을 의미합니다. – hsalimi

관련 문제