Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

Tuscany Web Application based Integration with Geronimo

1. Introduction

Developing SOA based solutions can be very complex and expensive. Apache Tuscany provides a java implementation of the emerging SCA specifications for SOA. Apache Geronimo is a fully certified Java EE 5 application server runtime. The ability to deploy and run SCA composite applications with Geronimo will bring great value to both projects and communities. In this whitepaper, we will describe a simple web application based integration between Tuscany and Geronimo and walk through how to develop a web application using Apache Tuscany and deploy it to Apache Geronimo.

2. WAR Packaging Scheme

In this scheme, we simply package the application artifcts together with the required tuscany jars and dependencies into standard web application archive (WAR). The WAR can be deployed to the most popular web containers such as Geronimo, Tomcat, Jetty and WebSphere. Some container-specific deployment descriptor files may be added.

A tuscany provided servlet filter (org.apache.tuscany.sca.host.webapp.TuscanyServletFilter) is configured to startup/shutdown the Tuscany runtime when the web application is started or stopped. The tuscany filter is also responsible to dispatch HTTP requests to HTTP-based bindings such as Web Services, JSONRPC and Atom/RSS Feed. Figure 1 below shows how the tuscany servlet filter bridges web application to SCA.

Image Removed

...

As illustrated in Figure 2, there are a few important files or folders in the WAR:

Image Removed

...

2.1 web.xml

Code Block
2xml
titleSample WEB-INF/web.xml
borderStylesolid

<?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>

  <display-name>Apache Tuscany Calculator Web Service Sample</display-name>
    <filter>
        <filter-name>tuscany</filter-name>
        <filter-class>org.apache.tuscany.sca.host.webapp.TuscanyServletFilter</filter-class>
    </filter>

    <filter-mapping>
        <filter-name>tuscany</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

</web-app>

...

2.2 geronimo-web.xml

lightweight infrastructure which enables users to easily implement SOA based solutions or to use
their existing assets and align them with SOA principles which would support a business model that can extend and expand as business needs change.

Apache Tuscany implements SCA specifications that is being standardized at OASIS. Tuscany provides the capabilities to construct, assemble and deploy composite applications using SCA.

This white paper explains how Tuscany integrates with Apache Geronimo, a fully certified Java EE 5 application server runtime, to provide added value to users wanting to develop SOA solutions using Geronimo as a platform. The added values include:

  • Extensibility of component implementation technologies
  • Extensibility of transport and protocol abstractions
  • A notion of cross-application/cross-network assembly and configuration
  • Integration of SCA with existing or new EJB based applications

The following are a set of usage scenarios that both JEE and SCA developers could be interested in.

  • Access SCA composites from Java EE components using JEE programming model
  • Access session beans from SCA service components
  • Expose SCA services as session beans or web services
  • Include Session Beans in a single SCA composition by providing an SCA implementation for session beans.
  • Inject SCA service references to web components to enable Web 2.0
  • Expose enterprise applications into an SCA domain what does this mean?
  • Use recursive SCA assembly in enterprise applications

In this whitepaper, we will describe an initial step taken to integrate Tuscany and Geronimo. It is assumed that you are familiar with Geronimo and Tuscany SCA. Here is the link to SCA user doc .

2. Staged Approach for Tuscany/Geronimo Integration

We had proposed to stage the Tuscany/Geronimo integration on the Geronimo/Tuscany mailing lists. Here is a summary of the basic ideas that were discussed.

  • Stage 1: Deploy tuscany runtime together with the application artifacts as a JEE web application
    With this approach, we can develop composite applications using SCA programming model to assemble a few components, access existing web services or EJB session beans and expose SCA component services over various protocols such as Web Services, JSONRPC, Feed (ATOM and RSS). The web components such as Servlet, JSP can talk to the SCA aassembly. The SCA assembly can talk to existing services and can provide services for JEE programs to consume. can the word composite application be used instead of sca assembly?
  • Stage 2: Integrate tuscany runtime as a plugin for Geronimo
    With this approach, SCA applications can be deployed to Geronimo via a Tuscany plugin. Geronimo can then manage/run the SCA composites. The Tuscany plugin also interacts with other containers in the Geronimo assembly such as Tomcat/Jetty, OpenEJB, ActiveMQ to provide various binding support for SCA services what does this mean?. The plugin could integrate with the QoSs such as Transaction and Security provided by Geronimo to support SCA intents/policies.
  • Stage 3: Enable Geronimo JEE to support SCA composites which include JEE constructs
    The main objective to support the SCA JEE integration spec: SCA Java EE Integration Specification
    With the SCA-enabled JEE, the application developers can use both the SCA and JEE programming model. Both SCA and JEE artifacts can participate in the assembly and be wired against each other in the SCA domain.

