Configuration of the Smart Client Container

Author: Holger Engels

Overview

The client consists of an application-client and optionally some local session beans. The application client is packaged in a jar as described in chapter 9.6 of the J2EE Spec 1.3. The packaging of the ejb-jars is described in chapter 23 of the EJB Spec 2.0. Both, the application client and the ejb jars have additional deployment descriptors that provide the ejb-(local)?-refs with detailed configuration.

Smart References

An ejb-ref can be defined toplevel in the application-client.xml or in the context of a session bean in the ejb-jar.xml. The corresponding smart-ref in the smart deployment descriptor is located at structurally the same place. If an ejb-ref is contained in a <session> with name blubber , then the corresponding smart-ref has also to be placed below a <session> with name blubber. A smart ref has the same ejb-ref-name as the ejb-ref and defines up to three units of information:

transport
How to connect the component. At the moment, there are two alternatives org.smartcc.RMITransport and org.smartcc.HTTPTransport. In future, there will also be a SOAPTransport
lookup
Where to find the component. This is the jndi name for RMI transport or the URL of the connector servlet for HTTP transport
properties
Additional information for the transport. The RMI transport uses jndi to locate the home interface of the session bean. The properties are provided to the InitialContext (Application Server dependent).

The following section shows the definition of an ejb reference contained in an application client. The transport is RMI, the server is JBoss and there are no interceptors specified.

<application-client>  <ejb-ref>    <ejb-ref-name>ejb/RemoteTest</ejb-ref-name>    <ejb-ref-type>Session</ejb-ref-type>    <home>org.smartcc.test.RemoteTestHome</home>    <remote>org.smartcc.test.RemoteTest</remote>  </ejb-ref></application-client>
<smart-client>  <smart-ref>    <ejb-ref-name>ejb/RemoteTest</ejb-ref-name>    <transport>org.smartcc.RMITransport</transport>    <lookup>ejb/RemoteTest</lookup>    <properties>      java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory      java.naming.provider.url=jnp://localhost:1099    </properties>  </smart-ref></smart-client>

The following section shows the definition of an ejb reference inside a local ejb. The transport is HTTP and two interceptors are specified.

<ejb-jar>   <enterprise-beans>      <session>         <ejb-name>DelegateTest</ejb-name>         <local-home>org.smartcc.test.DelegateTestLocalHome</local-home>         <local>org.smartcc.test.DelegateTestLocal</local>         <ejb-class>org.smartcc.test.DelegateTestBean</ejb-class>         <session-type>Stateless</session-type>         <transaction-type>Bean</transaction-type>         <ejb-ref>            <ejb-ref-name>ejb/RemoteTest</ejb-ref-name>            <ejb-ref-type>Session</ejb-ref-type>            <home>org.smartcc.test.RemoteTestHome</home>            <remote>org.smartcc.test.RemoteTest</remote>         </ejb-ref>      </session>   </enterprise-beans></ejb-jar>
<smart-ejb-jar>  <enterprise-beans>    <session>      <ejb-name>DelegateTest</ejb-name>      <smart-ref>        <ejb-ref-name>ejb/RemoteTest</ejb-ref-name>        <transport>org.smartcc.HTTPTransport</transport>        <lookup>ejb/RemoteTest</lookup>        <properties>          org.smartcc.connector.url=http://localhost:8080/HTTPConnector/        </properties>      </smart-ref>    </session>  </enterprise-beans></smart-ejb-jar>

Smart Local References

An ejb-local-ref can also be defined toplevel in the application-client.xml or context of a session bean in the ejb-jar.xml. The corresponding smart-local-ref in the smart deployment descriptor is located at structurally the same place. If an ejb-local-ref is contained in a <session> with name blubber, then the corresponding smart-local-ref has also to be placed below a <session> with name blubber. A smart local ref has the same ejb-ref-name as the ejb-local-ref and defines the lookup in the form of a jndi name.

The following section shows the definition of an ejb local reference contained in an application client. The lookup is the jndi name of the local session bean. Beware, that local-ejb-refs are not defined in the application-client_1_3.dtd. However, they are defined in the ejb-jar_2_0.dtd and the web-app_2_3.dtd.

<application-client>  <ejb-local-ref>    <ejb-ref-name>ejb/LocalTest</ejb-ref-name>    <ejb-ref-type>Session</ejb-ref-type>    <local-home>org.smartcc.test.LocalTestLocalHome</local-home>    <local>org.smartcc.test.LocalTestLocal</local>  </ejb-local-ref></application-client>
<smart-client>  <smart-local-ref>    <ejb-ref-name>ejb/LocalTest</ejb-ref-name>    <lookup>local/LocalTest</lookup>  </smart-local-ref></smart-client>

The following section shows the definition of an ejb local reference inside a local ejb.

<ejb-jar>   <enterprise-beans>      <session>         <ejb-name>AnotherTest</ejb-name>         <local-home>org.smartcc.test.AnotherTestLocalHome</local-home>         <local>org.smartcc.test.AnotherTestLocal</local>         <ejb-class>org.smartcc.test.AnotherTestBean</ejb-class>         <session-type>Stateless</session-type>         <transaction-type>Bean</transaction-type>         <ejb-local-ref>            <ejb-ref-name>ejb/LocalTest</ejb-ref-name>            <ejb-ref-type>Session</ejb-ref-type>            <local-home>org.smartcc.test.LocalTestHome</local-home>            <local>org.smartcc.test.LocalTest</local>         </ejb-local-ref>      </session>   </enterprise-beans></ejb-jar>
<smart-ejb-jar>  <enterprise-beans>    <session>      <ejb-name>AnotherTest</ejb-name>      <smart-local-ref>        <ejb-ref-name>ejb/LocalTest</ejb-ref-name>        <lookup>local/LocalTest</lookup>      </smart-local-ref>    </session>  </enterprise-beans></smart-ejb-jar>

Local references from a local bean to another local bean are there more or less for the sake of completeness. It's hard to imagine a real world scenario. Most of the client logic will be implemented as part of the application client and not in local session beans. However, if you plan to share logic between wep applications and java applications, local session beans will come in very handy.

Transports

The transport is the gateway between the caller context and that of the callee. For local session beans this is the place where the invocation is propagated to the target bean's proxies. Beside the jndi-name of the target's, there's nothing to configure. However, references to remote beans have to pass the network with all its peculiarities. The invocation has to be marshalled some way and the implementation must be able to deal with all the typical error situations. At the moment, there are two transports realized: org.smartcc.RMITransport and org.smartcc.HTTPTransport. The former delegates the job to the stub implementation of the particular server. The configuration of the RMITransports includes the jndi.properties of the server's jndi provider and the jndi name. The following properties address the naming service of WebSphere 4.0 on localhost:

java.naming.factory.initial=com.ibm.websphere.naming.WsnInitialContextFactoryjava.naming.provider.url=iiop://localhost:900

The HTTPTransport is a special case in that it requires a peer on the server: the HTTPConnector servlet. The servlet receives invocations via HTTP POST and forwards them to the particular stub of the target bean. The servlet uses the path info as the jndi name for the lookup of the home interface proxy. The web.xml of the servlet must be provided with the respective ejb-refs, of course. The HTTP URL of the servlet is provided as a transport property:

org.smartcc.connector.url=http://localhost:8080/HTTPConnector/

The trailing slash is important. The HTTPTransport connects to the servlet with an URL, that is a concatenation of the connector url and the lookup name in the form <org.smartcc.connector.url><lookup> (Thus the lookup will show up as the path info in the HttpServletRequest).

Posted by 퓨전마법사
,