SeamFramework.orgCommunity Documentation

부록 A. Integrating Web Beans into other environments

Currently Web Beans only runs in JBoss AS 5; integrating the RI into other EE environments (for example another application server like Glassfish), into a servlet container (like Tomcat), or with an Embedded EJB3.1 implementation is fairly easy. In this Appendix we will briefly discuss the steps needed.

The Web Beans SPI is located in the webbeans-spi module, and packaged as webbeans-spi.jar. Some SPIs are optional, if you need to override the default behavior, others are required.

All interfaces in the SPI support the decorator pattern and provide a Forwarding class located in the helpers sub package. Additional, commonly used, utility classes, and standard implementations are also located in the helpers sub package.

Web Beans also delegates EJB3 bean discovery to the container so that it doesn't have to scan for EJB3 annotations or parse ejb-jar.xml. For each EJB in the application an EJBDescriptor should be discovered:

public interface EjbDescriptor<T>

{
   
   /**
    * Gets the EJB type
    * 
    * @return The EJB Bean class
    */
   public Class<T> getType();
   /**
    * Gets the local business interfaces of the EJB
    * 
    * @return An iterator over the local business interfaces
    */
   public Iterable<BusinessInterfaceDescriptor<?>> getLocalBusinessInterfaces();
   
   /**
    * Gets the remote business interfaces of the EJB
    * 
    * @return An iterator over the remote business interfaces
    */
   public Iterable<BusinessInterfaceDescriptor<?>> getRemoteBusinessInterfaces();
   
