원격 세션 Bean에 액세스

EJB 클라이언트 응용프로그램은 Bean의 홈 인터페이스를 통해 해당 원격 세션 Bean에 액세스합니다.

이 타스크의 수행 목적 및 시기

세션 Bean은 프로세스 응용프로그램에 대해서는 BusinessFlowManager 세션 Bean 또는 타스크 응용프로그램에 대해서는 HumanTaskManager 세션 Bean일 수 있습니다.

이 타스크의 단계

  1. 원격 세션 Bean에 대한 참조를 응용프로그램 전개 설명자에 추가하십시오. 다음 파일 중 하나에 참조를 추가하십시오.
    • J2EE(Java™ 2 Platform, Enterprise Edition) 클라이언트 응용프로그램의 경우, application-client.xml 파일
    • 웹 응용프로그램의 경우, web.xml 파일
    • EJB(Enterprise JavaBeans™) 응용프로그램의 경우, ejb-jar.xml 파일
    프로세스 응용프로그램의 원격 홈 인터페이스에 대한 참조가 다음 예에 표시됩니다.
    <ejb-ref>
    	<ejb-ref-name>ejb/BusinessFlowManagerHome</ejb-ref-name>
    	<ejb-ref-type>Session</ejb-ref-type>
    	<home>com.ibm.bpe.api.BusinessFlowManagerHome</home>
    	<remote>com.ibm.bpe.api.BusinessFlowManager</remote>
    </ejb-ref>
    타스크 응용프로그램의 원격 홈 인터페이스에 대한 참조가 다음 예에 표시됩니다.
    <ejb-ref>
    	<ejb-ref-name>ejb/HumanTaskManagerHome</ejb-ref-name>
    	<ejb-ref-type>Session</ejb-ref-type>
    	<home>com.ibm.task.api.HumanTaskManagerHome</home>
    	<remote>com.ibm.task.api.HumanTaskManager</remote>
    </ejb-ref>

    WebSphere® Integration Developer를 사용하여 EJB 참조를 전개 설명자에 추가하는 경우 EJB 참조의 바인딩은 응용프로그램이 전개될 때 자동으로 작성됩니다. EJB 참조 추가에 대한 자세한 내용은 WebSphere Integration Developer 문서를 참조하십시오.

  2. 응용프로그램에서 생성된 스텁을 패키지하십시오.

    사용자의 응용프로그램이 BPEContainer 응용프로그램 또는 TaskContainer 응용프로그램이 실행되는 JVM(Java Virtual Machine)과 다른 JVM에서 실행되는 경우 다음 조치를 완료하십시오.

    1. 프로세스 응용프로그램의 경우, <install_root>/ProcessChoreographer/client/bpe137650.jar 파일을 응용프로그램의 EAR(Enterprise Archive) 파일에 패키지하십시오.
    2. 타스크 응용프로그램의 경우, <install_root>/ProcessChoreographer/client/task137650.jar 파일을 응용프로그램의 EAR 파일에 패키지하십시오.
    3. 비즈니스 프로세스 또는 휴먼 타스크에서 복잡한 데이터 유형을 사용하고 EJB 응용프로그램 또는 웹 응용프로그램에서 클라이언트를 실행하지 않는 경우, 해당하는 XSD 또는 WSDL 파일을 응용프로그램의 EAR 파일에 패키지하십시오.
    4. JAR 파일을 포함하도록 응용프로그램 모듈의 Manifest 파일에 있는 Classpath 매개변수를 설정하십시오.

      응용프로그램 모듈은 J2EE 응용프로그램, 웹 응용프로그램 또는 EJB 응용프로그램일 수 있습니다.

  3. JNDI(Java Naming and Directory Interface)에서 원격 세션 Bean의 홈 인터페이스에 대한 참조를 검색하십시오.

    다음 예는 프로세스 응용프로그램에 대한 해당 단계를 표시합니다.

    // Obtain the default initial JNDI context
    InitialContext initialContext = new InitialContext();
    
      // Lookup the remote home interface of the BusinessFlowManager bean
      Object result = 
             initialContext.lookup("java:comp/env/ejb/BusinessFlowManagerHome");
    
    // Convert the lookup result to the proper type
       BusinessFlowManagerHome processHome = 
               (BusinessFlowManagerHome)javax.rmi.PortableRemoteObject.narrow
               (result,BusinessFlowManagerHome.class);
    세션 Bean의 홈 인터페이스에는 EJB 오브젝트에 대한 작성 메소드가 포함됩니다. 이 메소드는 세션 Bean의 원격 인터페이스를 리턴합니다.
  4. 세션 Bean의 원격 인터페이스에 액세스하십시오.

    다음 예는 프로세스 응용프로그램에 대한 해당 단계를 표시합니다.

    BusinessFlowManager process = processHome.create();

    세션 Bean에 액세스할 수 있다고 해서 호출자가 프로세스에 대한 모든 조치를 수행할 수 있는 것입니다. 호출자는 또한 해당 조치를 수행할 수 있는 권한을 가지고 있어야 합니다. 세션 Bean의 인스턴스를 작성할 때 컨텍스트는 세션 Bean의 인스턴스와 연관됩니다. 컨텍스트에는 호출자의 프린시펄 ID, 그룹 멤버쉽 목록이 포함되며 컨텍스트는 호출자가 Business Process Choreographer J2EE 역할 중 하나를 가지는지 여부를 표시합니다. 글로벌 보안을 설정하지 않은 경우라도 컨텍스트를 사용하여 각 호출에 대한 호출자의 권한을 확인할 수 있습니다. 글로벌 보안을 설정하지 않은 경우, 호출자의 프린시펄 ID는 UNAUTHENTICATED 값을 가집니다.

  5. 서비스 인터페이스에서 표시한 비즈니스 함수를 호출하십시오.

    다음 예는 프로세스 응용프로그램에 대한 해당 단계를 표시합니다.

    process.initiate("MyProcessModel",input);
    응용프로그램의 호출이 트랜잭션으로 실행됩니다. 트랜잭션은 다음 방법 중 하나로 설정 및 종료됩니다.
    • WebSphere Application Server에 의해 자동으로(전개 설명자가 TX_REQUIRED 지정).
    • 응용프로그램에 의해 명시적으로. 응용프로그램 호출을 하나의 트랜잭션으로 번들화할 수 있습니다.
      // Obtain user transaction interface
      UserTransaction transaction= 
             (UserTransaction)initialContext.lookup("jta/usertransaction");
      
      // Begin a transaction
      transaction.begin();
      
      // Applications calls ...
      
      // On successful return, commit the transaction
      transaction.commit();
    팁: 데이터베이스 교착 상태를 방지하려면 다음과 유사한 명령문을 병렬 트랜잭션으로 실행하지 마십시오.
    // Obtain user transaction interface
    UserTransaction transaction= 
           (UserTransaction)initialContext.lookup("jta/usertransaction");
    
    transaction.begin();
    
    //read lock on the activity instance 
    process.getActivityInstance(aiid);     
    //write lock on the activity instance
    process.claim(aiid);               
         
    transaction.commit();

다음 예제에서는 3단계에서 5단계까지를 통해 타스크 응용프로그램을 찾는 방법을 보여줍니다.

// Obtain the default initial JNDI context
InitialContext initialContext = new InitialContext();

// Lookup the remote home interface of the HumanTaskManager bean
Object result = 
         initialContext.lookup("java:comp/env/ejb/HumanTaskManagerHome");

// Convert the lookup result to the proper type
HumanTaskManagerHome taskHome = 
           (HumanTaskManagerHome)javax.rmi.PortableRemoteObject.narrow
           (result,HumanTaskManagerHome.class);

...
//Access the remote interface of the session bean.
HumanTaskManager task = taskHome.create();

...
//Call the business functions exposed by the service interface
task.callTask(tkiid,input);
관련 개념
비즈니스 프로세스의 권한 역할
휴먼 타스크의 권한 역할

ⓒ Copyright IBM Corporation 2005, 2006.
이 Information Center는 Eclipse 기술을 기반으로 합니다. (http://www.eclipse.org)