Commit 38ccb4fa authored by Philippe Merle's avatar Philippe Merle
Browse files

Added a new example illustrating how to invoke an SCA-based Web service from...

Added a new example illustrating how to invoke an SCA-based Web service from an HTML/JavaScript page (i.e., a widget).
parent 8e25d12d
============================================================================
OW2 FraSCAti Examples: HelloWorld Widget
Copyright (C) 2012 Inria, University of Lille 1
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):
============================================================================
HelloWorld Widget:
------------------
This example illustrates how to invoke an SCA-based Web service from
an HTML/JavaScript page (i.e., a widget).
Have a look to src/main/resources/helloworld-widget.composite and
src/main/resources/widget/widget.html to see how the widget is implemented.
Compilation with Maven:
-----------------------
mvn install
Execution with Maven:
---------------------
mvn -Prun
mvn -Pexplorer (with FraSCAti Explorer)
mvn -Pexplorer-fscript (with FraSCAti Explorer and FScript plugin)
mvn -Pfscript-console (with FraSCAti FScript Console)
mvn -Pfscript-console-explorer (with FraSCAti Explorer and FScript Console)
mvn -Pexplorer-jdk6 (with FraSCAti Explorer and JDK6)
mvn -Prun,web (with FraSCAti Web Explorer)
Using the HelloWorld Widget:
----------------------------
Open your favorite Web browser and go to:
* http://localhost:8765/SayHello?wsdl to obtain the WSDL describing the
SayHello Web Service. To invoke this service, use soapUI for instance, or
* http://localhost:8765/SayHelloWidget/widget.html to obtain a dynamic HTML page
allowing to invoke the SayHello Web service.
<?xml version="1.0"?>
<!--
* OW2 FraSCAti Examples: HelloWorld Widget
*
* Copyright (c) 2012 Inria, University of Lille 1
*
* 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):
-->
<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>
<artifactId>helloworld-widget</artifactId>
<packaging>jar</packaging>
<name>OW2 FraSCAti Examples: HelloWorld Widget</name>
<parent>
<artifactId>parent</artifactId>
<groupId>org.ow2.frascati.examples</groupId>
<version>1.5-SNAPSHOT</version>
</parent>
<properties>
<composite.file>helloworld-widget</composite.file>
</properties>
<dependencies>
<dependency>
<groupId>org.ow2.frascati.examples.test</groupId>
<artifactId>frascati-test</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.ow2.frascati</groupId>
<artifactId>frascati-implementation-resource</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.ow2.frascati</groupId>
<artifactId>frascati-binding-http</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.ow2.frascati</groupId>
<artifactId>frascati-binding-ws</artifactId>
<version>${project.version}</version>
</dependency>
<!-- Generate JavaScript client code for Web Services. -->
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-javascript</artifactId>
<version>${cxf.version}</version>
</dependency>
</dependencies>
</project>
/**
* OW2 FraSCAti Examples: HelloWorld Widget
* Copyright (C) 2012 Inria, University of Lille 1
*
* 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.helloworld.widget;
public interface SayHello
{
String sayHello(String msg);
}
/**
* OW2 FraSCAti Examples: HelloWorld Widget
* Copyright (C) 2012 Inria, University of Lille 1
*
* 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.helloworld.widget;
import org.osoa.sca.annotations.Scope;
import org.osoa.sca.annotations.Service;
@Service(SayHello.class)
@Scope("COMPOSITE")
public class SayHelloImpl implements SayHello
{
public final String sayHello(final String msg)
{
return "Hello " + msg + "!";
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!-- OW2 FraSCAti Examples: HelloWorld Widget -->
<!-- Copyright (C) 2012 Inria, University of Lille 1 -->
<!-- -->
<!-- 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 xmlns="http://www.osoa.org/xmlns/sca/1.0"
xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/1.0"
xmlns:web="http://frascati.ow2.org/xmlns/web/1.0"
name="helloworld-widget">
<service name="SayHello" promote="SayHello/SayHello"/>
<component name="SayHello">
<implementation.java class="org.ow2.frascati.examples.helloworld.widget.SayHelloImpl" />
<service name="SayHello">
<binding.ws uri="/SayHello"/>
</service>
</component>
<component name="Widget">
<tuscany:implementation.resource location="widget" />
<service name="Resource">
<tuscany:binding.http uri="/SayHelloWidget"/>
</service>
<!--
<reference name="sayHello" target="SayHello/SayHello">
<binding.ws/>
</reference>
-->
</component>
</composite>
<!-- create an object to talk to the SayHello Web service. -->
var sayHello = new widget_helloworld_examples_frascati_ow2_org__SayHelloPortType_widget_helloworld_examples_frascati_ow2_org__SayHelloPort();
\ No newline at end of file
<!-- OW2 FraSCAti Examples: HelloWorld Widget -->
<!-- Copyright (C) 2012 Inria, University of Lille 1 -->
<!-- -->
<!-- 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): -->
<html>
<head>
<title>OW2 FraSCAti HelloWorld Widget Example</title>
<!-- Following generates and retrieves a JavaScript client for the SayHello Web service. -->
<script type="text/javascript" src="/SayHello?js"></script>
<!-- Following declares the variable 'sayHello' to invoke the SayHello Web service. -->
<script type="text/javascript" src="Widget.js"></script>
<script type="text/javascript">
<!-- This is the function called upon success. -->
function sayHelloResponse(response)
{
document.getElementById('sayHelloResponse').firstChild.nodeValue = response.getReturn();
}
<!-- This is the function called for an error. -->
function sayHelloError(error)
{
alert('error ' + error);
}
<!-- This function is invoked from the button press to run the service. -->
function invokeSayHello(msg)
{
document.getElementById('sayHelloResponse').firstChild.nodeValue = " - pending - ";
sayHello.sayHello(sayHelloResponse, sayHelloError, msg);
}
</script>
</head>
<body>
<h1>OW2 FraSCAti HelloWorld Widget Example</h1>
<form>
<div>
<table>
<tr>
<td>Run sayHello</td>
<td><input type="button" value="invoke" name="sayHello"
onClick="invokeSayHello(this.form.message.value)"></td>
<td><input type="text" value="" name="message"></td>
</tr>
<tr>
<td>sayHello response</td>
<td><span id='sayHelloResponse'>- not yet invoked -</span></td>
</tr>
</table>
</div>
</form>
</body>
</html>
/**
* OW2 FraSCAti Examples: HelloWorld Widget
* Copyright (C) 2012 Inria, University of Lille 1
*
* 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.helloworld.widget.test;
import org.junit.Test;
import org.ow2.frascati.examples.test.FraSCAtiTestCase;
import org.ow2.frascati.examples.helloworld.widget.SayHello;
public class HelloworldTestCase
extends FraSCAtiTestCase
{
@Override
public final String getComposite()
{
return "helloworld-widget";
}
@Test
public final void testService()
{
SayHello sayHello = getService(SayHello.class, "SayHello");
sayHello.sayHello("Philippe");
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment