Commit 28e2c1df authored by Nicolas Dolet's avatar Nicolas Dolet

Add an example with a rest binding bound to twitter services.

parent fb93ebb1
<?xml version="1.0"?>
<!--
* OW2 FraSCAti Examples: Twitter
*
* 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>twitter</artifactId>
<version>1.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>OW2 FraSCAti Examples: Twitter</name>
<parent>
<groupId>org.ow2.frascati.examples</groupId>
<artifactId>parent</artifactId>
<version>1.1-SNAPSHOT</version>
</parent>
<properties>
<composite.file>twitter-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>
<!-- <dependency>-->
<!-- <groupId>javax.xml.bind</groupId>-->
<!-- <artifactId>jaxb-api</artifactId>-->
<!-- <version>2.1</version>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>javax.ws.rs</groupId>-->
<!-- <artifactId>jsr311-api</artifactId>-->
<!-- <version>1.0</version>-->
<!-- </dependency>-->
</dependencies>
</project>
/***
* OW2 FraSCAti Examples: Twitter
* 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.twitter.api;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import org.ow2.frascati.examples.twitter.util.Ids;
import org.ow2.frascati.examples.twitter.util.User;
/**
* A simple API for Twitter.
*
* TODO: Must be extended with other RESTful methods of Twitter.
*
* @author Philippe Merle
*/
public interface Twitter {
/**
* Returns extended information of a given user in XML format.
*/
@GET
@Path("/users/show/{id}.xml")
@Produces("text/xml")
String getUserInXml(@PathParam("id") String id);
/**
* Returns extended information of a given user in JSON format.
*/
@GET
@Path("/users/show/{id}.json")
@Produces("application/json")
String getUserInJSON(@PathParam("id") String id);
/**
* Returns extended information of a given user.
*/
@GET
@Path("/users/show/{id}.xml")
User getUser(@PathParam("id") String id);
/**
* Returns the list of friends of a given user in XML format.
*/
@GET
@Path("/friends/ids/{id}.xml")
@Produces("text/xml")
String getFriendsInXml(@PathParam("id") String id);
/**
* Returns the list of friends of a given user in JSON format.
*/
@GET
@Path("/friends/ids/{id}.json")
@Produces("application/json")
String getFriendsInJSON(@PathParam("id") String id);
/**
* Returns the list of friends of a given user.
*/
@GET
@Path("/friends/ids/{id}.xml")
Ids getFriends(@PathParam("id") String id);
}
/***
* OW2 FraSCAti Examples: Twitter
* 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.twitter.lib;
import org.osoa.sca.annotations.Reference;
import org.osoa.sca.annotations.Service;
import org.ow2.frascati.examples.twitter.api.Twitter;
import org.ow2.frascati.examples.twitter.util.Ids;
import org.ow2.frascati.examples.twitter.util.User;
/**
* A simple client for Twitter.
*
* @author Philippe Merle
*/
@Service(Runnable.class)
public class Client implements Runnable {
/** Reference to the Twitter services. */
@Reference
private Twitter twitter;
/**
* @see java.lang.Runnable#run()
*/
public void run() {
final String userName = "vschiavoni";
getUser(userName);
getFriends(userName);
}
protected void getUser(String userName) {
System.out.println("getUserInXml(" + userName + "): " + twitter.getUserInXml(userName));
System.out.println("getUserInJSON(" + userName + "): " + twitter.getUserInJSON(userName));
User user = twitter.getUser(userName);
System.out.println(userName + ".id=" + user.id);
System.out.println(userName + ".name=" + user.name);
System.out.println(userName + ".screen_name=" + user.screen_name);
System.out.println(userName + ".location=" + user.location);
System.out.println(userName + ".description=" + user.description);
System.out.println(userName + ".profile_image_url=" + user.profile_image_url);
System.out.println(userName + ".url=" + user.url);
System.out.println(userName + ".protected=" + user.isProtected);
System.out.println(userName + ".followers_count=" + user.followers_count);
System.out.println(userName + ".profile_background_color=" + user.profile_background_color);
System.out.println(userName + ".profile_text_color=" + user.profile_text_color);
System.out.println(userName + ".profile_link_color=" + user.profile_link_color);
System.out.println(userName + ".profile_sidebar_fill_color=" + user.profile_sidebar_fill_color);
System.out.println(userName + ".profile_sidebar_border_color=" + user.profile_sidebar_border_color);
System.out.println(userName + ".friends_count=" + user.friends_count);
System.out.println(userName + ".created_at=" + user.created_at);
System.out.println(userName + ".favourites_count=" + user.favourites_count);
System.out.println(userName + ".utc_offset=" + user.utc_offset);
System.out.println(userName + ".time_zone=" + user.time_zone);
System.out.println(userName + ".profile_background_image_url=" + user.profile_background_image_url);
System.out.println(userName + ".profile_background_tile=" + user.profile_background_tile);
System.out.println(userName + ".statuses_count=" + user.statuses_count);
System.out.println(userName + ".verified=" + user.verified);
System.out.println(userName + ".status.created_at=" + user.status.created_at);
System.out.println(userName + ".status.id=" + user.status.id);
System.out.println(userName + ".status.text=" + user.status.text);
System.out.println(userName + ".status.source=" + user.status.source);
System.out.println(userName + ".status.truncated=" + user.status.truncated);
System.out.println(userName + ".status.in_reply_to_status_id=" + user.status.in_reply_to_status_id);
System.out.println(userName + ".status.in_reply_to_user_id=" + user.status.in_reply_to_user_id);
System.out.println(userName + ".status.favorited=" + user.status.favorited);
System.out.println(userName + ".status.in_reply_to_screen_name=" + user.status.in_reply_to_screen_name);
}
protected void getFriends(String userName) {
System.out.println("getFriendsInXml(" + userName + "): " + twitter.getFriendsInXml(userName));
System.out.println("getFriendsInJSON(" + userName + "): " + twitter.getFriendsInJSON(userName));
Ids friends = twitter.getFriends(userName);
System.out.println("getFriends(" + userName + "): " + friends.getId());
/* Removed as running this implies too many trafic.
for(String id : friends.getId()) {
getUser(id);
}
*/
}
}
/***
* OW2 FraSCAti Examples: Twitter
* 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.twitter.util;
import java.util.Collection;
import javax.xml.bind.annotation.XmlRootElement;
/**
*
* @author Philippe Merle
*/
@XmlRootElement
public class Ids {
private Collection<String> ids;
public Collection<String> getId() {
return ids;
}
public void setId(Collection<String> c) {
this.ids = c;
}
}
/***
* OW2 FraSCAti Examples: Twitter
* 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.twitter.util;
import javax.xml.bind.annotation.XmlRootElement;
/**
*
* @author Philippe Merle
*/
@XmlRootElement
public class Status {
public String created_at; // TODO: get as a DATE also.
public String id;
public String text;
public String source;
public boolean truncated;
public String in_reply_to_status_id;
public String in_reply_to_user_id;
public boolean favorited;
public String in_reply_to_screen_name;
}
/***
* OW2 FraSCAti Examples: Twitter
* 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.twitter.util;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlElement;
/**
*
* @author Philippe Merle
*/
@XmlRootElement
public class User {
public String id;
public String name;
public String screen_name;
public String location;
public String description;
public String profile_image_url; // TODO: get as a URL also.
public String url; // TODO: get as a URL also.
@XmlElement(name="protected")
public boolean isProtected;
public int followers_count;
public String profile_background_color; // COLOR
public String profile_text_color; // COLOR
public String profile_link_color; // COLOR
public String profile_sidebar_fill_color; // COLOR
public String profile_sidebar_border_color; // COLOR
public int friends_count;
public String created_at; // TODO: get as a DATE also.
public int favourites_count;
public int utc_offset;
public String time_zone;
public String profile_background_image_url; // TODO: get as a URL also.
public boolean profile_background_tile;
public int statuses_count;
// TO BE MAPPED <notifications></notifications>
public boolean verified;
// TO BE MAPPED <following></following>
public Status status;
}
<?xml version="1.0" encoding="ISO-8859-15"?>
<!-- OW2 FraSCAti Examples: Twitter -->
<!-- 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="twitter-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.twitter.lib.Client" />
<reference name="twitter">
<frascati:binding.rest uri="http://twitter.com"/>
</reference>
</component>
</composite>
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