Tuscany Hello World Web Sample

Overview

The Tuscany hello world web sample shows using the Tuscany SCA runtime in a Tomcat environment being accessed from a JSP page that implements the classic introductory hello world example.

Location

This sample is located  in the samples\sca\helloworldweb directory.

Setup

Set up your server as described in the Tomcat Setup.   If you are not using the pre-configured Tomcat server from the binary distribution, you will need to add sample-helloworldweb-incubating-M1.war to your tomcat's webapp directory.

Running

Once you've started your web server, use your browse to view the following URL: http://localhost:8080/sample-helloworldweb/
You should see a form you can supply your name and a submit button.  Once you submit the form the JSP page calls a Java class that gets the CurrentModuleContext and locates the SCA component to execute the greeting service.  Note, unlike the a J2SE in a Tomcat environment the Tuscany runtime is automatically initialized and running.

Results

The page should be updated with the greeting displayed below the form.

Code Overview

The source files are physically organized as shown below:
src
+---main
+---java
¦ +---helloworld
¦ HelloWorldImpl.java
¦ HelloWorldService.java
¦
+---resources
¦ sca.module
¦
+---webapp
¦ HelloWorldWeb.jsp
¦
¦
+---WEB-INF
web.xml



 

sca.module Defines the SCA module and component. Defines for the HelloWorldServiceComponent component and the Java class that implements that component
HelloWorldService.java Defines the Java interface implemented by the component.
HelloWorldImpl.java Implements the SCA component. Uses the SCA service annotation tag on the class to show what SCA interface is being implemented.
HelloWorldWeb.jsp Handles Web form input.. Obtains the module context which was defined by the sca.module file. From the module context locates the HelloWorldServiceComponent and then calls  the getGreetings method to invoke the component. and formats  returned results.
web.xml Standard J2EE web application's web.xml