<?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>Silveira Neto &#187; xort</title>
	<atom:link href="http://silveiraneto.net/tag/xort/feed/" rel="self" type="application/rss+xml" />
	<link>http://silveiraneto.net</link>
	<description>the world is a pixel</description>
	<lastBuildDate>Sun, 08 Jan 2012 05:17:57 +0000</lastBuildDate>
	<language>pt-br</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.5</generator>
		<item>
		<title>Buzz on JavaFX and Inkscape</title>
		<link>http://silveiraneto.net/2008/11/26/buzz-on-javafx-and-inkscape/</link>
		<comments>http://silveiraneto.net/2008/11/26/buzz-on-javafx-and-inkscape/#comments</comments>
		<pubDate>Wed, 26 Nov 2008 21:28:27 +0000</pubDate>
		<dc:creator>Silveira</dc:creator>
				<category><![CDATA[english]]></category>
		<category><![CDATA[GlassFish]]></category>
		<category><![CDATA[Inkscape]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JavaFX]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[Sun]]></category>
		<category><![CDATA[xort]]></category>

		<guid isPermaLink="false">http://silveiraneto.net/?p=1808</guid>
		<description><![CDATA[At November, 26, on the main page of java.sun.com at the section From The Blogosfere Thanks for all comments, suggestions and feedback on the post Inkscape and JavaFX working together. The JavaFX guru James Weaver posted about on his blog and it also figured out on java.sun.com on the From The Blogosfere section. Bob said [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;"><img class="size-full wp-image-1809 aligncenter" title="java.sun.com" src="http://silveiraneto.net/wp-content/uploads/2008/11/javasuncom.png" alt="" width="400" height="269" /><br />
<small>At November, 26, on the main page of <a href="http://sun.java.com">java.sun.com</a> at the section <em>From The Blogosfere</em></small></p>
<p>Thanks for all comments, suggestions and feedback on the post <a title="Blog post" href="http://silveiraneto.net/2008/11/21/inkscape-and-javafx-working-together/">Inkscape and JavaFX working together</a>. The JavaFX guru James Weaver <a title="Weaver's blog" href="http://learnjavafx.typepad.com/weblog/2008/11/up-the-nile-with-a-paddle.html">posted about</a> on his blog and it also figured out on <a title="Java at Sun" href="http://java.sun.com">java.sun.com</a> on the <em>From The Blogosfere</em> section.</p>
<p>Bob <a title="Comment" href="http://silveiraneto.net/2008/11/21/inkscape-and-javafx-working-together/#comment-3071">said that</a> there are <a title="Build Binaries" href="http://inkscape.modevia.com/win32/?C=M;O=D">build binaries</a> of Inkscape for Windows, so we can already see it 0.46-devel working without compiling yourself yours.</p>
<p>\o/</p>
<p>And hey, <a title="Project Xort" href="http://silveiraneto.net/2008/10/21/short-urls-with-glassfishmysql/">Project Xort</a> won a second place prize at the <a title="MYSQL+Glassfish Contest" href="http://blogs.sun.com/students/entry/mysql_and_glassfish_student_reviews">MySQL and GlassFish Student Reviews Contest</a>. A lot of guys here from Brazil were prized, congractulations guys!</p>
]]></content:encoded>
			<wfw:commentRss>http://silveiraneto.net/2008/11/26/buzz-on-javafx-and-inkscape/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Short urls with Glassfish+MySQL</title>
		<link>http://silveiraneto.net/2008/10/21/short-urls-with-glassfishmysql/</link>
		<comments>http://silveiraneto.net/2008/10/21/short-urls-with-glassfishmysql/#comments</comments>
		<pubDate>Wed, 22 Oct 2008 02:27:18 +0000</pubDate>
		<dc:creator>Silveira</dc:creator>
				<category><![CDATA[english]]></category>
		<category><![CDATA[GlassFish]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[servlet]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[URI]]></category>
		<category><![CDATA[url]]></category>
		<category><![CDATA[Web Application]]></category>
		<category><![CDATA[xort]]></category>

		<guid isPermaLink="false">http://silveiraneto.net/?p=1503</guid>
		<description><![CDATA[Pipes, Creative Commons photo by flattop341. 1. The Problem Internet is full of long urls and meaningless. Long urls are difficult to remember or print, usually full of redundancy and low semantic. With short and meaningful urls you can avoid thes problems and even achieve profitable goals with SEO SEO (search engine optimization) technics. There [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;"><img class="size-full wp-image-1517 aligncenter" title="pipes_by_flattop341_on_flickr" src="http://silveiraneto.net/wp-content/uploads/2008/10/pipes_by_flattop341_on_flickr.jpg" alt="" width="500" height="375" /><br />
Pipes, Creative Commons photo by <a href="http://flickr.com/photos/flattop341/253765659/">flattop341</a>.</p>
<h2>1. The Problem</h2>
<p>Internet is full of long urls and meaningless.</p>
<p>Long urls are difficult to remember or print, usually full of redundancy and low semantic. With short and meaningful urls you can avoid thes problems and even achieve profitable goals with SEO<br />
SEO (search engine optimization) technics.</p>
<p>There are services like <a title="Tiny URL" href="http://tinyurl.com/">Tiny URL</a>, <a title="Fancy URL" href="http://www.fancyurl.com/home.php">Fancy URL</a>, <a title="Moo URL" href="http://moourl.com/">Moo URL</a> and others. Although they solve part of the problems, they bring <a title="Wikipedia, english" href="http://en.wikipedia.org/wiki/TinyURL#Criticism">several others</a>. Another problem is if you have a web site like example.com and use a third-party service for short urls you are losing part of your mind-share with your users and clients.</p>
<p>As an example, if a example.com company wants to promote a open work position would be preferable spread a example.com/jobs instead of a tinyurl.com/examplejobs, or even worst, a tinyurl.com/3i4i592 (meaningless hash).</p>
<h2>2. Solution Approach</h2>
<p>I created a little program called <a title="xort project page" href="http://xort.dev.java.net">xort</a> that can be placed on your own server and provide you own short maintening your base url.</p>
<p style="text-align: center;"><img title="pipe_abstraction" src="http://silveiraneto.net/wp-content/uploads/2008/10/pipe_abstraction.png" alt="" /></p>
<p>I use a pipe abstraction. Each pipe redirects from a key url to an output url.</p>
<p>The idea is that you have <a title="xort project page" href="http://xort.dev.java.net">xort</a> installed and associated into your domain (preferably on /x). A pipe inside example.com would be like example.com/x/jobs.</p>
<h2>3. Tools</h2>
<p>All those tools are multi platform, open source and free.</p>
<h3>3.1 Glassfish Application Server</h3>
<p style="text-align: center;"><img title="Glassfish logo" src="../wp-content/uploads/2008/09/glassfish_logo_large.gif" alt="" /></p>
<p><a title="Glassfish Project" href="http://glassfish.dev.java.net">Glassfish</a> is an open source application server project led by Sun Microsystems for the Java Enterprise Edition (Java EE) platform. It&#8217;s very easy to install and run and have a very nice administration web interface where you can do from simple tasks like deploy a application to more complexes like clustering.</p>
<p style="text-align: center;"><img class="size-full wp-image-1249" title="glassfish_web_apps" src="../wp-content/uploads/2008/09/glassfish_web_apps.png" alt="" /><br />
Glassfish Admin Console</p>
<p>To develop the application I&#8217;m using <a title="NetBeans 6.5 Beta Download" href="http://download.netbeans.org/netbeans/6.5/beta/">NetBeans 6.5 Beta</a> that comes with <em>Glassfish V3 prelude b15b</em>. Netbeans also provides a integration of project, database and web server.</p>
<p style="text-align: center;"><img class="size-full wp-image-1504 aligncenter" title="netbeans services server glassfish" src="http://silveiraneto.net/wp-content/uploads/2008/10/netbeans_services_server_glassfish.png" alt="" width="361" height="161" /></p>
<p>Nevertheless, Glassfish has no dependencies with any IDE and perfectly works by alone. If you need <a title="Glassfish on Linux" href="http://silveiraneto.net/2008/09/07/glassfish-on-linux/">I wrote this post</a> explaining how to install and deploy a application on Glassfish from scratch.</p>
<h3>3.2 MySQL Relational Database</h3>
<p style="text-align: center;"><img class="size-full wp-image-1505 aligncenter" title="mysql" src="http://silveiraneto.net/wp-content/uploads/2008/10/mysql.png" alt="" width="180" height="93" /></p>
<p>MySQL is a relational database management system and probably the most used database on internet (has more than 11 million installations). It&#8217;s also very easy to install and administer, through command line or many gui interfaces.</p>
<p>To install MySQL and JDBC driver on Ubuntu just run as root:</p>
<blockquote><p># apt-get install mysql-server libmysql-java</p></blockquote>
<p>After installing and configuring it you can <a title="Looking for databases drivers" href="http://silveiraneto.net/2008/10/13/looking-for-databases-drivers/">test the jdbc driver throught this servlet code</a>. You can optionally register the MySQL on NetBeans to have a easier access to it thought the service tab.</p>
<p style="text-align: center;"><img class="size-full aligncenter" title="netbeans_services_databases" src="http://silveiraneto.net/wp-content/uploads/2008/10/netbeans_services_databases.png" alt="" /></p>
<p>At the command line you can invoke <em>mysql</em> command line interface and use MySql commands or SQL queries. I&#8217;ll login and create a database called xort:</p>
<blockquote><p>$ <strong>mysql -u username -p</strong><br />
Enter password:<br />
Welcome to the MySQL monitor.  Commands end with ; or \g.<br />
Your MySQL connection id is 13<br />
Server version: 5.0.51a-3ubuntu5.3 (Ubuntu)</p>
<p>Type &#8216;help;&#8217; or &#8216;\h&#8217; for help. Type &#8216;\c&#8217; to clear the buffer.</p>
<p>mysql&gt; <strong>create database xort;</strong><br />
Query OK, 1 row affected (0.06 sec)</p></blockquote>
<p>You could also create this database by an SQL statement:</p>
<div class="wp_syntax">
<div class="code">
<pre class="sql sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">DATABASE</span> xort;</pre>
</div>
</div>
<p>To select the database xort:</p>
<blockquote><p>mysql&gt; <strong>use xort;</strong><br />
Reading table information for completion of table and column names<br />
You can turn off this feature to get a quicker startup with -A</p>
<p>Database changed<br />
mysql&gt;</p></blockquote>
<p>Now we create a database called pipes with fields pin (pipe in) and pout (pipe out). They represent the input url and the output url of our pipe abstraction.</p>
<div class="wp_syntax">
<div class="code">
<pre class="sql sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> pipes <span style="color: #66cc66;">&#40;</span>
   pin varchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
   pout varchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#41;</span>;</pre>
</div>
</div>
<p>As we expect a lot of searches queries on this table, we can optionally create a index for it on pin field. This can reduce ours searches from O(n) to O(logn) (because pin&#8217;s will be ordered so don&#8217;t need to look all pipes, we can use logn algorithms like binary search).</p>
<div class="wp_syntax">
<div class="code">
<pre class="sql sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">INDEX</span> pinindex <span style="color: #993333; font-weight: bold;">ON</span> pipes <span style="color: #66cc66;">&#40;</span>pin<span style="color: #66cc66;">&#41;</span>;</pre>
</div>
</div>
<p>Another trick to improve our speed is recycling connections through connection pools.</p>
<p style="text-align: center;"><img class="size-full wp-image-1535 aligncenter" title="glassfish pool" src="http://silveiraneto.net/wp-content/uploads/2008/10/glassfish_pool.png" alt="" width="300" height="197" /></p>
<p>Creating a pool of MySQL connections on Glassfish is very easy. There&#8217;re two good tutorials on this subject:</p>
<ul>
<li> <a title="Permanent Link: Glassfish v2 UR1 and MySQL Connection Pool" rel="bookmark" href="http://thestewscope.wordpress.com/2008/01/08/glassfish-v2-ur1-and-mysql-connection-pool/">Glassfish v2 UR1 and MySQL Connection Pool</a></li>
<li><a title="Pooling with MySQL" href="http://dev.mysql.com/tech-resources/articles/connection_pooling_with_connectorj.html">Connection pooling with MySQL Connector/J</a></li>
</ul>
<p>And now we populate the database with some initial pipes.</p>
<div class="wp_syntax">
<div class="code">
<pre class="sql sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> pipes <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'blog'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'http://silveiraneto.net'</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> pipes <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'cejug'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'http://cejug.org/display/cejug/Home'</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> pipes <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'orkut'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'http://www.orkut.com.br/Main#Profile.aspx?rl=ls&amp;amp;uid=12443310329436634134'</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> pipes <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'glassfish'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'http://glassfish.dev.java.net'</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> pipes <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'mysql'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'http://dev.mysql.org'</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> pipes <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'twitter'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'http://twitter.com/silveira'</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> pipes <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'lab'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'http://maps.google.com/maps?f=q&amp;amp;geocode=&amp;amp;q=campus+do+pici&amp;amp;g=Fortaleza,+Brazil&amp;amp;ie=UTF8&amp;amp;t=h&amp;amp;ll=-3.745978,-38.574023&amp;amp;spn=0.002452,0.004823&amp;amp;z=18'</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> pipes <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'videos'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'http://br.youtube.com/user/NetoSilveira'</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> pipes <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'photos'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'http://flickr.com/photos/silveiraneto/'</span><span style="color: #66cc66;">&#41;</span>;</pre>
</div>
</div>
<h2>4. Program</h2>
<p>Basically we have just a program that implement this simple behavior:</p>
<ol>
<li>separate the key from the url.</li>
<li>if the key is a pin from a pipe then redirect to that pout.</li>
<li>else provide a way to create a new pipe.</li>
<li>list all pipes.</li>
<li>provide a way to remove a pipe.</li>
</ol>
<p>To get the key we need to separate the proper part of the request uri:</p>
<div class="wp_syntax">
<div class="code">
<pre class="java java" style="font-family:monospace;"><span style="color: #003399;">String</span> uri <span style="color: #339933;">=</span> request.<span style="color: #006633;">getRequestURI</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
<span style="color: #003399;">String</span> key <span style="color: #339933;">=</span> uri.<span style="color: #006633;">substring</span><span style="color: #009900;">&#40;</span>request.<span style="color: #006633;">getContextPath</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">length</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span>;</pre>
</div>
</div>
<p>After that we check if it matches with a pin of some pipe. In this case we redirect user for the correspondent pout:</p>
<div class="wp_syntax">
<div class="code">
<pre class="java java" style="font-family:monospace;">response.<span style="color: #006633;">sendRedirect</span><span style="color: #009900;">&#40;</span>pout<span style="color: #009900;">&#41;</span>;</pre>
</div>
</div>
<p>Notice that using this approach we can connect a url to a extern or intern url (even to another pipe).</p>
<h2>5. Download</h2>
<p>Check out the xort project and sources at <a href="http://xort.dev.java.net/">xort.dev.java.net</a>:</p>
<ul>
<li><a href="https://xort.dev.java.net/servlets/ProjectDocumentList">Releases</a>.</li>
<li><a title="Subversion" href="https://xort.dev.java.net/source/browse/xort/trunk/">Browse Source Code</a>.</li>
</ul>
<p>Or grab sources and the current build with:</p>
<blockquote><p>svn checkout https://xort.dev.java.net/svn/xort/trunk xort</p></blockquote>
<p>Parameters can be passed by the the web.xml file:</p>
<div class="wp_syntax">
<div class="code">
<pre class="xml xml" style="font-family:monospace;">   Set if users can add new pipes using the web interface.
allowNewPipes
true
&nbsp;
   JDBC driver to use
driver
com.mysql.jdbc.Driver
&nbsp;
   Username to login on the database.
username
root
&nbsp;
   Password for the given username.
password
yourpassword
&nbsp;
   JDBC path to database.
database
jdbc:mysql://localhost:3306/xort</pre>
</div>
</div>
<p>Xort up and running:</p>
<p style="text-align: center;"><a href="http://silveiraneto.net/wp-content/uploads/2008/10/xort_running.png"><img class="alignnone size-medium wp-image-1548" title="xort_running" src="http://silveiraneto.net/wp-content/uploads/2008/10/xort_running-500x312.png" alt="" width="500" height="312" /></a></p>
<p><object width="425" height="355"><param name="movie" value="http://www.youtube.com/v/b2Mrk8XfvKk&amp;rel=0&amp;color1=0x3a3a3a&amp;color2=0x999999"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/b2Mrk8XfvKk&amp;rel=0&amp;color1=0x3a3a3a&amp;color2=0x999999" type="application/x-shockwave-flash" wmode="transparent" width="425" height="355"></object></p>
]]></content:encoded>
			<wfw:commentRss>http://silveiraneto.net/2008/10/21/short-urls-with-glassfishmysql/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
	</channel>
</rss>