Stage 1 is now available in release 1.2 of Tuscany.

An initial prototype of stage 2 has been available in Tuscany since SCA Java 1.1-incubating release. Much more work is needed to re-align the plug-in to the latest release of Tuscany and to complete the work. Contributions are very welcome.

2. Set up Environment

Put links to SCA and Geronimo download. Which versions are needed.

3. Web Application based Tuscany/Geronimo - A "Shallow Integration"

Here we will cover the first step in integrating Tuscany with Geronimo which is running Tuscany as a webapp on top of Geronimo. This is now available in release 1.2 of Tuscany that can be downloaded from put link.

In this scheme,an SCA composite crated with Tuscany is packaged into a web applications archive (WAR) while including application artifacts and tuscany jars and dependencies. The WAR can be deployed to Geronimo or to other web containers such as Tomcat, Jetty and WebSphere. Some container-specific deployment descriptor files may be added. PLEASE CLARIFY

A tuscany provided servlet filter (org.apache.tuscany.sca.host.webapp.TuscanyServletFilter) is configured to startup/shutdown the Tuscany runtime when the web application is started or stopped. The tuscany filter is also responsible to dispatch HTTP requests to HTTP-based bindings such as Web Services, JSONRPC and Atom/RSS Feed. Figure 1 below shows how the tuscany servlet filter bridges web application to SCA.

Image Added

Center

Figure 1. Tuscany Webapp

As illustrated in Figure 2, there are a few important files or folders in the WAR:

Image Added

Center

Figure 2. Sample WAR

Anchor
web.xml
web.xml

2.1 web.xml

As shown below, we configure the web.xml with a Tuscany servlet filter which is responsible to dispatch HTTP requests to corresponding SCA service binding listeners.

Code Block
2xml
titleSample WEB-INF/web.xml
borderStylesolid

<?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>

  <display-name>Apache Tuscany Calculator Web Service Sample</display-name>
    <filter>
        <filter-name>tuscany</filter-name>
        <filter-class>org.apache.tuscany.sca.host.webapp.TuscanyServletFilter</filter-class>
    </filter>

    <filter-mapping>
        <filter-name>tuscany</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

The most important setting in the geronimo-web.xml is inverse-classloading which ensures the tuscany and its dependency classes will be loaded from the WEB-INF/lib. It creates an isolated environment for the tuscany runtime without being interfered by other jars shipped by Geronimo (such as axis2).

Code Block
2xml
titleSample WEB-INF/geronimo-web.xml
borderStylesolid

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://geronimo.apache.org/xml/ns/j2ee/web-2.0"
    xmlns:d="http://geronimo.apache.org/xml/ns/deployment-1.2">
    <d:environment>
        <d:moduleId>
            <d:groupId>org.apache.tuscany.sca</d:groupId>
            <d:artifactId>sample-calculator-ws-webapp</d:artifactId>
            <d:version>1.2-incubating-SNAPSHOT</d:version>
            <d:type>war</d:type>
        </d:moduleId>
        <d:inverse-classloading />
    </d:environment>
</web-app>

Anchor
scageronimo-contributionweb.xmlsca
geronimo-contributionweb.xml

2.

...

2 geronimo-

...

web.xml

META-INF/sca-contribution.xml defines the deployable composites for the given SCA contribution (the WAR in the webapp case). Tuscany servlet filter will bootstrap the SCA domain and deploy these composites.

AnchorMETA-INF/sca-contribution.xmlMETA-INF/sca-contribution.xmlThe most important setting in the geronimo-web.xml is inverse-classloading which ensures the tuscany and its dependency classes will be loaded from the WEB-INF/lib. It creates an isolated environment for the tuscany runtime without being interfered by other jars shipped by Geronimo (such as axis2).

Code Block
2xml
titleMETASample WEB-INF/calculatorgeronimo-web.compositexml
borderStylesolid
<?xml version="1.0" encoding="UTF-8"?>
<contribution<web-app xmlns="http://wwwgeronimo.osoaapache.org/xml/xmlnsns/scaj2ee/1web-2.0"
              targetNamespacexmlns:d="http://sample"geronimo.apache.org/xml/ns/deployment-1.2">
    <d:environment>
        <d:moduleId>
    xmlns:sample="http://sample">
   <deployable composite="sample:Calculator"/>
</contribution>

...

Code Block
2xml
titleCalculator.composite
borderStylesolid

