Version 8

    TODO: Add HTTPS.

     

    NOTE: This wiki is ONLY for EJB2s

     

    Setup

     

    Step 1. Grab a copy of JBoss AS 4.2.x+ or JBoss EAP 4.2.x/4.3.x+ and create a new server configuration (based on /default).

     

    Server Side

     

    Step 2. Within the deploy/ directory of the newly created configuration, create the following folder hierarchy:

     

    deploy/
      unified-http-invoker.sar/
        unified-invoker.war/
          WEB-INF/
        META-INF/

     

    Step 3. Within WEB-INF, create a file called web.xml that will contain the servlet definition that receives requests via HTTP protocol from within a web container and passes it onto the ServletServerInvoker for processing:

     

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE web-app PUBLIC
       "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
       "http://java.sun.com/dtd/web-app_2_3.dtd">
    
    <web-app>
        <servlet>
            <servlet-name>ServerInvokerServlet</servlet-name>
            <description>The ServerInvokerServlet receives requests via HTTP
               protocol from within a web container and passes it onto the
               ServletServerInvoker for processing.
            </description>
            <servlet-class>org.jboss.remoting.transport.servlet.web.ServerInvokerServlet</servlet-class>
            <init-param>
                <param-name>invokerName</param-name>
                <param-value>jboss.remoting:service=invoker,transport=servlet</param-value>
                <description>The servlet server invoker</description>
            </init-param>
            <load-on-startup>1</load-on-startup>
        </servlet>
        <servlet-mapping>
            <servlet-name>ServerInvokerServlet</servlet-name>
            <url-pattern>/ServerInvokerServlet/*</url-pattern>
        </servlet-mapping>
    </web-app>

     

    Step 4. Within META-INF, create a file called jboss-service.xml that will contain the unified invoker MBean that will communicate client and server via the servlet set up above, thus making invocations go through the HTTP layer:

     

    <?xml version="1.0" encoding="UTF-8"?>
    <server>
       <!-- Unified invoker (based on remoting) -->
       <mbean code="org.jboss.invocation.unified.server.UnifiedInvoker"
          name="jboss:service=invoker,type=unified,transport=servlet">
          <depends>jboss:service=TransactionManager</depends>
          <depends>jboss.remoting:service=connector,transport=servlet</depends>
       </mbean>
    
       <mbean code="org.jboss.remoting.transport.Connector"
          name="jboss.remoting:service=connector,transport=servlet"
          display-name="Servlet transport Connector">
          <attribute name="Configuration">
             <config>
                <invoker transport="servlet">
                   <attribute name="dataType" isParam="true">invocation</attribute>
                   <attribute name="marshaller" isParam="true">org.jboss.invocation.unified.marshall.InvocationMarshaller</attribute>
                   <attribute name="unmarshaller" isParam="true">org.jboss.invocation.unified.marshall.InvocationUnMarshaller</attribute>
                   <attribute name="serverBindAddress">${jboss.bind.address}</attribute>
                   <attribute name="serverBindPort">8080</attribute>
                   <attribute name="path">unified-invoker/ServerInvokerServlet</attribute>
                </invoker>
                <handlers>
                   <handler subsystem="invoker">jboss:service=invoker,type=unified,transport=servlet</handler>
                </handlers>
             </config>
          </attribute>      
       </mbean>
    </server>

     

    Deployment Archive

     

    Step 5. Take an SLSB and make it use a the unified invoker with HTTP transport. No changes are necessary to the ejb-jar.xml:

     

    <?xml version="1.0" encoding="UTF-8"?>
    <ejb-jar>
      <enterprise-beans>
          <session>
            <ejb-name>TimeTellerEjbHttp</ejb-name>
            <home>com.acme.ejb2.slsb.TimeTellerHome</home>
            <remote>com.acme.ejb2.slsb.TimeTeller</remote>
            <ejb-class>com.acme.ejb2.slsb.TimeTellerBean</ejb-class>
            <session-type>Stateless</session-type>
            <transaction-type>Container</transaction-type>
          </session>                          
      </enterprise-beans>
    </ejb-jar>

     

    However, in the jboss.xml, make sure the bean is going to use the unified invoker created above, configuring the file to look something like this:

     

    <?xml version="1.0"?>
    <jboss>
      <enterprise-beans>        
         <session>
            <ejb-name>TimeTellerEjbHttp</ejb-name>
            <jndi-name>ejb/TimeTellerEjbHttp</jndi-name>          
            <configuration-name>Unified Http Stateless SessionBean</configuration-name>
         </session>                
      </enterprise-beans>
        
      <invoker-proxy-bindings>
        <invoker-proxy-binding>
          <name>stateless-unified-http-invoker</name>
          <invoker-mbean>jboss:service=invoker,type=unified,transport=servlet</invoker-mbean>
          <proxy-factory>org.jboss.proxy.ejb.ProxyFactory</proxy-factory>
          <proxy-factory-config>
            <client-interceptors>
              <home>
                <interceptor>org.jboss.proxy.ejb.HomeInterceptor</interceptor>
                <interceptor>org.jboss.proxy.SecurityInterceptor</interceptor>
                <interceptor>org.jboss.proxy.TransactionInterceptor</interceptor>
                <interceptor call-by-value="false">org.jboss.invocation.InvokerInterceptor</interceptor>
                <interceptor call-by-value="true">org.jboss.invocation.MarshallingInvokerInterceptor</interceptor>
              </home>
              <bean>
                <interceptor>org.jboss.proxy.ejb.StatelessSessionInterceptor</interceptor>
                <interceptor>org.jboss.proxy.SecurityInterceptor</interceptor>
                <interceptor>org.jboss.proxy.TransactionInterceptor</interceptor>
                <interceptor call-by-value="false">org.jboss.invocation.InvokerInterceptor</interceptor>
                <interceptor call-by-value="true">org.jboss.invocation.MarshallingInvokerInterceptor</interceptor>
              </bean>
            </client-interceptors>
          </proxy-factory-config>
        </invoker-proxy-binding>
      </invoker-proxy-bindings>
        
      <container-configurations>
        <container-configuration extends="Standard Stateless SessionBean">
          <container-name>Unified Http Stateless SessionBean</container-name>
          <invoker-proxy-binding-name>stateless-unified-http-invoker</invoker-proxy-binding-name>
        </container-configuration>            
      </container-configurations>    
    </jboss>

     

    Client Side

     

    Step 6. Call the bean and you'll see invocations going through the HTTP layer.

     

    TimeTellerHome home = (TimeTellerHome)ctx.lookup("ejb/TimeTellerEjbHttp");
    TimeTeller teller = home.create();
    System.out.println(teller.whatsTheTime());

     

    Referenced by: