Commit 6cd20d5b authored by Nicolas Dolet's avatar Nicolas Dolet

New Web service (with client and server) example.

parent b08b2e63
============================================================================
OW2 FraSCAti Examples: Calculator
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: Nicolas Dolet
============================================================================
FraSCAti Calculator example:
------------------------------
This example shows how to expose and how to consume a web service with FraSCAti.
This module gathers the server and the client.
For running the example, open two terminals (for the server and for the client).
Compilation with Maven: (for the server and the client)
-----------------------
mvn install
Execution with Maven: (for the server and the client)
---------------------
mvn -Prun
Compilation and execution with the FraSCAti scripts: (for the server)
----------------------------------------------------
frascati compile src calculator-server
frascati run soap-calc -libpath calculator-server.jar
Compilation and execution with the FraSCAti scripts: (for the client)
----------------------------------------------------
frascati wsdl2java -f src/main/wsdl/Calculator.wsdl -o src/main/java
frascati compile src calculator-client
frascati run calc-client -libpath calculator-client.jar -s calc -m add -p 1 2
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java"/>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"/>
<classpathentry kind="src" path="target/generated/src/main/java"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>calc-client</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.maven.ide.eclipse.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.maven.ide.eclipse.maven2Nature</nature>
</natures>
</projectDescription>
#Thu Jun 04 01:10:39 CEST 2009
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.compliance=1.5
org.eclipse.jdt.core.compiler.source=1.5
#Thu Jun 04 01:10:37 CEST 2009
activeProfiles=
eclipse.preferences.version=1
fullBuildGoals=process-test-resources
includeModules=false
resolveWorkspaceProjects=true
resourceFilterGoals=process-resources resources\:testResources
skipCompilerPlugin=true
version=1
<?xml version="1.0"?>
<!--
* OW2 FraSCAti Examples: Calculator Client
*
* 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: Nicolas Dolet
*
* 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>calculator-client</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>OW2 FraSCAti Examples: Calculator Client</name>
<parent>
<groupId>org.ow2.frascati.examples</groupId>
<artifactId>calculator-parent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<properties>
<wsdl.file>Calculator.wsdl</wsdl.file>
<composite.file>calc-client</composite.file>
<service.name>calc</service.name>
<method.name>add</method.name>
<method.params>1 2</method.params>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>${cxf.version}</version>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.ow2.frascati.factory</groupId>
<artifactId>frascati-factory-tools</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
/***
* OW2 FraSCAti Examples: Soap Calculator Client
* 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: Nicolas Dolet
*
* Contributor(s):
*/
package org.ow2.frascati.examples.soapcalc.api;
import org.osoa.sca.annotations.Service;
/**
* Interface for the FraSCAti calculator service.
*/
@Service
public interface Calculator {
public int add(String i, String j);
public int sub(String i, String j);
public int mult(String i, String j);
public double div(String i, String j);
}
/***
* OW2 FraSCAti Examples: Soap Calculator Client
* 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: Nicolas Dolet
*
* Contributor(s): Philippe Merle
*/
package org.ow2.frascati.examples.soapcalc.lib;
import org.osoa.sca.annotations.Reference;
import org.ow2.frascati.examples.soapcalc.api.CalcService;
import org.ow2.frascati.examples.soapcalc.api.CalcServicePortType;
import org.ow2.frascati.examples.soapcalc.api.Calculator;
/**
* SCA Java Component implementation using the FraSCAti calculator web service
*/
public class Client
implements Calculator {
@Reference
protected CalcServicePortType calcservice;
// --------------------------------------------------------------------------
// Implementation of the Calculator interface
// --------------------------------------------------------------------------
public int add(String i, String j) {
return calcservice.add(new Integer(i).intValue(), new Integer(j).intValue());
}
public int sub(String i, String j) {
return calcservice.sub(new Integer(i).intValue(), new Integer(j).intValue());
}
public int mult(String i, String j) {
return calcservice.mult(new Integer(i).intValue(), new Integer(j).intValue());
}
public double div(String i, String j) {
return calcservice.div(new Integer(i).intValue(), new Integer(j).intValue());
}
}
<?xml version="1.0" encoding="ISO-8859-15"?>
<!-- OW2 FraSCAti Examples: Soap Calculator Client -->
<!-- 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: Nicolas Dolet -->
<!-- -->
<!-- Contributor(s): -->
<composite xmlns="http://www.osoa.org/xmlns/sca/1.0" name="calc-client"
targetNamespace="http://frascati.ow2.org/calc-client">
<service name="calc" promote="client/Calculator"/>
<component name="client">
<implementation.java class="org.ow2.frascati.examples.soapcalc.lib.Client" />
<reference name="calcservice">
<binding.ws wsdlElement="http://localhost:8080/services#wsdl.port(CalcService/CalcServicePort)" />
</reference>
</component>
</composite>
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions name="CalcService" targetNamespace="http://api.soapcalc.examples.frascati.ow2.org/" xmlns:ns1="http://schemas.xmlsoap.org/soap/http" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://api.soapcalc.examples.frascati.ow2.org/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<wsdl:types>
<xsd:schema attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://api.soapcalc.examples.frascati.ow2.org/" xmlns:tns="http://api.soapcalc.examples.frascati.ow2.org/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="mult" type="tns:mult"/>
<xsd:complexType name="mult">
<xsd:sequence>
<xsd:element name="arg0" type="xsd:int"/>
<xsd:element name="arg1" type="xsd:int"/>
</xsd:sequence>
</xsd:complexType>
<xsd:element name="multResponse" type="tns:multResponse"/>
<xsd:complexType name="multResponse">
<xsd:sequence>
<xsd:element name="return" type="xsd:int"/>
</xsd:sequence>
</xsd:complexType>
<xsd:element name="div" type="tns:div"/>
<xsd:complexType name="div">
<xsd:sequence>
<xsd:element name="arg0" type="xsd:int"/>
<xsd:element name="arg1" type="xsd:int"/>
</xsd:sequence>
</xsd:complexType>
<xsd:element name="divResponse" type="tns:divResponse"/>
<xsd:complexType name="divResponse">
<xsd:sequence>
<xsd:element name="return" type="xsd:double"/>
</xsd:sequence>
</xsd:complexType>
<xsd:element name="add" type="tns:add"/>
<xsd:complexType name="add">
<xsd:sequence>
<xsd:element name="arg0" type="xsd:int"/>
<xsd:element name="arg1" type="xsd:int"/>
</xsd:sequence>
</xsd:complexType>
<xsd:element name="addResponse" type="tns:addResponse"/>
<xsd:complexType name="addResponse">
<xsd:sequence>
<xsd:element name="return" type="xsd:int"/>
</xsd:sequence>
</xsd:complexType>
<xsd:element name="sub" type="tns:sub"/>
<xsd:complexType name="sub">
<xsd:sequence>
<xsd:element name="arg0" type="xsd:int"/>
<xsd:element name="arg1" type="xsd:int"/>
</xsd:sequence>
</xsd:complexType>
<xsd:element name="subResponse" type="tns:subResponse"/>
<xsd:complexType name="subResponse">
<xsd:sequence>
<xsd:element name="return" type="xsd:int"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
</wsdl:types>
<wsdl:message name="add">
<wsdl:part element="tns:add" name="parameters">
</wsdl:part>
</wsdl:message>
<wsdl:message name="div">
<wsdl:part element="tns:div" name="parameters">
</wsdl:part>
</wsdl:message>
<wsdl:message name="divResponse">
<wsdl:part element="tns:divResponse" name="parameters">
</wsdl:part>
</wsdl:message>
<wsdl:message name="multResponse">
<wsdl:part element="tns:multResponse" name="parameters">
</wsdl:part>
</wsdl:message>
<wsdl:message name="subResponse">
<wsdl:part element="tns:subResponse" name="parameters">
</wsdl:part>
</wsdl:message>
<wsdl:message name="sub">
<wsdl:part element="tns:sub" name="parameters">
</wsdl:part>
</wsdl:message>
<wsdl:message name="mult">
<wsdl:part element="tns:mult" name="parameters">
</wsdl:part>
</wsdl:message>
<wsdl:message name="addResponse">
<wsdl:part element="tns:addResponse" name="parameters">
</wsdl:part>
</wsdl:message>
<wsdl:portType name="CalcServicePortType">
<wsdl:operation name="mult">
<wsdl:input message="tns:mult" name="mult">
</wsdl:input>
<wsdl:output message="tns:multResponse" name="multResponse">
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="div">
<wsdl:input message="tns:div" name="div">
</wsdl:input>
<wsdl:output message="tns:divResponse" name="divResponse">
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="add">
<wsdl:input message="tns:add" name="add">
</wsdl:input>
<wsdl:output message="tns:addResponse" name="addResponse">
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="sub">
<wsdl:input message="tns:sub" name="sub">
</wsdl:input>
<wsdl:output message="tns:subResponse" name="subResponse">
</wsdl:output>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="CalcServiceSoapBinding" type="tns:CalcServicePortType">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="mult">
<soap:operation soapAction="" style="document"/>
<wsdl:input name="mult">
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="multResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="div">
<soap:operation soapAction="" style="document"/>
<wsdl:input name="div">
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="divResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="add">
<soap:operation soapAction="" style="document"/>
<wsdl:input name="add">
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="addResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="sub">
<soap:operation soapAction="" style="document"/>
<wsdl:input name="sub">
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="subResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="CalcService">
<wsdl:port binding="tns:CalcServiceSoapBinding" name="CalcServicePort">
<soap:address location="http://localhost:8080/Calculator"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
<?xml version="1.0"?>
<!--
* OW2 FraSCAti Examples: Calculator
*
* 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: Nicolas Dolet
*
* 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">
<modelVersion>4.0.0</modelVersion>
<groupId>org.ow2.frascati.examples</groupId>
<artifactId>calculator-parent</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>OW2 FraSCAti Examples: Calculator</name>
<parent>
<groupId>org.ow2.frascati.examples</groupId>
<artifactId>ws-parent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<modules>
<module>client</module>
<module>server</module>
</modules>
</project>
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java"/>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>soap-calculator</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.maven.ide.eclipse.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.maven.ide.eclipse.maven2Nature</nature>
</natures>
</projectDescription>
#Mon May 25 17:52:38 CEST 2009
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.compliance=1.5
org.eclipse.jdt.core.compiler.source=1.5
#Mon May 25 17:52:35 CEST 2009
activeProfiles=
eclipse.preferences.version=1
fullBuildGoals=process-test-resources
includeModules=false
resolveWorkspaceProjects=true
resourceFilterGoals=process-resources resources\:testResources
skipCompilerPlugin=true
version=1
<?xml version="1.0"?>
<!--
* OW2 FraSCAti Examples: Calculator Server
*
* 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: Nicolas Dolet
*
* 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>calculator-server</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>OW2 FraSCAti Examples: Calculator Server</name>
<parent>
<groupId>org.ow2.frascati.examples</groupId>
<artifactId>calculator-parent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<properties>
<composite.file>soap-calc</composite.file>
<service.name>''</service.name>
<method.name>''</method.name>
<method.params>''</method.params>
</properties>
<dependencies>
<dependency>
<groupId>org.ow2.frascati.factory</groupId>
<artifactId>frascati-factory-tools</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
/***
* OW2 FraSCAti Examples: Soap Calculator
* 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: Nicolas Dolet
*
* Contributor(s):
*/
package org.ow2.frascati.examples.soapcalc.api;
import javax.jws.WebMethod;
import javax.jws.WebService;
import org.osoa.sca.annotations.Service;
@Service
@WebService
public interface CalcService {
@WebMethod
public int add(int i, int j);
@WebMethod
public int sub(int i, int j);
@WebMethod
public int mult(int i, int j);
@WebMethod
public double div(int i, int j);
}
/***
* OW2 FraSCAti Examples: Soap Calculator
* 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