<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Christophe Hamerling [Archive] &#187; SOCIAL</title>
	<atom:link href="http://planet.petalslink.com/home/chamerling/tag/social/feed/" rel="self" type="application/rss+xml" />
	<link>http://planet.petalslink.com/home/chamerling</link>
	<description>Things around SOA, Web Services, Open Source and more...</description>
	<lastBuildDate>Wed, 07 Oct 2009 13:16:14 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.2</generator>
		<item>
		<title>JSR181 Servive Engine sample : Talk to Twitter</title>
		<link>http://planet.petalslink.com/home/chamerling/2009/04/01/jsr181-servive-engine-sample-talk-to-twitter/</link>
		<comments>http://planet.petalslink.com/home/chamerling/2009/04/01/jsr181-servive-engine-sample-talk-to-twitter/#comments</comments>
		<pubDate>Wed, 01 Apr 2009 11:29:11 +0000</pubDate>
		<dc:creator>Christophe Hamerling</dc:creator>
				<category><![CDATA[PEtALS]]></category>
		<category><![CDATA[SOCIAL]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://blog.ebmwebsourcing.com/home/chamerling/?p=79</guid>
		<description><![CDATA[Just for fun&#8230; The current article will show you that the JSR181 Service Engine really provides an easy way to create JBI services. Since creating simple HelloWorld service is quite boring, let&#8217;s talk to twitter micro blogging site. I will use the Twitter4J API () to talk to Twitter (right all the Twitter job is [...]]]></description>
			<content:encoded><![CDATA[<p>Just for fun&#8230;</p>
<p>The current article will show you that the JSR181 Service Engine really provides an easy way to create JBI services. Since creating simple HelloWorld service is quite boring, let&#8217;s talk to twitter micro blogging site.</p>
<p>I will use the Twitter4J API () to talk to Twitter (right all the Twitter job is done here&#8230; The current article is not a Twitter tutorial but just a small PEtALS one&#8230;).</p>
<p>Interface definition</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">net.chamerling.petals.twitter</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.jws.WebMethod</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.jws.WebParam</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.jws.WebService</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
 * @author chamerling
 *
 */</span>
@WebService
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">interface</span> TwitterService <span style="color: #009900;">&#123;</span>
&nbsp;
	@WebMethod
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> update<span style="color: #009900;">&#40;</span>@WebParam<span style="color: #009900;">&#40;</span>name <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;id&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #003399;">String</span> login,
			@WebParam<span style="color: #009900;">&#40;</span>name <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;password&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #003399;">String</span> password,
			@WebParam<span style="color: #009900;">&#40;</span>name <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;status&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #003399;">String</span> status<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> TwitterServiceException<span style="color: #339933;">;</span>
&nbsp;
	@WebMethod
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> getTimeLine<span style="color: #009900;">&#40;</span>@WebParam<span style="color: #009900;">&#40;</span>name <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;id&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #003399;">String</span> login,
			@WebParam<span style="color: #009900;">&#40;</span>name <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;password&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #003399;">String</span> password,
			@WebParam<span style="color: #009900;">&#40;</span>name <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;user&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #003399;">String</span> user<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> TwitterServiceException<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Implementation (quick)</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">net.chamerling.petals.twitter</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.ArrayList</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.List</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.jws.WebMethod</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.jws.WebParam</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.jws.WebService</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">twitter4j.Status</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">twitter4j.Twitter</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">twitter4j.TwitterException</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
 * @author chamerling
 *
 */</span>
@WebService<span style="color: #009900;">&#40;</span>serviceName <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;TwitterService&quot;</span>, name <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;TwitterService&quot;</span>, targetNamespace <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;http://twitter.chamerling.net/petals&quot;</span><span style="color: #009900;">&#41;</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> TwitterServiceImpl <span style="color: #000000; font-weight: bold;">implements</span> TwitterService <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">/*
	 * (non-Javadoc)
	 * @see net.chamerling.petals.twitter.TwitterService#update(java.lang.String, java.lang.String, java.lang.String)
	 */</span>
	@WebMethod
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> update<span style="color: #009900;">&#40;</span>@WebParam<span style="color: #009900;">&#40;</span>name <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;id&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #003399;">String</span> login,
			@WebParam<span style="color: #009900;">&#40;</span>name <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;password&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #003399;">String</span> password,
			@WebParam<span style="color: #009900;">&#40;</span>name <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;status&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #003399;">String</span> status<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> TwitterServiceException <span style="color: #009900;">&#123;</span>
		<span style="color: #003399;">String</span> result <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
			Status s <span style="color: #339933;">=</span> getTwitter<span style="color: #009900;">&#40;</span>login, password<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">update</span><span style="color: #009900;">&#40;</span>status<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			result <span style="color: #339933;">=</span> s.<span style="color: #006633;">getText</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span>twitter4j.<span style="color: #006633;">TwitterException</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> TwitterServiceException<span style="color: #009900;">&#40;</span>e.<span style="color: #006633;">getMessage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000000; font-weight: bold;">return</span> result<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">/*
	 * (non-Javadoc)
	 * @see net.chamerling.petals.twitter.TwitterService#getTimeLine(java.lang.String, java.lang.String, java.lang.String)
	 */</span>
	@WebMethod
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> getTimeLine<span style="color: #009900;">&#40;</span>@WebParam<span style="color: #009900;">&#40;</span>name <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;id&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #003399;">String</span> login,
			@WebParam<span style="color: #009900;">&#40;</span>name <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;password&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #003399;">String</span> password,
			@WebParam<span style="color: #009900;">&#40;</span>name <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;user&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #003399;">String</span> user<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> TwitterServiceException <span style="color: #009900;">&#123;</span>
		Twitter twitter <span style="color: #339933;">=</span> getTwitter<span style="color: #009900;">&#40;</span>login, password<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #003399;">List</span> result <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">ArrayList</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #003399;">List</span> status <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>user <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				status <span style="color: #339933;">=</span> twitter.<span style="color: #006633;">getUserTimeline</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
				status <span style="color: #339933;">=</span> twitter.<span style="color: #006633;">getUserTimeline</span><span style="color: #009900;">&#40;</span>user<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span>TwitterException e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> TwitterServiceException<span style="color: #009900;">&#40;</span>e.<span style="color: #006633;">getMessage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span>Status status2 <span style="color: #339933;">:</span> status<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			result.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>status2.<span style="color: #006633;">getText</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">return</span> result.<span style="color: #006633;">toArray</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #008000; font-style: italic; font-weight: bold;">/**
	 * TODO : Some work to do for caching...
	 * 
	 * @param login
	 * @param password
	 * @return
	 */</span>
	<span style="color: #000000; font-weight: bold;">private</span> Twitter getTwitter<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> login, <span style="color: #003399;">String</span> password<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">new</span> Twitter<span style="color: #009900;">&#40;</span>login, password<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Put all of this in a JSR181 Service Unit, ie create the good Service Unit descriptor (cf to source attchment), package it (use PEtALS Maven plugin) and that&#8217;s all. JSR181 makes it easy ;o)</p>
<p>So now you can publish some status to Twitter with PEtALS.<br />
I have created a test acount here <a href="http://twitter.com/chamerlingtest">http://twitter.com/chamerlingtest</a> on which I have published messages with PEtALS.</p>
<p>Service Unit sources are available here : <a href="http://dl.getdropbox.com/u/73785/blog/twitter-jsr181.zip">http://dl.getdropbox.com/u/73785/blog/twitter-jsr181.zip</a></p>
]]></content:encoded>
			<wfw:commentRss>http://planet.petalslink.com/home/chamerling/2009/04/01/jsr181-servive-engine-sample-talk-to-twitter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>I am on Twitter</title>
		<link>http://planet.petalslink.com/home/chamerling/2009/01/13/i-am-on-twitter/</link>
		<comments>http://planet.petalslink.com/home/chamerling/2009/01/13/i-am-on-twitter/#comments</comments>
		<pubDate>Tue, 13 Jan 2009 08:32:52 +0000</pubDate>
		<dc:creator>Christophe Hamerling</dc:creator>
				<category><![CDATA[Non classé]]></category>
		<category><![CDATA[SOCIAL]]></category>

		<guid isPermaLink="false">http://blog.ebmwebsourcing.com/home/chamerling/?p=32</guid>
		<description><![CDATA[You can now follow me on Twitter : http://twitter.com/chamerling]]></description>
			<content:encoded><![CDATA[<p>You can now follow me on Twitter : <a href="http://twitter.com/chamerling" target="_blank">http://twitter.com/chamerling</a></p>
]]></content:encoded>
			<wfw:commentRss>http://planet.petalslink.com/home/chamerling/2009/01/13/i-am-on-twitter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