<?xml version="1.0" encoding="UTF-8"?>
<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"     <d:groupId>org.apache.tuscany.sca</d:groupId>
            <d:artifactId>sample-calculator-ws-webapp</d:artifactId>
           targetNamespace="http://sample" <d:version>1.2-incubating-SNAPSHOT</d:version>
           xmlns:sample="http://sample" <d:type>war</d:type>
        </d:moduleId>
   name="Calculator">

    <component name="CalculatorServiceComponent">
		<implementation.java class="calculator.CalculatorServiceImpl"     <d:inverse-classloading />
    </d:environment>
</web-app>

Anchor
sample-scenario
sample-scenario

3. The sample scenario

We will use a Tuscany sample called calcualtor to demonstrate how the Geronimo/Tuscany integration using web application approach works. You can find the calculatr sample in Tuscany svn repo.

3.1 SCA composites

Below is the picture for the calculator sample and the description of SCA composite file.

Image Added

 
The  Calculator.composite is one such deployable sca composite and is defined as follows.

Anchor
Calculator.composite
Calculator.composite

Code Block
2xml
titleCalculator.composite
borderStylesolid

<?xml version="1.0" encoding="UTF-8"?>
<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
           targetNamespace="http://sample"    <reference name="addService" >
           <interface.java interface="calculator.AddService" />
            <binding.ws uri="http://localhost:8080/sample-calculator-ws-webapp/AddServiceComponent"/>
        </reference>
        <reference name="subtractService" target="SubtractServiceComponent"></reference>
        <reference name="multiplyService" target="MultiplyServiceComponent"></reference>
        <reference name="divideService" target="DivideServiceComponent"></reference>
    </component>

    <component name="AddServiceComponent">
        <implementation.java class="calculator.AddServiceImpl"/>   xmlns:sample="http://sample"
        <service   name="AddServiceCalculator">

    <component name="CalculatorServiceComponent">
		<implementation.java class="calculator.CalculatorServiceImpl"/>
        <reference name="addService" >
           <interface.java interface="calculator.AddService" />
            <binding.ws uri="http://localhost:8080/sample-calculator-ws-webapp/AddServiceComponent"/>
        </service>reference>
    </component>

    <component<reference name="SubtractServiceComponent">subtractService" target="SubtractServiceComponent"></reference>
        <reference name="multiplyService" target="MultiplyServiceComponent"></reference>
        <implementation.java class="calculator.SubtractServiceImpl"/><reference name="divideService" target="DivideServiceComponent"></reference>
    </component>

    <component name="MultiplyServiceComponentAddServiceComponent">
        <implementation.java class="calculator.MultiplyServiceImplAddServiceImpl"/>
    </component>

    <component<service name="DivideServiceComponentAddService">
        <implementation     <interface.java classinterface="calculator.DivideServiceImpl"AddService" />
            <binding.ws/>
        </component>

service>
    </composite>

3. Devloping a Tuscany web application for Geronimo using Maven and Eclipse

3.1 Create an empty maven project for your web application

Code Block

mvn archetype:generate

Select 18: internal -> maven-archetype-webapp (A simple Java web application) and provide the groupId/artifactId/version and package name.

You can use the calculator-ws-webapp sample as a template to configure the pom.xml.

Code Block

mvn eclipse:eclipse

3.2 Import the project into Eclipse

In Eclipse, following the menu: File --> Import --> General --> Exising Projects into Workspace.

Image Removed

4. Configure the maven pom.xml to generate web.xml and geronimo-web.xml automatically

Tuscany provides a maven which can generate the WEB-INF/web.xml and WEB-IN/geronimo-web.xml automatically as part of the maven build. The following xml snippet shows
the usage.

Code Block
xmlxml

<build>
    <plugins>
    <!-- Generate web-xml and geronimo deployment descriptor --component>

    <component name="SubtractServiceComponent">
        <implementation.java class="calculator.SubtractServiceImpl"/>
    </component>

    <component name="MultiplyServiceComponent">
        <implementation.java class="calculator.MultiplyServiceImpl"/>
    </component>

    <component name="DivideServiceComponent">
        <plugin>
            <groupId>org.apache.tuscany.sca</groupId><implementation.java class="calculator.DivideServiceImpl"/>
            <artifactId>tuscany-maven-web-junit</artifactId>
            <version>1.2-incubating-SNAPSHOT</version>
            <executions>
                <execution>
                    <id>generate-web-xml</id>
      </component>

</composite>

Anchor
sca-contribution.xml
sca-contribution.xml

3.2 sca-contribution.xml

