<?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>Radek's Tech Blog &#187; equinox</title>
	<atom:link href="http://urbas.tk/index.php/tag/equinox/feed/" rel="self" type="application/rss+xml" />
	<link>http://urbas.tk</link>
	<description>Radoslaw H. Urbas homepage / blog</description>
	<lastBuildDate>Tue, 01 Jun 2010 20:31:19 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Running servlets inside Equinox/Eclipse</title>
		<link>http://urbas.tk/index.php/2010/01/22/running-servlets-inside-equinox/</link>
		<comments>http://urbas.tk/index.php/2010/01/22/running-servlets-inside-equinox/#comments</comments>
		<pubDate>Fri, 22 Jan 2010 17:57:34 +0000</pubDate>
		<dc:creator>Radoslaw Urbas</dc:creator>
				<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[IT]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[equinox]]></category>
		<category><![CDATA[jetty]]></category>
		<category><![CDATA[servlets]]></category>

		<guid isPermaLink="false">http://urbas.tk/?p=195</guid>
		<description><![CDATA[Creating plug-in hosting servlet Create new plug-in project Add plug-in dependencies javax.servlet org.eclipse.equinox.http.registry Add extension: org.eclipse.equinox.http.registry.servlets Configure servlet mapping in extension definition &#60;?xml version=&#34;1.0&#34; encoding=&#34;UTF-8&#34;?&#62; &#60;?eclipse version=&#34;3.4&#34;?&#62; &#60;plugin&#62; &#160; &#60;extension point=&#34;org.eclipse.equinox.http.registry.servlets&#34;&#62; &#60;servlet alias=&#34;/echo&#34; class=&#34;servlets.EchoServlet&#34; /&#62; &#60;/extension&#62; &#160; &#60;/plugin&#62; Create servlet class package servlets; &#160; package servlets; &#160; import java.io.IOException; import java.io.PrintWriter; &#160; import javax.servlet.http.HttpServlet; import [...]]]></description>
			<content:encoded><![CDATA[<ul>
<li>Creating plug-in hosting servlet
<ul>
<li>Create new plug-in project<a href="http://urbas.tk/wp-content/equinox_servlets_1.PNG"><img class="size-full wp-image-196 aligncenter" title="equinox_servlets_1" src="http://urbas.tk/wp-content/equinox_servlets_1.PNG" alt="equinox_servlets_1" width="360" height="430" /></a></li>
<li>Add plug-in dependencies
<ul>
<li><strong><em>javax.servlet</em></strong></li>
<li><strong><em>org.eclipse.equinox.http.registry</em></strong></li>
</ul>
</li>
<li>Add extension: <strong><em>org.eclipse.equinox.http.registry.servlets</em></strong></li>
<li>Configure servlet mapping in extension definition

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?eclipse</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;3.4&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;plugin<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;extension</span> <span style="color: #000066;">point</span>=<span style="color: #ff0000;">&quot;org.eclipse.equinox.http.registry.servlets&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet</span> <span style="color: #000066;">alias</span>=<span style="color: #ff0000;">&quot;/echo&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;servlets.EchoServlet&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/extension<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/plugin<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

</li>
<li>Create servlet class

<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;">servlets</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">servlets</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.IOException</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.PrintWriter</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.servlet.http.HttpServlet</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.servlet.http.HttpServletRequest</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.servlet.http.HttpServletResponse</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> EchoServlet <span style="color: #000000; font-weight: bold;">extends</span> HttpServlet <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">long</span> serialVersionUID <span style="color: #339933;">=</span> 137926368689939745L<span style="color: #339933;">;</span>
&nbsp;
	@Override
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> doGet<span style="color: #009900;">&#40;</span>HttpServletRequest request,
			HttpServletResponse response<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
		<span style="color: #003399;">String</span> value <span style="color: #339933;">=</span> request.<span style="color: #006633;">getParameter</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;value&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #003399;">PrintWriter</span> writer<span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
			writer <span style="color: #339933;">=</span> response.<span style="color: #006633;">getWriter</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #003399;">String</span> outputText <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Echo Servlet inside Equinox/Eclipse says: &quot;</span>
					<span style="color: #339933;">+</span> value<span style="color: #339933;">;</span>
			<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>outputText<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			writer.<span style="color: #006633;">write</span><span style="color: #009900;">&#40;</span>outputText<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			writer.<span style="color: #006633;">close</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><span style="color: #003399;">IOException</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #666666; font-style: italic;">// TODO Auto-generated catch block</span>
			e.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

</li>
</ul>
</li>
<li>Running plug-in hosting servlets in Eclipse IDE
<ul>
<li>Create new Run Configuration</li>
<li>Choose OSGi Framework</li>
<li>Deselect all preselected plug-ins from bundles list</li>
<li>Select only:
<ul>
<li>Newly created plug-in that&#8217;s hosting servlets</li>
<li><em><strong>org.mortbay.jetty.server</strong></em></li>
<li><em><strong>org.eclipse.equinox.http.jetty</strong></em></li>
</ul>
</li>
<li>Use Add Required Bundles option</li>
<li>Save configuration and Run it</li>
</ul>
</li>
<li>Using servlet
<ul>
<li>By default when running this configuration Jetty will start on port 80</li>
<li>Open a browser and hit URL for this example <em>http://localhost/echo?value=Hello<a href="http://urbas.tk/wp-content/equinox_servlets_2.PNG"><img class="aligncenter size-full wp-image-209" title="equinox_servlets_2" src="http://urbas.tk/wp-content/equinox_servlets_2.PNG" alt="equinox_servlets_2" width="419" height="312" /></a></em><a href="http://urbas.tk/wp-content/equinox_servlets_3.PNG"><img class="aligncenter size-full wp-image-197" title="equinox_servlets_3" src="http://urbas.tk/wp-content/equinox_servlets_3.PNG" alt="equinox_servlets_3" width="417" height="444" /></a></li>
</ul>
</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://urbas.tk/index.php/2010/01/22/running-servlets-inside-equinox/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
