Commit de902cee authored by Nicolas Dolet's avatar Nicolas Dolet

Add an example (client+server) with a rest binding: counter.

parent bbcddb84
<?xml version="1.0"?>
<!--
* OW2 FraSCAti Examples: 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: 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>counter-client</artifactId>
<version>1.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>OW2 FraSCAti Examples: RESTfull Counter Client</name>
<parent>
<groupId>org.ow2.frascati.examples</groupId>
<artifactId>counter-parent</artifactId>
<version>1.1-SNAPSHOT</version>
</parent>
<properties>
<composite.file>counter-client</composite.file>
<service.name>r</service.name>
<method.name>run</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: 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): Nicolas Dolet
*/
package org.ow2.frascati.examples.counter.api;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.FormParam;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
/**
* A simple counter service.
*
* @author Philippe Merle
*/
public interface CounterService {
/**
* Return the counter value.
*
* @return the counter value.
*/
@GET
@Path("/")
@Produces("text/plain")
int getValue();
/**
* Increment the counter value.
*/
@POST
@Path("/incr")
void increment(@FormParam("v") int v);
/**
* Decrement the counter value.
*/
@POST
@Path("/decr")
void decrement(@FormParam("v") int v);
/**
* Reset the counter value.
*
* NOTE: Apache CXF 2.2.2 does not allow to name this method 'reset'. Because
* the proxy generated by the Apache CXF JAXRS client frontend inherits from
* the Client interface which already declares a 'reset' method.
*/
@POST
@Path("/reset")
void resetIt();
}
/***
* OW2 FraSCAti Examples: 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): Nicolas Dolet
*/
package org.ow2.frascati.examples.counter.lib;
import org.osoa.sca.annotations.Reference;
import org.osoa.sca.annotations.Service;
import org.ow2.frascati.examples.counter.api.CounterService;
/**
* Implementation of a {@link CounterService} client component.
*
* @author Philippe Merle
*/
@Service(Runnable.class)
public class Client
implements Runnable {
/** The counter service to invoke. */
@Reference
private CounterService counter;
/**
* @see java.lang.Runnable#run()
*/
public void run() {
System.out.println("CounterService getValue: " + counter.getValue());
System.out.println("CounterService increment(10)...");
counter.increment(10);
System.out.println("CounterService getValue: " + counter.getValue());
System.out.println("CounterService decrement(10)...");
counter.decrement(10);
System.out.println("CounterService getValue: " + counter.getValue());
}
}
<?xml version="1.0" encoding="ISO-8859-15"?>
<!-- OW2 FraSCAti Examples: 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: Nicolas Dolet -->
<!-- -->
<!-- Contributor(s): -->
<composite name="counter-client"
xmlns="http://www.osoa.org/xmlns/sca/1.0"
xmlns:frascati="http://frascati.ow2.org/plugin"
targetNamespace="http://frascati.ow2.org/twitter">
<service name="r" promote="client/Runnable"/>
<component name="client">
<implementation.java class="org.ow2.frascati.examples.counter.lib.Client" />
<reference name="counter">
<frascati:binding.rest uri="http://localhost:8080/CounterService"/>
</reference>
</component>
</composite>
<?xml version="1.0"?>
<!--
* OW2 FraSCAti Examples: 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: 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>counter-parent</artifactId>
<version>1.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>OW2 FraSCAti Examples: RESTfull Counter</name>
<parent>
<groupId>org.ow2.frascati.examples</groupId>
<artifactId>parent</artifactId>
<version>1.1-SNAPSHOT</version>
</parent>
<modules>
<module>client</module>
<module>server</module>
</modules>
</project>
<?xml version="1.0"?>
<!--
* OW2 FraSCAti Examples: 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: 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>counter-server</artifactId>
<version>1.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>OW2 FraSCAti Examples: RESTfull Counter Server</name>
<parent>
<groupId>org.ow2.frascati.examples</groupId>
<artifactId>counter-parent</artifactId>
<version>1.1-SNAPSHOT</version>
</parent>
<properties>
<composite.file>counter-server</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: 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): Nicolas Dolet
*/
package org.ow2.frascati.examples.counter.api;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.FormParam;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import org.osoa.sca.annotations.Service;
/**
* A simple counter service.
*
* @author Philippe Merle
*/
@Service
public interface CounterService {
/**
* Return the counter value.
*
* @return the counter value.
*/
@GET
@Path("/")
@Produces("text/plain")
int getValue();
/**
* Increment the counter value.
*/
@POST
@Path("/incr")
void increment(@FormParam("v") int v);
/**
* Decrement the counter value.
*/
@POST
@Path("/decr")
void decrement(@FormParam("v") int v);
/**
* Reset the counter value.
*
* NOTE: Apache CXF 2.2.2 does not allow to name this method 'reset'. Because
* the proxy generated by the Apache CXF JAXRS client frontend inherits from
* the Client interface which already declares a 'reset' method.
*/
@POST
@Path("/reset")
void resetIt();
}
/***
* OW2 FraSCAti Examples: 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): Nicolas Dolet
*/
package org.ow2.frascati.examples.counter.lib;
import org.osoa.sca.annotations.Scope;
import org.ow2.frascati.examples.counter.api.CounterService;
/**
* A simple implementation of the {@link CounterService} interface.
*
* @author Philippe Merle
*/
@Scope("COMPOSITE")
public class CounterServiceImpl
implements CounterService {
/** Internal state of the counter. */
protected int value;
/**
* Return the counter value.
*
* @return the counter value.
*/
public int getValue() {
System.out.println("CounterServiceImpl getValue(" + value + ')');
return value;
}
/**
* Increment the counter value.
*/
public void increment(int v) {
System.out.println("CounterServiceImpl increment(" + v + ')');
value = value + v;
}
/**
* Decrement the counter value.
*/
public void decrement(int v) {
System.out.println("CounterServiceImpl decrement(" + v + ')');
value = value - v;
}
/**
* Reset the counter value.
*/
public void resetIt() {
System.out.println("CounterServiceImpl resetIt.");
value = 0;
}
}
<?xml version="1.0" encoding="ISO-8859-15"?>
<!-- OW2 FraSCAti Examples: 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: Nicolas Dolet -->
<!-- -->
<!-- Contributor(s): -->
<composite name="counter-server"
xmlns="http://www.osoa.org/xmlns/sca/1.0"
xmlns:frascati="http://frascati.ow2.org/plugin"
targetNamespace="http://frascati.ow2.org/twitter">
<component name="server">
<implementation.java class="org.ow2.frascati.examples.counter.lib.CounterServiceImpl" />
<service name="counter">
<frascati:binding.rest uri="http://localhost:8080/CounterService"/>
</service>
</component>
</composite>
......@@ -130,6 +130,7 @@
<module>isbn-test</module>
<module>dictionary</module>
<module>twitter-rest</module>
<module>counter-rest</module>
</modules>
</project>
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