META-INF/sca-contribution.xml defines the deployable composites for the given SCA contribution (the WAR in the webapp case). Tuscany servlet filter will bootstrap the SCA domain and deploy these composites.

Anchor
META-INF/sca-contribution.xml
META-INF/sca-contribution.xml

Code Block
2xml
titleMETA-INF/calculator.composite
borderStylesolid

<?xml version="1.0" encoding="UTF-8"?>
<contribution xmlns="http://www.osoa.org/xmlns/sca/1.0"
              <configuration>targetNamespace="http://sample"
                        <geronimo>true</geronimo>xmlns:sample="http://sample">
                    </configuration>
                    <phase>process-resources</phase>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

Test automation with maven

<deployable composite="sample:Calculator"/>
</contribution>

3.3 Web service binding

You can expose a SCA service as a web service or access external web services using SCA.

3.4 Talk to existing stateless session bean using binding.ejb

You can acccess existing stateless session bean using binding.ejb. Here is an example of the composite file.

Code Block
2xml
titlebinding.ejb
borderStylesolid

<binding.ejb uri="corbaname:iiop:1.2@localhost:1050#VegetablesCatalogEJB" /> 
Note
titleConfigure the Session Bean to bind to a CORBA JNDI name

Make sure org.apache.geronimo.configs/openejb-corba-deployer/2.0.2/car is started. Look under System Modules in Geronimo admin console.
Configure the EJB deployment plan: openejb-jar.xml

4. Devloping a Tuscany web application for Geronimo using Maven and Eclipse

4.1 Create an empty maven project for your web application

Code Block

mvn archetype:generate

Select 18: internal -> maven-archetype-webapp (A simple Java web application) and provide the groupId/artifactId/version and package name.

You can use the calculator-ws-webapp sample as a template to configure the pom.xml.

Code Block

mvn eclipse:eclipse

4.2 Import the project into Eclipse

In Eclipse, following the menu: File -> Import -> General --> Exising Projects into Workspace.Image Added

4.3. Configure the maven pom.xml to generate web.xml and geronimo-web.xml automatically

Tuscany provides a maven which can generate the WEB-INF/web.xml and WEB-IN/geronimo-web.xml automatically as part of the maven build. The following xml snippet shows
the usage.

Code Block
xml
xml

<build>
    <plugins>
    <!-- Generate web-xml and geronimo deployment descriptor -->
        <plugin>
Code Block
2xml
titleSample pom.xml
borderStylesolid

