Commit bc44b766 authored by Christophe Demarey's avatar Christophe Demarey
Browse files

Add a json-rpc example.

parent 15bc3096
============================================================================
OW2 FraSCAti Examples: HelloWorld Web Service
Copyright (C) 2010 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: Christophe Demarey
Contributor:
============================================================================
HelloWorld Json Rpc:
--------------------
This example shows how to expose an SCA service with Json RPC and how to
consume it with an SCA client composite.
Compilation with Maven:
-----------------------
mvn install
Execution with Maven:
---------------------
1) Open a console for the server
cd server
mvn -Prun (standalone execution)
mvn -Pexplorer (with FraSCAti Explorer)
2) Open another console for the client
cd client
mvn -Prun (standalone execution)
mvn -Pexplorer (with FraSCAti Explorer)
Compilation and execution with the FraSCAti script:
---------------------------------------------------
1) Open a console and follow instructions in the 'server' directory
2) Open another console and follow instructions in the 'client' directory
============================================================================
OW2 FraSCAti Examples: HelloWorld Json Rpc
Copyright (C) 2010 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: Christophe Demarey
Contributor:
============================================================================
HelloWorld Json Rpc Client:
---------------------------
This example shows how to consume the Json Rpc service exposed by the
helloworld-jsonrpc-server example.
Compilation with Maven:
-----------------------
mvn install
Execution with Maven:
---------------------
mvn -Prun (standalone execution)
mvn -Pexplorer (with FraSCAti Explorer)
Compilation and execution with the FraSCAti script:
---------------------------------------------------
frascati compile src hello
frascati run helloworld-jsonrpc-client -libpath hello.jar -s r -m run
<?xml version="1.0"?>
<!--
* OW2 FraSCAti Examples: HelloWorld Json Rpc
*
* Copyright (c) 2010 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: Christophe Demarey
*
* 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-jsonrpc-client</artifactId>
<packaging>jar</packaging>
<name>OW2 FraSCAti Examples: HelloWorld Json Rpc Client</name>
<parent>
<groupId>org.ow2.frascati.examples</groupId>
<artifactId>helloworld-jsonrpc-parent</artifactId>
<version>1.3-SNAPSHOT</version>
</parent>
<properties>
<composite.file>helloworld-jsonrpc-client</composite.file>
<service.name>r</service.name>
<method.name>run</method.name>
</properties>
</project>
/***
* OW2 FraSCAti Examples: HelloWorld Web Service
* Copyright (C) 2008-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: Damien Fournier
*
* Contributor(s): Nicolas Dolet
*/
package org.ow2.frascati.examples.helloworld.jsonrpc;
import org.osoa.sca.annotations.Init;
import org.osoa.sca.annotations.Reference;
public class ClientImpl implements Runnable {
// --------------------------------------------------------------------------
// SCA Reference
// --------------------------------------------------------------------------
private HelloService s;
@Reference
public void setPrintService(HelloService service){
this.s = service;
}
//--------------------------------------------------------------------------
// Default constructor
// --------------------------------------------------------------------------
public ClientImpl() {
System.out.println("CLIENT created");
}
@Init
public void init() {
System.out.println("CLIENT initialized");
}
// --------------------------------------------------------------------------
// Implementation of the Runnable interface
// --------------------------------------------------------------------------
public void run() {
System.out.println("Call the service...");
s.print("hello world");
}
}
/***
* OW2 FraSCAti Examples: HelloWorld Json Rpc
* Copyright (C) 2010 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: Christophe Demarey
*
* Contributor(s):
*/
package org.ow2.frascati.examples.helloworld.jsonrpc;
import org.osoa.sca.annotations.Service;
@Service
public interface HelloService {
public void print(String msg);
}
<?xml version="1.0" encoding="UTF-8"?>
<!-- OW2 FraSCAti Examples: HelloWorld Web Service -->
<!-- Copyright (C) 2008 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: Damien Fournier -->
<!-- -->
<!-- Contributor(s): Nicolas Dolet -->
<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
xmlns:wsdli="http://www.w3.org/2004/08/wsdl-instance"
name="helloworld-jsonrpc-client">
<service name="r" promote="client/r">
<interface.java interface="java.lang.Runnable" />
</service>
<component name="client">
<service name="r">
<interface.java interface="java.lang.Runnable" />
</service>
<reference name="printService">
<frascati:binding.jsonrpc uri="http://localhost:9000/HelloService"/>
</reference>
<implementation.java class="org.ow2.frascati.examples.helloworld.jsonrpc.ClientImpl" />
</component>
</composite>
<?xml version="1.0"?>
<!--
* OW2 FraSCAti Examples: HelloWorld Json Rpc
*
* Copyright (c) 2009-2010 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: Christophe Demarey
*
* 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-jsonrpc-parent</artifactId>
<packaging>pom</packaging>
<name>OW2 FraSCAti Examples: HelloWorld Json Rpc</name>
<parent>
<groupId>org.ow2.frascati.examples</groupId>
<artifactId>parent</artifactId>
<version>1.3-SNAPSHOT</version>
</parent>
<dependencies>
<dependency>
<groupId>org.ow2.frascati</groupId>
<artifactId>frascati-binding-jsonrpc</artifactId>
<version>${frascati.version}</version>
</dependency>
</dependencies>
<modules>
<module>client</module>
<module>server</module>
</modules>
</project>
============================================================================
OW2 FraSCAti Examples: HelloWorld Json Rpc
Copyright (C) 2010 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: Christophe Demarey
Contributor:
============================================================================
HelloWorld Json Rpc Server:
---------------------------
This example shows how to expose an SCA service with Json Rpc.
Compilation with Maven:
-----------------------
mvn install
Execution with Maven:
---------------------
mvn -Prun (standalone execution)
mvn -Pexplorer (with FraSCAti Explorer)
Compilation and execution with the FraSCAti script:
---------------------------------------------------
frascati compile src hello
frascati run helloworld-jsonrpc-server -libpath hello.jar
<?xml version="1.0"?>
<!--
* OW2 FraSCAti Examples: HelloWorld Json Rpc
*
* Copyright (c) 2010 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: Christophe Demarey
-->
<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-jsonrpc-server</artifactId>
<packaging>jar</packaging>
<name>OW2 FraSCAti Examples: HelloWorld Json Rpc Server</name>
<parent>
<groupId>org.ow2.frascati.examples</groupId>
<artifactId>helloworld-jsonrpc-parent</artifactId>
<version>1.3-SNAPSHOT</version>
</parent>
<properties>
<composite.file>helloworld-jsonrpc-server</composite.file>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
<dependency>
<groupId>org.ow2.frascati.examples.test</groupId>
<artifactId>frascati-test</artifactId>
<version>${frascati.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
/***
* OW2 FraSCAti Examples: HelloWorld Json Rpc
* Copyright (C) 2010 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: Christophe Demarey
*
* Contributor(s):
*/
package org.ow2.frascati.examples.helloworld.jsonrpc;
import org.osoa.sca.annotations.Service;
@Service
public interface HelloService {
public void print(String msg);
}
/***
* OW2 FraSCAti Examples: HelloWorld Json Rpc
* Copyright (C) 2010 INRIA, University of Lille1
*
* 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: Christophe Demarey
*
* Contributor(s):
*/
package org.ow2.frascati.examples.helloworld.jsonrpc;
import org.osoa.sca.annotations.Property;
public class ServerImpl implements HelloService {
// --------------------------------------------------------------------------
// SCA Properties
// --------------------------------------------------------------------------
private String header = "->";
private int count = 1;
public String getHeader() {
return header;
}
@Property
public void setHeader(final String header) {
this.header = header;
}
public int getCount() {
return count;
}
@Property
public void setCount(final int count) {
this.count = count;
}
// --------------------------------------------------------------------------
// Default constructor
// --------------------------------------------------------------------------
public ServerImpl() {
System.out.println("SERVER created");
}
// --------------------------------------------------------------------------
// Implementation of the HelloService interface
// --------------------------------------------------------------------------
public void print(final String msg) {
System.out.println("Server: begin printing...");
for (int i = 0; i < (count); ++i) {
System.out.println(((header) + msg));
}
System.out.println("Server: print done.");
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!-- OW2 FraSCAti Examples: HelloWorld Json Rpc -->
<!-- Copyright (C) 2008-2010 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: Christophe Demarey -->
<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
xmlns:frascati="http://frascati.ow2.org/xmlns/sca/1.1"
xmlns:wsdli="http://www.w3.org/2004/08/wsdl-instance"
name="helloworld-jsonrpc-server">
<service name="s" promote="server/s">
<interface.java interface="org.ow2.frascati.examples.helloworld.jsonrpc.HelloService"/>
<frascati:binding.jsonrpc uri="http://localhost:9000/HelloService"/>
</service>
<component name="server">
<implementation.java class="org.ow2.frascati.examples.helloworld.jsonrpc.ServerImpl"/>
<service name="s">
<interface.java interface="org.ow2.frascati.examples.helloworld.jsonrpc.HelloService"/>
</service>
</component>