Commit 874ff960 authored by Philippe Merle's avatar Philippe Merle
Browse files

Added two examples showing how to package an SCA composite into a WAR:

* server-war/ packages the counter server plus the FraSCAti Runtime Assembly Factory
* server-explorer-war/ packages the counter server plus FraSCAti Explorer
  when the web server starts the war, the FraSCAti Explorer window appears on the
  web server machine allowing one to introspect and reconfigure the SCA application.
These wars were tested and work well with Jetty and Tomcat 5.5.28.

Added a FraSCAti Explorer plugin to call methods of the CounterService interface.

Tests and feedbacks are welcome.
parent 1aa6fd2e
/***
* OW2 FraSCAti Examples: RESTful Counter
* Copyright (C) 2009 INRIA, USTL
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Contact: frascati@ow2.org
*
* Author: Philippe Merle
*
* Contributor(s):
*
*/
package org.ow2.frascati.examples.counter.explorer;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JPanel;
import org.objectweb.util.explorer.api.TreeView;
import org.ow2.frascati.examples.counter.api.CounterService;
import org.ow2.frascati.explorer.gui.AbstractSelectionPanel;
/**
* Is the FraSCAti Explorer plugin to interact with {@link CounterService} instances.
*
* @author Philippe Merle
*/
@SuppressWarnings("serial")
public class CounterServicePanel extends AbstractSelectionPanel<CounterService> {
/**
* The label displaying the current value of the selected counter.
*/
private JLabel valueLabel;
/**
* The default constructor creates the panel.
*/
public CounterServicePanel() {
super();
this.setLayout(new GridLayout(4, 1));
JPanel panel1 = new JPanel();
this.add(panel1);
panel1.add(new JLabel("Current counter value: "));
valueLabel = new JLabel();
panel1.add(valueLabel);
JPanel panel2 = new JPanel();
this.add(panel2);
JButton incrementButton = new JButton("Increment");
panel2.add(incrementButton);
panel2.add(new JLabel("with: "));
final JTextField incrementField = new JTextField(5);
panel2.add(incrementField);
incrementButton.addActionListener( new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
// invoke the counter service.
getSelection().increment(
Integer.parseInt(incrementField.getText())
);
// refresh the value of the counter.
refreshValueLabel();
} catch(NumberFormatException nfe) {
throw new Error(nfe);
}
}
}
);
JPanel panel3 = new JPanel();
this.add(panel3);
JButton decrementButton = new JButton("Decrement");
panel3.add(decrementButton);
panel3.add(new JLabel("with: "));
final JTextField decrementField = new JTextField(5);
panel3.add(decrementField);
decrementButton.addActionListener( new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
// invoke the counter service.
getSelection().decrement(
Integer.parseInt(decrementField.getText())
);
// refresh the value of the counter.
refreshValueLabel();
} catch(NumberFormatException nfe) {
throw new Error(nfe);
}
}
}
);
JPanel panel4 = new JPanel();
this.add(panel4);
JButton resetButton = new JButton("Reset the counter value");
panel4.add(resetButton);
resetButton.addActionListener( new ActionListener() {
public void actionPerformed(ActionEvent e) {
// invoke the counter service.
getSelection().resetIt();
// refresh the value of the counter.
refreshValueLabel();
}
}
);
}
protected void refreshValueLabel() {
// display the current value of the counter.
valueLabel.setText(String.valueOf(this.getSelection().getValue()));
}
/**
* (non-Javadoc)
* @see org.objectweb.util.explorer.api.Panel#selected(org.objectweb.util.explorer.api.TreeView)
*/
@Override
public void selected(TreeView treeView) {
// this sets the counter service returned by this.getSelection().
super.selected(treeView);
// refresh the value of the counter.
refreshValueLabel();
}
}
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!--
* ====================================================================
*
* OW2 FraSCAti Examples: RESTful Counter
* Copyright (C) 2009 INRIA, USTL
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*
* Contact: frascati@ow2.org
*
* Author: Philippe Merle
*
* Contributor(s):
* ====================================================================
-->
<explorer>
<!-- ================================================================= -->
<!-- FraSCAti Explorer plugins for this example. -->
<!-- ================================================================= -->
<node type-name="org.ow2.frascati.examples.counter.api.CounterService">
<panel>
<code>org.ow2.frascati.examples.counter.explorer.CounterServicePanel</code>
</panel>
</node>
</explorer>
\ No newline at end of file
......@@ -22,12 +22,12 @@
*
* Author: Nicolas Dolet
*
* Contributor(s):
* Contributor(s): Philippe Merle
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.ow2.frascati.examples</groupId>
......@@ -46,5 +46,7 @@
<modules>
<module>client</module>
<module>server</module>
<module>server-war</module>
<module>server-explorer-war</module>
</modules>
</project>
============================================================================
OW2 FraSCAti Examples: RESTful Counter Web Application
Copyright (C) 2009 INRIA, USTL
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Contact: frascati@ow2.org
Author: Philippe Merle
Contributor:
============================================================================
FraSCAti RESTful Counter Web Application with FraSCAti Explorer:
----------------------------------------------------------------
This example shows how to package a RESTful service (CounterService) into a WAR
and then to deploy it on a Web Application Server like Jetty, Tomcat, JBoss,
Geronimo, JOnAS, etc.
Compilation with Maven:
-----------------------
mvn install
Execution with Maven:
---------------------
mvn jetty:run
This command starts a standalone Jetty server on port 8080. This server loads
the FraSCAti RESTful Counter Web Application on the context path '/counter-rest'.
This war deploys the FraSCAti Explorer Servlet where the SCA composite
'counter-web-application' is launched.
Deploying the WAR on a Web Application server:
----------------------------------------------
Install target/counter-server-explorer-web-application.war on your favorite
Web Application server, e.g., Jetty, Tomcat, JBoss, Geronimo, etc.
For instance, for Apache Tomcat:
* copy the war to the Tomcat webapps directory:
cp target/counter-server-explorer-web-application.war $CATALINA_HOME/webapps/counter-rest.war
* Use the Tomcat Manager page to start the war.
For other Web servers, please refer to the documentation of your favorite server.
Exploring the deployed SCA composite:
-------------------------------------
When the war is deployed then FraSCAti Explorer is launched. So you could
introspect and reconfigure the RESTful Counter composite as you want to.
Using the RESTful Counter from a client Web browser:
----------------------------------------------------
Open your favorite Web browser and go to:
* http://localhost:8080/counter-rest/ to load the HTML page allowing to interact
with the SCA RESTful Counter service.
* http://localhost:8080/counter-rest/resources to see the list of exported RESTful resources.
* http://localhost:8080/counter-rest/resources/counter to access to the
RESTful resource exposing the current value of the counter.
* http://localhost:8080/counter-rest/resources/counter?_wadl to obtain the
WADL describing the RESTful Counter service.
Interesting files to read:
--------------------------
* pom.xml contains the Maven process to build the war and start the Jetty server.
* src/main/resources/counter-web-application.composite contains the SCA composite
deployed into the Web Application server.
* src/main/webapp/WEB-INF/web.xml contains the configuration of the RESTful Counter
Web Application.
* src/main/webapp/index.html is the HTML page accessible by http://localhost:8080/counter-rest/
Let's note that the implementation of the RESTful Counter is available in the directory ../server/
<?xml version="1.0"?>
<!--
* OW2 FraSCAti Examples: RESTful Counter Web Application
*
* Copyright (c) 2009 INRIA
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<!-- =================== -->
<!-- General Information -->
<!-- =================== -->
<groupId>org.ow2.frascati.examples</groupId>
<artifactId>counter-server-explorer-web-application</artifactId>
<version>1.1-SNAPSHOT</version>
<packaging>war</packaging>
<parent>
<groupId>org.ow2.frascati.examples</groupId>
<artifactId>counter-parent</artifactId>
<version>1.1-SNAPSHOT</version>
</parent>
<name>OW2 FraSCAti Examples: RESTful Counter Web Application with FraSCAti Explorer</name>
<url>http://frascati.ow2.org</url>
<inceptionYear>2009</inceptionYear>
<developers>
<developer>
<id>merle</id>
<name>Philippe Merle</name>
<email>Philippe.Merle@inria.fr</email>
<organization>INRIA</organization>
<organizationUrl>http://www.inria.fr</organizationUrl>
<roles>
<role>Architect</role>
<role>Developer</role>
</roles>
</developer>
</developers>
<licenses>
<license>
<name>The GNU Lesser General Public License, Version 2.1</name>
<url>http://www.gnu.org/licenses/lgpl-2.1.html</url>
</license>
</licenses>
<!-- ==========-->
<!-- Reporting -->
<!-- ========= -->
<!-- ============ -->
<!-- Dependencies -->
<!-- ============ -->
<dependencies>
<!-- Include in the war the implementation of the counter server. -->
<dependency>
<groupId>org.ow2.frascati.examples</groupId>
<artifactId>counter-server</artifactId>
<version>${project.version}</version>
</dependency>
<!-- Include in the war the FraSCAti Explorer. -->
<dependency>
<groupId>org.ow2.frascati</groupId>
<artifactId>frascati-explorer</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<!-- ======= -->
<!-- Build -->
<!-- ======= -->
<build>
<defaultGoal>war:war</defaultGoal>
<plugins>
<!-- Build the Web Application aRchive. -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.0</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
</manifest>
</archive>
</configuration>
</plugin>
<!-- type 'mvn jetty:run' to launch this war with Jetty. -->
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<configuration>
<scanIntervalSeconds>10</scanIntervalSeconds>
<!-- Here is the path where the war is deployed. -->
<contextPath>/counter-rest</contextPath>
<connectors>
<connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
<!-- Here is the port where Jetty is deployed. -->
<port>8080</port>
<maxIdleTime>60000</maxIdleTime>
</connector>
</connectors>
</configuration>
</plugin>
</plugins>
</build>
</project>
<?xml version="1.0" encoding="ISO-8859-15"?>
<!-- OW2 FraSCAti Examples: RESTful Counter Web Application -->
<!-- Copyright (C) 2009 INRIA, USTL -->
<!-- -->
<!-- This library is free software; you can redistribute it and/or -->
<!-- modify it under the terms of the GNU Lesser General Public -->
<!-- License as published by the Free Software Foundation; either -->
<!-- version 2 of the License, or (at your option) any later version. -->
<!-- -->
<!-- This library is distributed in the hope that it will be useful, -->
<!-- but WITHOUT ANY WARRANTY; without even the implied warranty of -->
<!-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -->
<!-- Lesser General Public License for more details. -->
<!-- -->
<!-- You should have received a copy of the GNU Lesser General Public -->
<!-- License along with this library; if not, write to the Free Software -->
<!-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -->
<!-- -->
<!-- Contact: frascati@ow2.org -->
<!-- -->
<!-- Author: Philippe Merle -->
<!-- -->
<!-- Contributor(s): -->
<composite name="counter-web-application"
xmlns="http://www.osoa.org/xmlns/sca/1.0"
xmlns:frascati="http://frascati.ow2.org/xmlns/sca/1.1"
targetNamespace="http://frascati.ow2.org/counter">
<component name="server">
<implementation.java class="org.ow2.frascati.examples.counter.lib.CounterServiceImpl" />
<service name="counter">
<!-- Let's note that the URI of the following binding does not contain the address -->
<!-- of the web server and the path to the web application. These are automatically -->
<!-- added by Apache CXF according to the configuration of the web server and -->
<!-- the web application where this composite is launched. -->
<frascati:binding.rest uri="/counter"/>
</service>
</component>
</composite>
<?xml version="1.0" encoding="UTF-8"?>
<!-- OW2 FraSCAti Examples: RESTful Counter Web Application -->
<!-- Copyright (C) 2009 INRIA, USTL -->
<!-- -->
<!-- This library is free software; you can redistribute it and/or -->
<!-- modify it under the terms of the GNU Lesser General Public -->
<!-- License as published by the Free Software Foundation; either -->
<!-- version 2 of the License, or (at your option) any later version. -->
<!-- -->
<!-- This library is distributed in the hope that it will be useful, -->
<!-- but WITHOUT ANY WARRANTY; without even the implied warranty of -->
<!-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -->
<!-- Lesser General Public License for more details. -->
<!-- -->
<!-- You should have received a copy of the GNU Lesser General Public -->
<!-- License along with this library; if not, write to the Free Software -->
<!-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -->
<!-- -->
<!-- Contact: frascati@ow2.org -->
<!-- -->
<!-- Author: Philippe Merle -->
<!-- -->
<!-- Contributor: -->
<!-- -->
<!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 id="OW2-FraSCAti-Examples-RESTful-Counter-Explorer-Web-Application" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>OW2 FraSCAti RESTful Counter Web Application with FraSCAti Explorer</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<!-- OW2 FraSCAti Explorer Servlet -->
<servlet>
<servlet-name>FraSCAtiExplorerServlet</servlet-name>
<display-name>OW2 FraSCAti Explorer Servlet</display-name>
<servlet-class>org.ow2.frascati.explorer.servlet.FraSCAtiExplorerServlet</servlet-class>
<init-param>
<param-name>composite</param-name>
<!-- Here is the list of SCA composites to start. -->
<param-value>counter-web-application</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>FraSCAtiExplorerServlet</servlet-name>
<!-- Here is the url pattern where SCA WS and RESTful bindings are exposed. -->
<url-pattern>/resources/*</url-pattern>
</servlet-mapping>
</web-app>
<!-- OW2 FraSCAti Examples: RESTful Counter Web Application -->
<!-- Copyright (C) 2009 INRIA, USTL -->
<!-- -->
<!-- This library is free software; you can redistribute it and/or -->
<!-- modify it under the terms of the GNU Lesser General Public -->
<!-- License as published by the Free Software Foundation; either -->
<!-- version 2 of the License, or (at your option) any later version. -->
<!-- -->
<!-- This library is distributed in the hope that it will be useful, -->
<!-- but WITHOUT ANY WARRANTY; without even the implied warranty of -->
<!-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -->
<!-- Lesser General Public License for more details. -->
<!-- -->
<!-- You should have received a copy of the GNU Lesser General Public -->
<!-- License along with this library; if not, write to the Free Software -->
<!-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -->
<!-- -->
<!-- Contact: frascati@ow2.org -->
<!-- -->
<!-- Author: Philippe Merle -->
<!-- -->
<!-- Contributor: -->
<!-- -->
<html>
<head>
<title>OW2 FraSCAti Examples: RESTful Counter Web Application with FraSCAti Explorer</title>
</head>
<body onload="updateCounterValueField()">
<script language="JavaScript">
function updateCounterValue() {
try {
var xhr = new XMLHttpRequest();
xhr.open("GET", "resources/counter", false);
xhr.send(null);
document.counter.value.value = xhr.responseText
} catch(e) {
alert(e);
}
}
function submitFormUpdateCounterValue(form) {
try {
form.submit();
updateCounterValue();
} catch(e) {
alert(e);
}
}
</script>
<form name="counter">
Click on the following text input to update the counter value:
<input type="text" name="value" onfocus="updateCounterValue()">
</form>
<form action="resources/counter/incr" method="post">