<!--
        This profile handles generation of jar/war artifacts to be used in executing tests in a web-container
        -->
        <profile>
            <id>webapp</id>
            <activation>
                <activeByDefault>false</activeByDefault>
            </activation>

            <dependencies>
                <dependency>
	    	    <groupId>org.apache.tuscany.sca</groupId>
	    	    <artifactId>tuscany-host-webapp</artifactId>
	    	    <version>1.2-incubating-SNAPSHOT</version>
                           <scope>runtime</scope>
	    </dependency>
                <dependency>
	    	    <groupId>org.apache.tuscany.sca</groupId>
	    	    <artifactId>tuscany-host-webapp-junit</artifactId>
	    	    <version>1.2-incubating-SNAPSHOT</version>
                    <scope>runtime</scope>
	    	</dependency>
                <dependency>
	    	    <groupId>javax.servlet</groupId>
	    	    <artifactId>servlet-api</artifactId>
	    	    <version>2.3</version>
                    <scope>provided</scope>
	    	</dependency>
	    </dependencies>

            <build>
                <pluginManagement>
                    <plugins>
                        <!-- Skip local junit test cases -->
                        <plugin>
                            <groupId>org.apache.maven.plugins</groupId>
                            <artifactId>maven-surefire-plugin</artifactId>
                            <version>2.3.1</version>
                            <configuration>
                                <skip>true</skip>
                            </configuration>
                        </plugin>
                    </plugins>
                </pluginManagement>

                <plugins>

                    <!-- Generate web-xml -->
                    <plugin>
                        <groupId>org.apache.tuscany.sca</groupId>
                        <artifactId>tuscany-maven-web-junit</artifactId>
                        <version>1.2-incubating-SNAPSHOT</version>
                        <executions>
                            <execution>
                                <id>generate-web-xml</id>
                                <phase>process-resources</phase>
                                <goals>
                                    <goal>generate</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>

                    <!-- Create war and include jUnit test classes -->
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-war-plugin</artifactId>
                        <version>2.0.2</version>
                        <configuration>
                            <primaryArtifact>false</primaryArtifact>
                            <!-- Exclude a few jars to avoid conflicts -->
                            <warSourceExcludes>WEB-INF/lib/tuscany-host-tomcat-*.jar,WEB-INF/lib/tuscany-host-jetty-*.jar,servlet-api-*.jar, WEB-INF/classes/META-INF/sca-contribution*.xml</warSourceExcludes>
                            <webResources>
                                <resource>
                                    <directory>${project.build.directory}/test-classes</directory>
                                    <targetPath>WEB-INF/classes</targetPath>
                                </resource>

                                <resource>
                                    <directory>${project.build.directory}/classes/META-INF</directory>
                                    <includes>
                                        <include>sca-contribution*.xml</include>
                                    </includes>
                                    <targetPath>META-INF</targetPath>
                                </resource>

                                <!-- Add the junit -->
                                <resource>
                                    <directory>${settings.localRepository}/junit/junit/4.2</directory>
                                    <includes>
                                        <include>junit-4.2.jar</include>
                                    </includes>
                                    <targetPath>WEB-INF/lib</targetPath>
                                </resource>

                            </webResources>
                        </configuration>
                        <executions>
                            <execution>
                                <phase>package</phase>
                                <goals>
                                    <goal>war</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <profile>
            <id>geronimo</id>
            <activation>
                <activeByDefault>false</activeByDefault>
            </activation>
            <properties>
                <http.port>8080</http.port>
                <http.base>http://127.0.0.1:${http.port}</http.base>
                <geronimo.home>${env.GERONIMO_HOME}</geronimo.home>
            </properties>

            <build>
                <plugins>
                    <!-- Generate web-xml and geronimo deployment descriptor -->
                    <plugin>
                        <groupId>org.apache.tuscany.sca</groupId>
                        <artifactId>tuscany-maven-web-junit</artifactId>
                        <version>1.2-incubating-SNAPSHOT</version>
                        <executions>
                            <execution>
                                <id>generate-web-xml</id>
                                <configuration>
                                    <geronimo>true</geronimo>
                                </configuration>
                                <phase>process-resources</phase>
                                <goals>
                                    <goal>generate</goal>
                                </goals>
                            </execution>
                            <execution>
                                <id>web-junit-test</id>
                                <configuration>
                                    <url>${http.base}/${project.build.finalName}/junit?op=runAll</url>
                                </configuration>
                                <phase>integration-test</phase>
                                <goals>
                                    <goal>test</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>

                    <plugin>
                        <groupId>org.apache.geronimo.plugins</groupId>
                        <artifactId>geronimo-maven-plugin</artifactId>
                        <version>2.0.2</version>
                        <configuration>
                            <geronimoHome>${geronimo.home}</geronimoHome>
                        </configuration>
                        <executions>
                            <execution>
                                <id>start-container</id>
                                <phase>pre-integration-test</phase>
                                <goals>
                                    <goal>start</goal>
                                </goals>
                                <configuration>
                                    <background>true</background>
                                </configuration>
                            </execution>
                            <execution>
                                <id>deploy-war</id>
                                <phase>pre-integration-test</phase>
                                <goals>
                                    <goal>deploy</goal>
                                </goals>
                                <configuration>
                                    <moduleArchive>${project.build.directory}/${project.build.finalName}.war</moduleArchive>
                                </configuration>
                            </execution>
                            <execution>
                                <id>undeploy-war</id>
                                <phase>post-integration-test</phase>
                                <goals>
                                    <goal>undeploy</goal>
                                </goals>
                                <configuration>
                                    <moduleId>${groupId}/${artifactId}/${version}/war</moduleId>
                                </configuration>
                            </execution>
                            <execution>
                                <id>stop-container</id>
                                <phase>post-integration-test</phase>
                                <goals>
                                    <goal>stop</goal>
                    <groupId>org.apache.tuscany.sca</groupId>
            </goals><artifactId>tuscany-maven-web-junit</artifactId>
            <version>1.2-incubating-SNAPSHOT</version>
            <executions>
        <configuration>
        <execution>
                    <id>generate-web-xml</id>
        <username>system</username>
            <configuration>
                        <password>manager<<geronimo>true</password>geronimo>
                    </configuration>
            </configuration>
        <phase>process-resources</phase>
                    </execution><goals>
                        <<goal>generate</executions>goal>
                    </plugin>goals>
                </plugins>execution>
            </build>executions>
        </profile>

...

plugin>
    </plugins>
</build>

5. Test automation with maven

Tuscany has a suite of tests called itests. We have modified the tests to enable running of web applications as part of the test suite.

Automation of itests in web applications

6. Next steps

Tuscany Geronimo Integration Next Steps