   /**
    * Get the remove methods of the EJB
    * 
    * @return An iterator over the remove methods
    */
   public Iterable<Method> getRemoveMethods();
   /**
    * Indicates if the bean is stateless
    * 
    * @return True if stateless, false otherwise
    */
   public boolean isStateless();
   /**
    * Indicates if the bean is a EJB 3.1 Singleton
    * 
    * @return True if the bean is a singleton, false otherwise
    */
   public boolean isSingleton();
   /**
    * Indicates if the EJB is stateful
    * 
    * @return True if the bean is stateful, false otherwise
    */
   public boolean isStateful();
   /**
    * Indicates if the EJB is and MDB
    * 
    * @return True if the bean is an MDB, false otherwise
    */
   public boolean isMessageDriven();
   /**
    * Gets the EJB name
    * 
    * @return The name
    */
   public String getEjbName();

EjbDescriptor는 쉽게 알 수 있어야 하며 EJB 사양에 정의되어 있음으로 관련된 메타데이터를 반환해야 합니다. 이러한 두 가지 인터페이스에 더하여, 로컬 비지니스 인터페이스를 나타내는 BusinessInterfaceDescriptor가 있습니다. (EJB 인스턴스를 검색하는데 사용되는 인터페이스 클래스 및 jndi 이름을 캡슐화)

The resolution of @EJB (for injection into simple beans), the resolution of local EJBs (for backing session beans) and remote EJBs (for injection as a Java EE resource) is delegated to the container. You must provide an implementation of org.jboss.webbeans.ejb.spi.EjbServices which provides these operations. For resolving the @EJB injection point, Web Beans will provide the InjectionPoint; for resolving local EJBs, the EjbDescriptor will be provided, and for remote EJBs the jndiName, mappedName, or ejbLink will be provided.

When resolving local EJBs (used to back session beans) a wrapper (SessionObjectReference) around the EJB reference is returned. This wrapper allows Web Beans to request a reference that implements the given business interface, and, in the case of SFSBs, request the removal of the EJB from the container.

Web Beans must delegate JTA activities to the container. The SPI provides a couple hooks to easily achieve this with the TransactionServices interface.

public interface TransactionServices

{
   /**
    * Possible status conditions for a transaction. This can be used by SPI
    * providers to keep track for which status an observer is used.
    */
   public static enum Status
   {
      ALL, SUCCESS, FAILURE
   }
   /**
    * Registers a synchronization object with the currently executing
    * transaction.
    * 
    * @see javax.transaction.Synchronization
    * @param synchronizedObserver
    */
   public void registerSynchronization(Synchronization synchronizedObserver);
   /**
    * Queries the status of the current execution to see if a transaction is
    * currently active.
    * 
    * @return true if a transaction is active
    */
   public boolean isTransactionActive();
}

The enumeration Status is a convenience for implementors to be able to keep track of whether a synchronization is supposed to notify an observer only when the transaction is successful, or after a failure, or regardless of the status of the transaction.

Any javax.transaction.Synchronization implementation may be passed to the registerSynchronization() method and the SPI implementation should immediately register the synchronization with the JTA transaction manager used for the EJBs.

To make it easier to determine whether or not a transaction is currently active for the requesting thread, the isTransactionActive() method can be used. The SPI implementation should query the same JTA transaction manager used for the EJBs.

The org.jboss.webbeans.bootstrap.api.Bootstrap interface defines the bootstrap for Web Beans. To boot Web Beans, you must obtain an instance of org.jboss.webbeans.bootstrap.WebBeansBootstrap (which implements Boostrap), tell it about the SPIs in use, and then request the container start.

The bootstrap is split into phases, bootstrap initialization and boot and shutdown. Initialization will create a manager, and add the standard (specification defined) contexts. Bootstrap will discover EJBs, classes and XML; add beans defined using annotations; add beans defined using XML; and validate all beans.

The bootstrap supports multiple environments. An environment is defined by an implementation of the Environment interface. A number of standard envrionments are built in as the enumeration Environments. Different environments require different services to be present (for example servlet doesn't require transaction, EJB or JPA services). By default an EE environment is assumed, but you can adjust the environment by calling bootstrap.setEnvironment().

Web Beans uses a generic-typed service registry to allow services to be registered. All services implement the Service interface. The service registry allows services to be added and retrieved.

To initialize the bootstrap you call Bootstrap.initialize(). Before calling initialize(), you must register any services required by your environment. You can do this by calling bootstrap.getServices().add(JpaServices.class, new MyJpaServices()). You must also provide the application context bean store.

Having called initialize(), the Manager can be obtained by calling Bootstrap.getManager().

To boot the container you call Bootstrap.boot().

To shutdown the container you call Bootstrap.shutdown() or webBeansManager.shutdown(). This allows the container to perform any cleanup operations needed.

API의 외부 구현에서의 올바른 기능을 실행하게 하기 위해 Web Beans RI이 컨테이너에 위치하게 해야 할 여러 요구 사항이 있습니다

Classloader 분리

Web Beans RI를 다수의 애플리케이션의 운용을 지원하는 환경으로 통합할 경우, 각각의 Web Beans 애플리케이션에 대한 클래스로더 분리를 자동으로 또는 사용자 설정을 통해 반드시 활성화해야 합니다.

Servlet

Web Beans를 Servlet 환경으로 통합할 경우, Servlet을 사용하는 각각의 Web Beans 애플리케이션에 대해 자동으로 또는 사용자 설정을 통해 org.jboss.webbeans.servlet.WebBeansListener를 Servlet 청취자로 등록해야 합니다.

JSF

If you are integrating the Web Beans into a JSF environment you must register org.jboss.webbeans.jsf.WebBeansPhaseListener as a phase listener, and org.jboss.webbeans.el.WebBeansELREsolver as an EL resolver, either automatically, or through user configuration, for each Web Beans application which uses JSF.

If you are integrating the Web Beans into a JSF environment you must register org.jboss.webbeans.servlet.ConversationPropagationFilter as a Servlet listener, either automatically, or through user configuration, for each Web Beans application which uses JSF. This filter can be registered for all Servlet deployment safely.

Session Bean 인터셉터

Web Beans를 EJB 환경으로 통합하고자 할 경우 엔터프라이즈 beans를 사용하는 각각의 Web Beans 애플리케이션 용으로 모든 EJB 애플리케이션에 대해 EJB 인터셉터로서 org.jboss.webbeans.ejb.SessionBeanInterceptor를 자동으로 또는 사용자 설정을 통해 등록해야 합니다.

The webbeans-core.jar

If you are integrating the Web Beans into an environment that supports deployment of applications, you must insert the webbeans-core.jar into the applications isolated classloader. It cannot be loaded from a shared classloader.

Binding the manager in JNDI

You should bind a Reference to the Manager ObjectFactory into JNDI at java:app/Manager. The type should be javax.inject.manager.Manager and the factory class is org.jboss.webbeans.resources.ManagerObjectFactory