<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0"><channel><atom:id>tag:blogger.com,1999:blog-36773632</atom:id><lastBuildDate>Fri, 27 Jan 2012 12:54:02 +0000</lastBuildDate><category>logging</category><category>Tipping Point</category><category>JPA</category><category>nexus</category><category>quartz</category><category>JSP</category><category>JUG</category><category>books</category><category>BSD License</category><category>phpLDAPadmin</category><category>Java.net</category><category>community</category><category>maven</category><category>JAX-RS</category><category>HTTPD</category><category>SJSAS</category><category>open source</category><category>add-on</category><category>Web</category><category>JSE6</category><category>white paper</category><category>EJB</category><category>Collections</category><category>facelets</category><category>OSCON</category><category>JRuby</category><category>Jython</category><category>spring</category><category>JAXB</category><category>License</category><category>Solaris</category><category>broken windows theory</category><category>Solaris 10</category><category>CDI</category><category>Persistence</category><category>Apache</category><category>Resin</category><category>JSE5</category><category>Jersey</category><category>anti-patterns</category><category>JEE5</category><category>Web Server</category><category>jQuery</category><category>mySQL</category><category>CSS</category><category>Subversion</category><category>Javascript</category><category>Rails</category><category>example</category><category>movable type</category><category>JSTL</category><category>Design</category><category>concurrency</category><category>wordpress</category><category>LDAP</category><category>WebM</category><category>OpenSolaris</category><category>Drupal</category><category>SELF</category><category>Netbeans</category><category>Tomcat</category><category>JDK7</category><category>woodstock</category><category>hsqldb</category><category>icefaces</category><category>FindBugs</category><category>JEE6</category><category>Eclipse</category><category>RoR</category><category>JSF</category><category>SunOne</category><category>Internet Explorer</category><category>JSR-292</category><category>blogging</category><category>Apache2</category><category>Redmine</category><category>JavaEE</category><category>Architecture</category><category>POI</category><category>Xcode</category><category>Web Server 7.0</category><category>AJAX</category><category>glassfish</category><category>viral expansion</category><category>SCJP</category><category>Mojarra</category><category>JSR-295</category><category>template</category><category>Oracle</category><category>viral marketing</category><category>JavaOne</category><category>Programming</category><category>OS X</category><category>Swing</category><category>JNDI</category><category>commons</category><category>frameworks</category><category>MIT License</category><category>wicket</category><category>plugin</category><category>JSR-311</category><category>codec</category><category>Presentation</category><category>Grails</category><category>source control</category><category>viral expansion loop</category><category>SSL</category><category>Ruby on Rails</category><category>Quercus</category><category>JSON</category><category>tapestry</category><category>CACert</category><category>EL</category><category>JSR-296</category><category>IDEA</category><category>Tomahawk</category><category>Xwiki</category><category>REST</category><category>patterns</category><category>tutorial</category><category>GreenJUG</category><category>GAE</category><category>Java</category><category>blog</category><category>RichFaces</category><category>thread</category><category>Google</category><category>JDBC</category><category>JavaFX</category><category>App Engine</category><category>PHP</category><category>JCP</category><category>certification</category><category>IntelliJ</category><category>pragmatic</category><category>JavaDB</category><category>Apache Derby</category><category>Visual JSF</category><category>Ruby</category><category>OpenDS</category><category>article</category><category>TLS</category><category>maps</category><category>JSE7</category><category>Caucho</category><category>mercurial</category><category>OpenJDK</category><title>Java Evangelist John Yeary's Blog</title><description /><link>http://javaevangelist.blogspot.com/</link><managingEditor>noreply@blogger.com (John Yeary)</managingEditor><generator>Blogger</generator><openSearch:totalResults>220</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/JavaEvangelistJohnYearysBlog" /><feedburner:info uri="javaevangelistjohnyearysblog" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><geo:lat>34.762693</geo:lat><geo:long>-82.24512</geo:long><creativeCommons:license>http://creativecommons.org/licenses/by-sa/3.0/</creativeCommons:license><image><link>http://creativecommons.org/licenses/by-sa/3.0/</link><url>http://creativecommons.org/images/public/somerights20.gif</url><title>Some Rights Reserved</title></image><feedburner:emailServiceId>JavaEvangelistJohnYearysBlog</feedburner:emailServiceId><feedburner:feedburnerHostname>http://feedburner.google.com</feedburner:feedburnerHostname><item><guid isPermaLink="false">tag:blogger.com,1999:blog-36773632.post-8683313248734308459</guid><pubDate>Sat, 21 Jan 2012 23:43:00 +0000</pubDate><atom:updated>2012-01-21T18:43:46.601-05:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">example</category><category domain="http://www.blogger.com/atom/ns#">Java</category><category domain="http://www.blogger.com/atom/ns#">JDK7</category><category domain="http://www.blogger.com/atom/ns#">tutorial</category><category domain="http://www.blogger.com/atom/ns#">Netbeans</category><title>NetBeans 7.1 IDE: Remote Database Connections</title><description>&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://netbeans.org/images_www/collateral/71/nb-banner-71lf.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://netbeans.org/images_www/collateral/71/nb-banner-71lf.png" /&gt;&lt;/a&gt;&lt;/div&gt;
The &lt;a href="http://netbeans.org/"&gt;NetBeans 7.1 IDE&lt;/a&gt; has a feature that has been around for a while, but does not get as much attention as it should. NetBeans allows you to take advantage of using remote databases for doing Java development. There are a number of wizards which can take advantage of connections created in the &lt;b&gt;Services → Database&lt;/b&gt; tab.&lt;br /&gt;
&lt;br /&gt;
In the demonstration video, I connect to a remote &lt;a href="http://db.apache.org/derby"&gt;Apache Derby&lt;/a&gt; Database, but the same principals apply to any database as long as you have JDBC drivers available.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Tips &amp;amp; Tricks&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
To verify that a remote database is &lt;a href="http://db.apache.org/derby"&gt;Apache Derby&lt;/a&gt; (&lt;a href="http://www.oracle.com/technetwork/java/javadb/overview/index.html"&gt;Java DB&lt;/a&gt;) which is listening on port 1527 (default Derby port). I connect to the remote application and append &lt;b&gt;XXX;create=true;&lt;/b&gt; to the end of the connection string. When I test the database connection, if it is&amp;nbsp;&lt;a href="http://db.apache.org/derby"&gt;Apache Derby&lt;/a&gt;, it will create the new database which confirms our suspicion.&lt;br /&gt;
&lt;br /&gt;
This 3 minute video demonstrates this valuable feature which developers should use for all their database needs.&lt;br /&gt;
&lt;br /&gt;
&lt;iframe allowfullscreen="" frameborder="0" height="480" src="http://www.youtube.com/embed/Fk2EkBs-Oq4" width="640"&gt;&lt;/iframe&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/36773632-8683313248734308459?l=javaevangelist.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/ERwQekID4uBqFH6OCXA3J29OxE0/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ERwQekID4uBqFH6OCXA3J29OxE0/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/ERwQekID4uBqFH6OCXA3J29OxE0/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ERwQekID4uBqFH6OCXA3J29OxE0/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/JavaEvangelistJohnYearysBlog/~4/6rm2px2qADM" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/JavaEvangelistJohnYearysBlog/~3/6rm2px2qADM/netbeans-71-ide-remote-database.html</link><author>noreply@blogger.com (John Yeary)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://img.youtube.com/vi/Fk2EkBs-Oq4/default.jpg" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://javaevangelist.blogspot.com/2012/01/netbeans-71-ide-remote-database.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-36773632.post-8705490509123905516</guid><pubDate>Sat, 21 Jan 2012 22:54:00 +0000</pubDate><atom:updated>2012-01-21T17:54:26.572-05:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">example</category><category domain="http://www.blogger.com/atom/ns#">Java</category><category domain="http://www.blogger.com/atom/ns#">JDK7</category><category domain="http://www.blogger.com/atom/ns#">tutorial</category><category domain="http://www.blogger.com/atom/ns#">Netbeans</category><title>NetBeans 7.1 IDE: Shelve and Un-Shelve Changes</title><description>&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://netbeans.org/images_www/collateral/71/nb-banner-71lf.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://netbeans.org/images_www/collateral/71/nb-banner-71lf.png" /&gt;&lt;/a&gt;&lt;/div&gt;
The &lt;a href="http://netbeans.org/"&gt;NetBeans 7.1 IDE&lt;/a&gt; introduces a really cool new feature called shelving. This allows a developer to make changes to a project without committing them to a source control system.&lt;br /&gt;
&lt;br /&gt;
How often have you wanted to try out some new idea on your code without having to check it into source control? This allows you to do just that.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;What is shelving?&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Shelving creates a patch based on whether an individual file, files, or project is selected. This is a standard patch file and can be applied from the command line, or sent via email to others.&lt;br /&gt;
&lt;br /&gt;
A nice feature is that you can provide meaningful names to the shelved changes. This makes it easier to go back later and apply them to your project.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Note:&lt;/b&gt;&amp;nbsp;This functionality is only available for &lt;a href="http://subversion.apache.org/"&gt;Subversion&lt;/a&gt; and &lt;a href="http://mercurial.selenic.com/"&gt;Mercurial&lt;/a&gt; based projects.&lt;br /&gt;
&lt;br /&gt;
I created a five minute video to demonstrate this really cool new feature.&lt;br /&gt;
&lt;br /&gt;
&lt;iframe allowfullscreen="" frameborder="0" height="480" src="http://www.youtube.com/embed/o-0M1-CsztA" width="640"&gt;&lt;/iframe&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/36773632-8705490509123905516?l=javaevangelist.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/1yi47w_PNpkMNOnXu-9KZ2oNV7k/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/1yi47w_PNpkMNOnXu-9KZ2oNV7k/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/1yi47w_PNpkMNOnXu-9KZ2oNV7k/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/1yi47w_PNpkMNOnXu-9KZ2oNV7k/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/JavaEvangelistJohnYearysBlog/~4/trRcNRjCRfA" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/JavaEvangelistJohnYearysBlog/~3/trRcNRjCRfA/netbeans-71-ide-shelve-and-un-shelve.html</link><author>noreply@blogger.com (John Yeary)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://img.youtube.com/vi/o-0M1-CsztA/default.jpg" height="72" width="72" /><thr:total>2</thr:total><feedburner:origLink>http://javaevangelist.blogspot.com/2012/01/netbeans-71-ide-shelve-and-un-shelve.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-36773632.post-3494214604443763716</guid><pubDate>Sat, 21 Jan 2012 22:36:00 +0000</pubDate><atom:updated>2012-01-21T18:02:57.293-05:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">example</category><category domain="http://www.blogger.com/atom/ns#">Java</category><category domain="http://www.blogger.com/atom/ns#">JDK7</category><category domain="http://www.blogger.com/atom/ns#">tutorial</category><category domain="http://www.blogger.com/atom/ns#">Netbeans</category><title>NetBeans 7.1 IDE: Inspect and Transform to JDK 7</title><description>&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://netbeans.org/images_www/collateral/71/nb71box.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://netbeans.org/images_www/collateral/71/nb71box.png" /&gt;&lt;/a&gt;&lt;/div&gt;
I gave a talk this month at the &lt;a href="http://greenjug.java.net/"&gt;Greenville Java Users Group (GreenJUG)&lt;/a&gt; on the new features, and tips &amp;amp; tricks in the new &lt;a href="http://netbeans.org/"&gt;NetBeans 7.1 IDE&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
One of the most popular demonstrations was using NetBeans to download &lt;a href="http://commons.apache.org/io/"&gt;Apache Commons IO&lt;/a&gt; from the &lt;a href="http://subversion.apache.org/"&gt;Apache Subversion&lt;/a&gt; repository, open the &lt;a href="http://maven.apache.org/"&gt;Apache Maven&lt;/a&gt; project natively, and upgrade it from JDK 5 to JDK 7.&lt;br /&gt;
&lt;br /&gt;
This is a real world demonstration of the incredible and powerful new capabilities in the IDE. What is particularly interesting is that the &lt;a href="http://commons.apache.org/io/"&gt;Apache Commons IO&lt;/a&gt; project does a great job of providing &amp;nbsp;unit tests to validate our changes.&lt;br /&gt;
&lt;br /&gt;
I created a 20 minute video which demonstrates this really vital new functionality to help you migrate your projects to JDK 7.&lt;br /&gt;
&lt;br /&gt;
&lt;iframe allowfullscreen="" frameborder="0" height="480" src="http://www.youtube.com/embed/momyEYyVbrU" width="640"&gt;&lt;/iframe&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/36773632-3494214604443763716?l=javaevangelist.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/AmDYTQZlRGbcVSj5TyOkjEHO2QE/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/AmDYTQZlRGbcVSj5TyOkjEHO2QE/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/AmDYTQZlRGbcVSj5TyOkjEHO2QE/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/AmDYTQZlRGbcVSj5TyOkjEHO2QE/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/JavaEvangelistJohnYearysBlog/~4/x3givXocYmI" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/JavaEvangelistJohnYearysBlog/~3/x3givXocYmI/netbeans-71-ide-inspect-and-transform.html</link><author>noreply@blogger.com (John Yeary)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://img.youtube.com/vi/momyEYyVbrU/default.jpg" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://javaevangelist.blogspot.com/2012/01/netbeans-71-ide-inspect-and-transform.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-36773632.post-8016340240809620692</guid><pubDate>Fri, 20 Jan 2012 21:02:00 +0000</pubDate><atom:updated>2012-01-20T16:02:14.048-05:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">example</category><category domain="http://www.blogger.com/atom/ns#">Programming</category><category domain="http://www.blogger.com/atom/ns#">JavaEE</category><category domain="http://www.blogger.com/atom/ns#">JEE5</category><category domain="http://www.blogger.com/atom/ns#">tutorial</category><category domain="http://www.blogger.com/atom/ns#">Jersey</category><category domain="http://www.blogger.com/atom/ns#">glassfish</category><category domain="http://www.blogger.com/atom/ns#">JAX-RS</category><category domain="http://www.blogger.com/atom/ns#">Netbeans</category><category domain="http://www.blogger.com/atom/ns#">JSR-311</category><category domain="http://www.blogger.com/atom/ns#">JEE6</category><title>Jersey Tip of the Day: Use GZIP compression</title><description>JAX-RS (Jersey) offers a GZIP filter to compress data for responses, and to handle GZIP compressed requests. This functionality is very easy to enable, and is configurable for both requests, and responses.
&lt;script class="brush: xml" type="syntaxhighlighter"&gt;
&lt;![CDATA[
     &lt;init-param&gt;
         &lt;param-name&gt;com.sun.jersey.spi.container.ContainerRequestFilters&lt;/param-name&gt;
         &lt;param-value&gt;com.sun.jersey.api.container.filter.GZIPContentEncodingFilter&lt;/param-value&gt;
     &lt;/init-param&gt;
     &lt;init-param&gt;
         &lt;param-name&gt;com.sun.jersey.spi.container.ContainerResponseFilters&lt;/param-name&gt;
         &lt;param-value&gt;com.sun.jersey.api.container.filter.GZIPContentEncodingFilter&lt;/param-value&gt;
     &lt;/init-param&gt;
]]&gt;
&lt;/script&gt;

That does not get much easier.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;You can prove that this works by querying your resource with Firebug, or Developer Tools (depending on browser). You can also confirm that it is working by performing a query like:

&lt;br /&gt;
&lt;blockquote&gt;
curl -HAccept-Encoding:gzip -HAccept:application/json http://localhost:8080/content-coding-gzip/webresources/widget &amp;gt; json.gz &lt;br /&gt;
gzip -v -l json.gz 

&lt;/blockquote&gt;
&lt;pre&gt;method  crc     date  time           compressed        uncompressed  ratio uncompressed_name
defla 3a79ae18 Jan 20 15:25                1370                3389  60.3% json
&lt;/pre&gt;
&lt;br /&gt;
The only issue that I have with the currently implemented version is that it does not use configurable compression level.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/36773632-8016340240809620692?l=javaevangelist.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/hQkaUunh8VlP3Ntf8dJ8rKIBDyA/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/hQkaUunh8VlP3Ntf8dJ8rKIBDyA/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/hQkaUunh8VlP3Ntf8dJ8rKIBDyA/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/hQkaUunh8VlP3Ntf8dJ8rKIBDyA/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/JavaEvangelistJohnYearysBlog/~4/zDRAOldAPrg" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/JavaEvangelistJohnYearysBlog/~3/zDRAOldAPrg/jersey-tip-of-day-use-gzip-compression.html</link><author>noreply@blogger.com (John Yeary)</author><thr:total>0</thr:total><feedburner:origLink>http://javaevangelist.blogspot.com/2012/01/jersey-tip-of-day-use-gzip-compression.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-36773632.post-3894262612944051896</guid><pubDate>Tue, 17 Jan 2012 16:52:00 +0000</pubDate><atom:updated>2012-01-17T11:52:32.863-05:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">example</category><category domain="http://www.blogger.com/atom/ns#">Programming</category><category domain="http://www.blogger.com/atom/ns#">JavaEE</category><category domain="http://www.blogger.com/atom/ns#">JEE5</category><category domain="http://www.blogger.com/atom/ns#">tutorial</category><category domain="http://www.blogger.com/atom/ns#">Jersey</category><category domain="http://www.blogger.com/atom/ns#">glassfish</category><category domain="http://www.blogger.com/atom/ns#">JAX-RS</category><category domain="http://www.blogger.com/atom/ns#">Netbeans</category><category domain="http://www.blogger.com/atom/ns#">JSR-311</category><category domain="http://www.blogger.com/atom/ns#">JEE6</category><title>JAX-RS Tip of the Day: Use OPTIONS Method to Determine Resource Capabilities</title><description>Did you know that you can make an &lt;a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.2"&gt;OPTIONS &lt;/a&gt;method call to a JAX-RS resource to determine its capabilites? JAX-RS supports a complete set of HTTP methods including OPTIONS.&lt;br /&gt;
&lt;br /&gt;
If you make a specific URI request to a resource, it will return the supported methods like GET, PUT, HEAD, and &lt;a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.2"&gt;OPTIONS&lt;/a&gt;. In addition, Jersey supports returning the &lt;a href="http://en.wikipedia.org/wiki/Web_Application_Description_Language"&gt;WADL&lt;/a&gt; file by default. This allows tools like NetBeans to take advantage of the resource.&lt;br /&gt;
&lt;br /&gt;
So I guess some examples are in order. The first example is a request to the server URI which in this case is GlassFish 3.1.1. This is followed by a request to a specific resource on the server instance.

&lt;blockquote&gt;
curl -X OPTIONS -v http://localhost:8080
&lt;/blockquote&gt;

&lt;pre&gt;
* About to connect() to localhost port 8080 (#0)
*   Trying ::1... Operation not permitted
*   Trying 127.0.0.1... connected
&gt; OPTIONS / HTTP/1.1
&gt; User-Agent: curl/7.22.0 (i686-pc-cygwin) libcurl/7.22.0 OpenSSL/0.9.8r zlib/1.2.5 libidn/1.22 libssh2/1.2.7
&gt; Host: localhost:8080
&gt; Accept: */*
&gt;
&lt; HTTP/1.1 200 OK
&lt; X-Powered-By: Servlet/3.0 JSP/2.2 (GlassFish Server Open Source Edition 3.1.1 Java/Sun Microsystems Inc./1.6)
&lt; Server: GlassFish Server Open Source Edition 3.1.1
&lt; Allow: GET, HEAD, POST, PUT, DELETE, TRACE, OPTIONS
&lt; Content-Length: 0
&lt; Date: Tue, 17 Jan 2012 14:31:17 GMT
&lt;
* Connection #0 to host localhost left intact
* Closing connection #0
&lt;/pre&gt;

As you can see the command reports that GlassFish supports all standard HTTP 1.1 methods as denoted by the &lt;i&gt;Allow:&lt;/i&gt; header. This example calls a specific resource on the server which only supports a subset of the HTTP methods based on the annotations in the resource. The methods always supported by a resource are HEAD and OPTIONS, but this has two methods annotated as &lt;code&gt;@GET&lt;/code&gt; and &lt;code&gt;@POST&lt;/code&gt;. Additionally, not that the &lt;i&gt;Content-Type: application/vnd.sun.wadl+xml&lt;/i&gt; is returned which includes the WADL for this particular resource.

&lt;blockquote&gt;
curl -X OPTIONS -v http://localhost:8080/RESTApproachFormParameter/resources/example
&lt;/blockquote&gt;

&lt;pre&gt;
* About to connect() to localhost port 8080 (#0)
*   Trying ::1... Operation not permitted
*   Trying 127.0.0.1... connected
&gt; OPTIONS /RESTApproachFormParameter/resources/example HTTP/1.1
&gt; User-Agent: curl/7.22.0 (i686-pc-cygwin) libcurl/7.22.0 OpenSSL/0.9.8r zlib/1.2.5 libidn/1.22 libssh2/1.2.7
&gt; Host: localhost:8080
&gt; Accept: */*
&gt;
&lt; HTTP/1.1 200 OK
&lt; X-Powered-By: Servlet/3.0 JSP/2.2 (GlassFish Server Open Source Edition 3.1.1 Java/Sun Microsystems Inc./1.6)
&lt; Server: GlassFish Server Open Source Edition 3.1.1
&lt; Allow: OPTIONS,POST,GET,HEAD
&lt; Content-Type: application/vnd.sun.wadl+xml
&lt; Content-Length: 1085
&lt; Date: Tue, 17 Jan 2012 15:01:49 GMT
&lt;
* Connection #0 to host localhost left intact
* Closing connection #0
&lt;/pre&gt;
&lt;script type="syntaxhighlighter" class="brush: xml"&gt;&lt;![CDATA[
&lt;?xml version="1.0" encoding="UTF-8" standalone="yes"?&gt;
&lt;application xmlns="http://research.sun.com/wadl/2006/10"&gt;
 &lt;doc xmlns:jersey="http://jersey.java.net/" jersey:generatedBy="Jersey: 1.8 06/24/2011 12:17 PM"/&gt;
 &lt;resources base="http://localhost:8080/RESTApproachFormParameter/resources/"&gt;
  &lt;resource path="example"&gt;
   &lt;method id="get" name="GET"&gt;
    &lt;response&gt;
     &lt;representation mediaType="application/json"/&gt;
    &lt;/response&gt;
   &lt;/method&gt;
   &lt;method id="post" name="POST"&gt;
    &lt;request&gt;
     &lt;representation mediaType="application/x-www-form-urlencoded"&gt;
      &lt;param xmlns:xs="http://www.w3.org/2001/XMLSchema" name="name" style="query" type="xs:string"/&gt;
      &lt;param xmlns:xs="http://www.w3.org/2001/XMLSchema" name="value" style="query" type="xs:string"/&gt;
     &lt;/representation&gt;
    &lt;/request&gt;
    &lt;response&gt;
     &lt;representation mediaType="application/json"/&gt;
    &lt;/response&gt;
   &lt;/method&gt;
   &lt;resource path="{index}"&gt;
    &lt;param xmlns:xs="http://www.w3.org/2001/XMLSchema" name="index" style="template" type="xs:int"/&gt;
    &lt;method id="get" name="GET"&gt;
     &lt;response&gt;
      &lt;representation mediaType="application/json"/&gt;
     &lt;/response&gt;
    &lt;/method&gt;
   &lt;/resource&gt;
  &lt;/resource&gt;
 &lt;/resources&gt;
&lt;/application&gt;
]]&gt;&lt;/script&gt;

In summary, you can take advantage of the OPTIONS method to determine what a particular resource will provide for you without any knowledge of the subject domain.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/36773632-3894262612944051896?l=javaevangelist.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/VO6yvwK3385T4RfWdzauId_kons/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/VO6yvwK3385T4RfWdzauId_kons/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/VO6yvwK3385T4RfWdzauId_kons/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/VO6yvwK3385T4RfWdzauId_kons/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/JavaEvangelistJohnYearysBlog/~4/o4wnaUhxs5w" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/JavaEvangelistJohnYearysBlog/~3/o4wnaUhxs5w/jax-rs-tip-of-day-use-options-method-to.html</link><author>noreply@blogger.com (John Yeary)</author><thr:total>0</thr:total><feedburner:origLink>http://javaevangelist.blogspot.com/2012/01/jax-rs-tip-of-day-use-options-method-to.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-36773632.post-1966644075616633541</guid><pubDate>Fri, 13 Jan 2012 16:12:00 +0000</pubDate><atom:updated>2012-01-13T11:27:28.570-05:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">example</category><category domain="http://www.blogger.com/atom/ns#">glassfish</category><category domain="http://www.blogger.com/atom/ns#">Netbeans</category><title>GlassFish Default Encoding ISO-8859-1</title><description>GlassFish &lt;a href="http://docs.oracle.com/cd/E18930_01/html/821-2418/beaft.html#beafw"&gt;default encoding&lt;/a&gt; returns text encoded as &lt;a href="http://en.wikipedia.org/wiki/ISO/IEC_8859-1"&gt;ISO-8859-1&lt;/a&gt;. This is based on the Hypertext Transfer Protocol -- HTTP/1.1 RFC &lt;a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.7.1"&gt;3.7.1 Canonicalization and Text Defaults&lt;/a&gt; which requires the default encoding for text to be returned in this manner.
&lt;br /&gt;
&lt;br /&gt;
Web application developers often use UTF-8 as the encoding in their applications, but fail to change the server defaults. This applies to anything which uses Servlets (including JSP, and JSF). You can change the defaults in the &lt;b&gt;sun-web.xml&lt;/b&gt;, or &lt;b&gt;glassfish-web.xml&lt;/b&gt; as shown below by setting the &lt;b&gt;&lt;a href="http://docs.oracle.com/cd/E18930_01/html/821-2417/beavn.html#SJSASEEADGbeavn"&gt;parameter-encoding&lt;/a&gt;&lt;/b&gt; element. This remove a number of default encoding warnings like this:&lt;br /&gt;
&lt;pre&gt;WARNING: WEB0500: default-locale attribute of locale-charset-info element is being ignored

WARNING: PWC4011: Unable to set request character encoding to UTF-8 from context /, because request parameters have already been read, or ServletRequest.getReader() has already been called.
&lt;/pre&gt;
&lt;br /&gt;
&lt;script class="brush: xml" type="syntaxhighlighter"&gt;
&lt;![CDATA[
&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;!DOCTYPE glassfish-web-app PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Servlet 3.0//EN" 
"http://glassfish.org/dtds/glassfish-web-app_3_0-1.dtd"&gt;
&lt;glassfish-web-app error-url=""&gt;
    &lt;class-loader delegate="true"/&gt;

    &lt;!-- Change the default character encoding from ISO-8859-1 to UTF-8 --&gt;
    &lt;parameter-encoding default-charset="UTF-8"/&gt;

    &lt;jsp-config&gt;
        &lt;property name="keepgenerated" value="true"&gt;
            &lt;description&gt;Keep a copy of the generated servlet class' java code.&lt;/description&gt;
        &lt;/property&gt;
    &lt;/jsp-config&gt;
&lt;/glassfish-web-app&gt;
]]&gt;
&lt;/script&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/36773632-1966644075616633541?l=javaevangelist.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/C6_qf2J5EW_pD4HbgW9a6yXF1cw/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/C6_qf2J5EW_pD4HbgW9a6yXF1cw/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/C6_qf2J5EW_pD4HbgW9a6yXF1cw/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/C6_qf2J5EW_pD4HbgW9a6yXF1cw/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/JavaEvangelistJohnYearysBlog/~4/_rFZlq4q5_4" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/JavaEvangelistJohnYearysBlog/~3/_rFZlq4q5_4/glassfish-default-encoding-iso-8859-1.html</link><author>noreply@blogger.com (John Yeary)</author><thr:total>0</thr:total><feedburner:origLink>http://javaevangelist.blogspot.com/2012/01/glassfish-default-encoding-iso-8859-1.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-36773632.post-7871168559390585217</guid><pubDate>Thu, 12 Jan 2012 19:33:00 +0000</pubDate><atom:updated>2012-01-12T15:52:14.060-05:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">AJAX</category><category domain="http://www.blogger.com/atom/ns#">JAXB</category><category domain="http://www.blogger.com/atom/ns#">JEE5</category><category domain="http://www.blogger.com/atom/ns#">Jersey</category><category domain="http://www.blogger.com/atom/ns#">JAX-RS</category><category domain="http://www.blogger.com/atom/ns#">maven</category><category domain="http://www.blogger.com/atom/ns#">JEE6</category><category domain="http://www.blogger.com/atom/ns#">JSR-311</category><category domain="http://www.blogger.com/atom/ns#">example</category><category domain="http://www.blogger.com/atom/ns#">Programming</category><category domain="http://www.blogger.com/atom/ns#">JSON</category><category domain="http://www.blogger.com/atom/ns#">JavaEE</category><category domain="http://www.blogger.com/atom/ns#">tutorial</category><category domain="http://www.blogger.com/atom/ns#">glassfish</category><category domain="http://www.blogger.com/atom/ns#">Netbeans</category><title>JAX-RS Tip of the Day: Client Content Negotiation</title><description>One of the less discussed aspects of JAX-RS based on the HTTP 1.1 specification is client negotiation. We often write our applications from the server side and expect the client to send us an &lt;code&gt;Accept: */*&lt;/code&gt; header which details which media types the client can accept. The server simply returns whatever we have coded for example &lt;code&gt;@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})&lt;/code&gt;. 
However I bet a number of you have seen something like this before:

&lt;br /&gt;
&lt;blockquote&gt;
http://www.example.com/documents/mydoc?format=doc
&lt;br /&gt;
http://www.example.com/documents/mydoc.xml
&lt;/blockquote&gt;
The first example is not very subtle. It tells you the client wants a mydoc.doc by requesting a specific format. The second example is more subtle, and the end user (client) may not notice. I made it a "little" more obvious by changing it to .xml. However, most folks would have missed it if I used mydoc.doc. You would have assumed it was a MS Word document to start with. In actuality, the media type returned here is controlled by the file extension.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Note: &lt;/b&gt;Updated the source code to include header based negotiation, but this is just mimicking server content negotiation.
&lt;br/&gt;&lt;br/&gt;
In the attached Apache Maven project developed on NetBeans 7.1:&amp;nbsp;&lt;a href="http://commondatastorage.googleapis.com/bluelotussoftware/code/jersey-content-negotiation.zip"&gt;jersey-content-negotiation.zip&lt;/a&gt;. I demonstrate how to do it.
&lt;br /&gt;
&lt;br /&gt;
The first example returns JSON by default, and other media formats as requested. If it does not understand the media type requested, it simply returns plain text.&lt;br /&gt;
&lt;br /&gt;
On the second example which uses the media type extension, I return a 400 - Bad Request instead of plain text like the first example. This subtlety is based on the fact that the client is requesting a specific type based on extension. If you ask for .pdf and get .txt, the result may cause an unanticipated consequence so it is better to throw an exception.&lt;br /&gt;
&lt;br /&gt;
The mixed media type returns are possible because of the &lt;code&gt;Response&lt;/code&gt; being wrapped as demonstrated in a previous post:&amp;nbsp;&lt;a href="http://javaevangelist.blogspot.com/2012/01/jax-rs-tip-of-day-use-response-to-wrap.html"&gt;JAX-RS Tip of the Day: Use Response to wrap... Responses&lt;/a&gt;.&lt;br /&gt;
&lt;h2&gt;ContentNegotiationResource.java&lt;/h2&gt;
&lt;hr /&gt;
&lt;script class="brush: js" type="syntaxhighlighter"&gt;
&lt;![CDATA[
/*
 *  Copyright 2012 Blue Lotus Software, LLC..
 *  Copyright 2012 John Yeary &lt;john.yeary@bluelotussoftware.com&gt;.
 *
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/*
 * $Id: ContentNegotiationResource.java,v 9b1064fb9d26 2012/01/12 18:14:54 jyeary $
 */
package com.bluelotussoftware.example.jersey;

import com.bluelotussoftware.example.jersey.misc.Widget;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

/**
 * Example resource class hosted at the URI path "/example" example
 *
 * @author John Yeary &lt;john.yeary@bluelotussoftware.com&gt;
 * @version 1.0
 */
@Path("/example")
public class ContentNegotiationResource {

    private Widget widget;

    public ContentNegotiationResource() {
        widget = new Widget("X", "Y");
    }

    /**
     * Performs the client requested content negotiation based on format
     * requested.
     *
     * @param format may be one of "json", or "xml". The default is "json", and
     * an unknown value will be processed as {@link javax.ws.rs.core.MediaType.TEXT_PLAIN}.
     * @return a {@code Response} which wraps the entity which may be JSON, XML,
     * or text.
     */
    @GET
    public Response getByFormat(@QueryParam(value = "format") @DefaultValue(value = "json") String format) {

        if ("json".equals(format)) {
            return Response.ok(widget, MediaType.APPLICATION_JSON).build();
        } else if ("xml".equals(format)) {
            return Response.ok(widget, MediaType.APPLICATION_XML).build();
        } else {
            return Response.ok("widget : " + widget.toString(), MediaType.TEXT_PLAIN).build();
        }
    }

    /**
     * Performs client requested content negotiation based on media type
     * requested based on extension.
     *
     * @param type media type extension which may be either ".json", or ".xml".
     * All other requested types will result in a {@link javax.ws.rs.WebApplicationException}
     * which has a {@link javax.ws.rs.core.Response.Status#BAD_REQUEST}. &lt;p&gt;
* &lt;b&gt;Note: &lt;/b&gt;There are no default types returned since this is specific
     * to the extension requested. &lt;/p&gt;
* @return a {@code Response} which wraps the entity which may be JSON, or
     * XML.
     */
    @GET
    @Path(value = "widget.{type}")
    public Response getByType(@PathParam(value = "type") String type) {

        if ("json".equals(type)) {
            return Response.ok(widget, MediaType.APPLICATION_JSON).build();
        } else if ("xml".equals(type)) {
            return Response.ok(widget, MediaType.APPLICATION_XML).build();
        } else {
            /*
             * We will throw a WebApplcationException to indicate that we don't
             * accept the requested type.
             */
            throw new WebApplicationException(Response.Status.BAD_REQUEST);
        }
    }
}
]]&gt;
&lt;/script&gt;

&lt;br /&gt;
&lt;table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-zcX9c0IgFa0/Tw8qbReEJcI/AAAAAAAABUc/B7OrboJCS94/s1600/JerseyClientNegotiation.png" imageanchor="1" style="clear: left; margin-bottom: 1em; margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="390" src="http://1.bp.blogspot.com/-zcX9c0IgFa0/Tw8qbReEJcI/AAAAAAAABUc/B7OrboJCS94/s640/JerseyClientNegotiation.png" width="640" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;Client Negotiation Examples&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/36773632-7871168559390585217?l=javaevangelist.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/lFO6POTjiVx0NujFXRqe5Vx_8X8/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/lFO6POTjiVx0NujFXRqe5Vx_8X8/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/lFO6POTjiVx0NujFXRqe5Vx_8X8/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/lFO6POTjiVx0NujFXRqe5Vx_8X8/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/JavaEvangelistJohnYearysBlog/~4/whkEoctyM6g" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/JavaEvangelistJohnYearysBlog/~3/whkEoctyM6g/jax-rs-tip-of-day-client-negotiation.html</link><author>noreply@blogger.com (John Yeary)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/-zcX9c0IgFa0/Tw8qbReEJcI/AAAAAAAABUc/B7OrboJCS94/s72-c/JerseyClientNegotiation.png" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://javaevangelist.blogspot.com/2012/01/jax-rs-tip-of-day-client-negotiation.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-36773632.post-2136137866699867666</guid><pubDate>Wed, 11 Jan 2012 21:15:00 +0000</pubDate><atom:updated>2012-01-11T17:45:50.636-05:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">AJAX</category><category domain="http://www.blogger.com/atom/ns#">JAXB</category><category domain="http://www.blogger.com/atom/ns#">JEE5</category><category domain="http://www.blogger.com/atom/ns#">Jersey</category><category domain="http://www.blogger.com/atom/ns#">JAX-RS</category><category domain="http://www.blogger.com/atom/ns#">JEE6</category><category domain="http://www.blogger.com/atom/ns#">JSR-311</category><category domain="http://www.blogger.com/atom/ns#">example</category><category domain="http://www.blogger.com/atom/ns#">Programming</category><category domain="http://www.blogger.com/atom/ns#">JSON</category><category domain="http://www.blogger.com/atom/ns#">JavaEE</category><category domain="http://www.blogger.com/atom/ns#">tutorial</category><category domain="http://www.blogger.com/atom/ns#">glassfish</category><category domain="http://www.blogger.com/atom/ns#">Netbeans</category><title>JAX-RS Tip of the Day: Use Response to wrap... Responses</title><description>One of the really nice features of JAX-RS is the ability to implement fine grained control over the response returned from the server based on the client request. The &lt;code&gt;&lt;a href="http://jersey.java.net/nonav/apidocs/latest/jersey/javax/ws/rs/core/Response.ResponseBuilder.html"&gt;Response.ResponseBuilder&lt;/a&gt;&lt;/code&gt; gives us incredible flexibility to generate the response. Since it uses the builder pattern, it is easy to daisy-chain the information we want into a custom response.&lt;br /&gt;
&lt;br /&gt;
I would highly recommend that you consider returning a custom response for all requests. I would like to explain with an example. I would like to perform a &lt;code&gt;@POST&lt;/code&gt; request where I am creating a new object on the server. Since it is a HTTP 1.1 request, I look at &lt;a href="http://www.w3.org/Protocols/rfc2616/rfc2616.html"&gt;Hypertext Transfer Protocol -- HTTP/1.1 (RFC-2616)&lt;/a&gt; to see what I &lt;b&gt;must&lt;/b&gt;, &lt;b&gt;should&lt;/b&gt;, and &lt;b&gt;may&lt;/b&gt; return. The difference in the word choices has specific meaning in the specification. In my case, I would like to be completely compliant.
&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote&gt;
10.2.2 201 Created &lt;br/&gt;

The request has been fulfilled and resulted in a new resource being created. The newly created resource can be referenced by the URI(s) returned in the entity of the response, with the most specific URI for the resource given by a Location header field. The response SHOULD include an entity containing a list of resource characteristics and location(s) from which the user or user agent can choose the one most appropriate. The entity format is specified by the media type given in the Content-Type header field. The origin server MUST create the resource before returning the 201 status code. If the action cannot be carried out immediately, the server SHOULD respond with 202 (Accepted) response instead.
&lt;br/&gt;
A 201 response MAY contain an ETag response header field indicating the current value of the entity tag for the requested variant just created, see section 14.19.
&lt;/blockquote&gt;
&lt;br /&gt;
OK, the basic response must return 201 - Created status, and a Location header. It should contain an entity (which may only be entity-headers) and may contain an ETag. This is all very easy to do with Jersey.

&lt;script class="brush: java" type="syntaxhighlighter"&gt;
&lt;![CDATA[
    @POST
    @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
    @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
    public Response post(@FormParam("name") String name, @FormParam("value") String value) {
        Widget widget = new Widget(name, value);
        ws.add(widget);
        int index = ws.getWidgets().indexOf(widget);
        UriBuilder uriBuilder = UriBuilder.fromUri(uriInfo.getRequestUri());
        uriBuilder.path("{index}");
        EntityTag etag = new EntityTag(Hex.encodeHexString(widget.toString().getBytes()));
        return Response.created(uriBuilder.build(index)).
                tag(etag).
                entity(widget).
                type(MediaType.APPLICATION_JSON).
                build();
    }
]]&gt;
&lt;/script&gt;

As you can see from the code snippet, we read the &lt;code&gt;@FormParam&lt;/code&gt; information from a form, and create an object which we add to a &lt;code&gt;List&amp;lt;Widget%gt;&lt;/code&gt; objects signified by the &lt;code&gt;ws.add(widget)&lt;/code&gt; we get the index value for use in our URI. Next we create a URI from our request, and add a path to it for our index.&lt;br /&gt;
&lt;br /&gt;
Finally we use &lt;a href="http://commons.apache.org/codec/"&gt;Apache Commons Codec&lt;/a&gt; &lt;code&gt;Hex&lt;/code&gt; to generate a hex string for our ETag.

Finally this is all combined in a &lt;code&gt;Response&lt;/code&gt; sent back to the client. This can be seen below.

&lt;script class="brush: text" type="syntaxhighlighter"&gt;
&lt;![CDATA[
HTTP/1.1 201 - Created
X-Powered-By: Servlet/3.0 JSP/2.2 (GlassFish Server Open Source Edition 3.1.1 Java/Sun Microsystems Inc./1.6)
Server: GlassFish Server Open Source Edition 3.1.1
Location: http://localhost:8080/jersey/resources/example/0
Etag: "7b226e616d65223a2258222c2276616c7565223a2259227d"
Content-Type: application/json
Transfer-Encoding: chunked
Date: Wed, 11 Jan 2012 21:10:35 GMT
{"name":"X","value":"Y"}
]]&gt;
&lt;/script&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/36773632-2136137866699867666?l=javaevangelist.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/CAaQlTAYNwsi4YuC5ydfx4F82cA/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/CAaQlTAYNwsi4YuC5ydfx4F82cA/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/CAaQlTAYNwsi4YuC5ydfx4F82cA/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/CAaQlTAYNwsi4YuC5ydfx4F82cA/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/JavaEvangelistJohnYearysBlog/~4/QVTq_rD1YB0" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/JavaEvangelistJohnYearysBlog/~3/QVTq_rD1YB0/jax-rs-tip-of-day-use-response-to-wrap.html</link><author>noreply@blogger.com (John Yeary)</author><thr:total>0</thr:total><feedburner:origLink>http://javaevangelist.blogspot.com/2012/01/jax-rs-tip-of-day-use-response-to-wrap.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-36773632.post-5906905749351214002</guid><pubDate>Tue, 10 Jan 2012 14:20:00 +0000</pubDate><atom:updated>2012-01-09T09:55:45.533-05:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">example</category><category domain="http://www.blogger.com/atom/ns#">Programming</category><category domain="http://www.blogger.com/atom/ns#">JSON</category><category domain="http://www.blogger.com/atom/ns#">JAXB</category><category domain="http://www.blogger.com/atom/ns#">JavaEE</category><category domain="http://www.blogger.com/atom/ns#">AJAX</category><category domain="http://www.blogger.com/atom/ns#">JEE5</category><category domain="http://www.blogger.com/atom/ns#">tutorial</category><category domain="http://www.blogger.com/atom/ns#">Jersey</category><category domain="http://www.blogger.com/atom/ns#">JAX-RS</category><category domain="http://www.blogger.com/atom/ns#">JSR-311</category><category domain="http://www.blogger.com/atom/ns#">JEE6</category><title>Interesting Articles on JAX-RS</title><description>&lt;h2&gt;

What do I Read?&lt;/h2&gt;
I was asked what articles I really like on Jersey, and how to learn more about it. Here is an incomplete list.&lt;br /&gt;
&lt;br /&gt;
If you find more really good ones, please post comments, and I will add them to the list if I like them.
&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://codahale.com/what-makes-jersey-interesting-parameter-classes/"&gt;What Makes Jersey Interesting: Parameter Classes&lt;/a&gt; - This article includes examples which explain parametrized classes being used in &lt;a href="http://jersey.java.net/"&gt;Jersey&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;&lt;a href="http://codahale.com/what-makes-jersey-interesting-injection-providers/"&gt;What Makes Jersey Interesting: Injection Providers&lt;/a&gt; - This article demonstrates a method of doing dependency injection in &lt;a href="http://jersey.java.net/"&gt;Jersey&lt;/a&gt;. Specifically, it addresses using the &lt;a href="http://jersey.java.net/nonav/apidocs/1.11/jersey/index.html?overview-summary.html"&gt;&lt;code&gt;@Context&lt;/code&gt;&lt;/a&gt; annotation to inject a &lt;a href="http://jersey.java.net/nonav/apidocs/1.11/jersey/index.html?overview-summary.html"&gt;&lt;code&gt;UriInfo&lt;/code&gt;&lt;/a&gt; object.&lt;/li&gt;
&lt;li&gt;&lt;a href="http://coenraets.org/blog/2011/12/restful-services-with-jquery-and-java-using-jax-rs-and-jersey/"&gt;RESTful services with jQuery and Java using JAX-RS and Jersey&lt;/a&gt; - This is a great article on using &lt;a href="http://jquery.com/"&gt;jQuery &lt;/a&gt;with JAX-RS. It also demonstrates using &lt;code&gt;curl&lt;/code&gt; to test your services and includes code and sample syntax. This article is very professionally done.&lt;/li&gt;
&lt;li&gt;&lt;a href="http://coenraets.org/blog/2011/11/building-restful-services-with-java-using-jax-rs-and-jersey-sample-application/"&gt;Building RESTful Services with Java Using JAX-RS and Jersey — Sample Application&lt;/a&gt; - A demo application including code which demonstrates JAX-RS (&lt;a href="http://jersey.java.net/"&gt;Jersey&lt;/a&gt;). It is very well done, and it is easy to follow.&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.mkyong.com/webservices/jax-rs/jax-rs-formparam-example/"&gt;JAX-RS @FormParam example&lt;/a&gt; - This simple demo application uses an HTML based form to submit to a &lt;a href="http://jersey.java.net/"&gt;Jersey&lt;/a&gt; based REST service.&lt;/li&gt;
&lt;li&gt;&lt;a href="http://blogs.oracle.com/sandoz/entry/formparam"&gt;@FormParam&lt;/a&gt; - This is a simple to the point version of using &lt;code&gt;@FormParam&lt;/code&gt;. It also explains how to test it using &lt;a href="http://jersey.java.net/"&gt;Jersey&lt;/a&gt; client.&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.theserverlabs.com/blog/2009/01/12/rest-web-services-with-jaxb-jax-rs-and-sun-jersey/"&gt;REST web services with JAXB, JAX-RS and Sun Jersey&lt;/a&gt; - A well written article on using &lt;a href="http://jaxb.java.net/"&gt;JAXB &lt;/a&gt;along with &lt;a href="http://jersey.java.net/"&gt;Jersey&lt;/a&gt; to create applications. The article includes examples of using &lt;code&gt;curl&lt;/code&gt; to test the results.&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.mkyong.com/webservices/jax-rs/jax-rs-matrixparam-example/"&gt;JAX-RS @MatrixParam example&lt;/a&gt; - An example application that demonstrates &lt;code&gt;@MatrixParam&lt;/code&gt; usage.&lt;/li&gt;
&lt;li&gt;&lt;a href="http://stackoverflow.com/questions/8194408/how-to-access-parameters-in-a-restful-post-method"&gt;How to access parameters in a RESTful POST method&lt;/a&gt; - Multiple examples of how to get parameters from a POST.&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.vogella.de/articles/REST/article.html"&gt;REST with Java (JAX-RS) using Jersey - Tutorial&lt;/a&gt; - This is a superb article on JAX-RS and is very professionally done.&lt;/li&gt;
&lt;li&gt;&lt;a href="http://macstrac.blogspot.com/2009/01/jax-rs-as-one-web-framework-to-rule.htm"&gt;JAX-RS as the one Java web framework to rule them all?&lt;/a&gt; - This is just a general discussion article with links to other related technologies.&lt;/li&gt;
&lt;/ul&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/36773632-5906905749351214002?l=javaevangelist.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/spXoBYewhODwPnos4F3TXB8vtSU/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/spXoBYewhODwPnos4F3TXB8vtSU/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/spXoBYewhODwPnos4F3TXB8vtSU/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/spXoBYewhODwPnos4F3TXB8vtSU/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/JavaEvangelistJohnYearysBlog/~4/t-xzRmWbXGQ" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/JavaEvangelistJohnYearysBlog/~3/t-xzRmWbXGQ/interesting-articles-on-jax-rs.html</link><author>noreply@blogger.com (John Yeary)</author><thr:total>0</thr:total><feedburner:origLink>http://javaevangelist.blogspot.com/2012/01/interesting-articles-on-jax-rs.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-36773632.post-7743172830042244343</guid><pubDate>Sun, 08 Jan 2012 01:29:00 +0000</pubDate><atom:updated>2012-01-07T20:50:04.133-05:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Web</category><category domain="http://www.blogger.com/atom/ns#">frameworks</category><category domain="http://www.blogger.com/atom/ns#">example</category><category domain="http://www.blogger.com/atom/ns#">mercurial</category><category domain="http://www.blogger.com/atom/ns#">OS X</category><category domain="http://www.blogger.com/atom/ns#">glassfish</category><category domain="http://www.blogger.com/atom/ns#">Web Server</category><category domain="http://www.blogger.com/atom/ns#">Apache2</category><category domain="http://www.blogger.com/atom/ns#">Apache</category><category domain="http://www.blogger.com/atom/ns#">source control</category><title>Using Apache HTTPD (Web Server) mod_proxy with GlassFish and Mercurial</title><description>&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://blog.deborahblum.com/wp-content/uploads/2010/03/mercury_drops_large.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="188" src="http://blog.deborahblum.com/wp-content/uploads/2010/03/mercury_drops_large.jpg" width="200" /&gt;&lt;/a&gt;&lt;/div&gt;
I wrote an article on how to use&amp;nbsp;&lt;a href="http://javaevangelist.blogspot.com/2009/05/secure-mercurial-in-glassfish-using-ssl.html"&gt;Secure Mercurial in GlassFish using SSL&lt;/a&gt;&amp;nbsp;a few weeks ago. After the article was published, I was asked about URL rewriting. I had not really messed with it in the past except with &lt;a href="http://ocpsoft.com/prettyfaces/"&gt;PrettyFaces&lt;/a&gt;&amp;nbsp;(which works like a champ for reference).&lt;br /&gt;
&lt;br /&gt;
I tried a framework called &lt;a href="http://www.tuckey.org/urlrewrite/"&gt;Url Rewrite Filter&lt;/a&gt;&amp;nbsp;which did a decent job of rewriting URLs. It is a simple library added to your project which uses a servlet filter to handle the URL re-writing. Add the filter to the web.xml, and a urlrewrite.xml which handles the rewrites. It works much in the same manner as&amp;nbsp;&lt;a href="http://ocpsoft.com/prettyfaces/"&gt;PrettyFaces&lt;/a&gt;, but is targeted at JSP/Servlets.&lt;br /&gt;
&lt;br /&gt;
In my case, I have an Apple G5 PPC which is the main server for my source repository for &lt;a href="http://mercurial.selenic.com/"&gt;Mercurial&lt;/a&gt;. This presents some challenges since the Java version is limited to 1.5, and therefore &lt;a href="http://glassfish.java.net/"&gt;GlassFish&lt;/a&gt; can't be upgraded to v3 from v2.1.1. I did manage to get GlassFish v3 to run with &lt;a href="http://openjdk.java.net/"&gt;OpenJDK&lt;/a&gt; 1.7 (BSD Port), but the&lt;a href="http://openjdk.java.net/projects/zero/"&gt; Zero VM&lt;/a&gt; is too slow to handle the load. Kurt Miller has a couple of the builds for &lt;a href="http://www.intricatesoftware.com/OpenJDK/macppc/"&gt;Mac PPC&lt;/a&gt; There are a number of reasons for my interest, the primary one for URL rewriting is that GlassFish v3 supports &lt;a href="http://tomcat.apache.org/connectors-doc/ajp/ajpv13a.html"&gt;AJP&lt;/a&gt; out of the box.&lt;br /&gt;
&lt;br /&gt;
&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-VMmuBORRZEc/TwjutOALKOI/AAAAAAAABUM/WeJ4qQap6HY/s1600/gf_mod_jk.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="320" src="http://1.bp.blogspot.com/-VMmuBORRZEc/TwjutOALKOI/AAAAAAAABUM/WeJ4qQap6HY/s320/gf_mod_jk.png" width="266" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;Enabling JK Listener (mod_jk)&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
Using GlassFish v3 would provide a more optimal solution as you can see from the administration console. I decided to try using the mod_jk articles I found for GlassFish v2 from Amy Roh: &lt;a href="http://weblogs.java.net/blog/amyroh/archive/2006/08/glassfish_suppo.html"&gt;GlassFish supports configurable AJP Connector&lt;/a&gt;&amp;nbsp;and Jean-Francois Arcand's &lt;a href="http://jfarcand.wordpress.com/2006/03/17/running-glassfish-with-apache-httpd-3/"&gt;Running GlassFish with Apache httpd&lt;/a&gt;. &amp;nbsp;I tried to combine these with mod_proxy and mod_proxy_ajp. The articles are focused on a specific build, and I was unsuccessful in using them. I am sure it has to framework versions, but I did not want spend too much time troubleshooting.&lt;br /&gt;
&lt;br /&gt;
Finally, I tried using a simple mod_proxy arrangement along with mod_rewrite. This arrangement was surprisingly easy to configure, and worked the first time I tried it.&lt;br /&gt;
&lt;br /&gt;
Here is the configuration I used:&lt;br /&gt;
&lt;h2&gt;
httpd.conf&lt;/h2&gt;
&lt;hr /&gt;
&lt;script class="brush: plain" type="syntaxhighlighter"&gt;
&lt;![CDATA[
...
LoadModule proxy_module libexec/apache2/mod_proxy.so
LoadModule proxy_ajp_module libexec/apache2/mod_proxy_ajp.so
LoadModule rewrite_module libexec/apache2/mod_rewrite.so
# Virtual hosts
Include /private/etc/apache2/extra/httpd-vhosts.conf
...
]]&gt;
&lt;/script&gt;
&lt;br /&gt;
&lt;h2&gt;
httpd-vhosts.conf&lt;/h2&gt;
&lt;hr /&gt;
&lt;script class="brush: plain" type="syntaxhighlighter"&gt;
&lt;![CDATA[
&lt;virtualhost *:*&gt;
 RewriteEngine On
 RewriteOptions Inherit
 ProxyPass /mercurial http://127.0.0.1:8080/mercurial
 ProxyPassReverse /mercurial http://127.0.0.1:8080/mercurial
 ProxyPassReverseCookiePath /mercurial /
&lt;/VirtualHost&gt;
]]&gt;
&lt;/script&gt;
Those simple changes allowed me to rewrite the URL, and open only two ports on my firewall 80 and 443 which are a very good arrangement. As noted in &lt;a href="http://javaevangelist.blogspot.com/2009/05/secure-mercurial-in-glassfish-using-ssl.html"&gt;Secure Mercurial in GlassFish using SSL&lt;/a&gt;, I am using GlassFish SSL and security to handle my authentication so this is truly a very good solution.&lt;br /&gt;
&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-MRTx13hl558/Twj1ZVFt9MI/AAAAAAAABUU/GI2uYzz1ARQ/s1600/MercurialSampling.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="268" src="http://1.bp.blogspot.com/-MRTx13hl558/Twj1ZVFt9MI/AAAAAAAABUU/GI2uYzz1ARQ/s640/MercurialSampling.png" width="640" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;Mercurial Repositories&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/36773632-7743172830042244343?l=javaevangelist.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/8KupQdNP0SqEjPDO4hSQte4TUUw/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/8KupQdNP0SqEjPDO4hSQte4TUUw/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/8KupQdNP0SqEjPDO4hSQte4TUUw/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/8KupQdNP0SqEjPDO4hSQte4TUUw/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/JavaEvangelistJohnYearysBlog/~4/Uu3D0bDgwcw" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/JavaEvangelistJohnYearysBlog/~3/Uu3D0bDgwcw/using-apache-httpd-web-server-modproxy.html</link><author>noreply@blogger.com (John Yeary)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/-VMmuBORRZEc/TwjutOALKOI/AAAAAAAABUM/WeJ4qQap6HY/s72-c/gf_mod_jk.png" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://javaevangelist.blogspot.com/2012/01/using-apache-httpd-web-server-modproxy.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-36773632.post-8371821922680649637</guid><pubDate>Thu, 05 Jan 2012 16:04:00 +0000</pubDate><atom:updated>2012-01-05T11:04:24.070-05:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Programming</category><title>MD5 Checksum and Cryptographic Signature Checks on Code</title><description>&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://1.bp.blogspot.com/-xasGgUlylFc/TlUPnM8NzWI/AAAAAAAADOo/ub0Q1-K4i5E/s1600/spiedon.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="142" src="http://1.bp.blogspot.com/-xasGgUlylFc/TlUPnM8NzWI/AAAAAAAADOo/ub0Q1-K4i5E/s200/spiedon.jpg" width="200" /&gt;&lt;/a&gt;&lt;/div&gt;
I just wanted to post a generally good idea on downloading code. I recently downloaded some code from an Apache mirror site which I checked against its MD5 checksum and it failed. At first I thought that the file was corrupt and re-downloaded it. Again it failed the MD5 check, so I checked its cryptographic (GPG) signature and it failed.&lt;br /&gt;
&lt;br /&gt;
I downloaded the code from another mirror and everything worked correctly. I notified the mirror site of the inconsistency, and carried on. However, I often wonder how much we shortcut our work, and fail to check that vital information.&lt;br /&gt;
&lt;br /&gt;
Here is a gentle reminder. If the code has an MD5, SHA, and cryptographic signature, please take the extra 5 minutes to check all three. It will verify your downloads, are safe.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Also keep in mind that if you don't, and make a war file that contains these potentially infected sources, you are propagating the problem.&lt;/b&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/36773632-8371821922680649637?l=javaevangelist.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/xEIu5U15yQCGNQb_3ElDWI_w2Co/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/xEIu5U15yQCGNQb_3ElDWI_w2Co/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/xEIu5U15yQCGNQb_3ElDWI_w2Co/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/xEIu5U15yQCGNQb_3ElDWI_w2Co/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/JavaEvangelistJohnYearysBlog/~4/ZnT2ahxPBSc" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/JavaEvangelistJohnYearysBlog/~3/ZnT2ahxPBSc/md5-checksum-and-cryptographic.html</link><author>noreply@blogger.com (John Yeary)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/-xasGgUlylFc/TlUPnM8NzWI/AAAAAAAADOo/ub0Q1-K4i5E/s72-c/spiedon.jpg" height="72" width="72" /><thr:total>2</thr:total><feedburner:origLink>http://javaevangelist.blogspot.com/2012/01/md5-checksum-and-cryptographic.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-36773632.post-5607983428376035068</guid><pubDate>Thu, 05 Jan 2012 13:08:00 +0000</pubDate><atom:updated>2012-01-05T08:17:43.713-05:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">AJAX</category><category domain="http://www.blogger.com/atom/ns#">JAXB</category><category domain="http://www.blogger.com/atom/ns#">JEE5</category><category domain="http://www.blogger.com/atom/ns#">Jersey</category><category domain="http://www.blogger.com/atom/ns#">JAX-RS</category><category domain="http://www.blogger.com/atom/ns#">JEE6</category><category domain="http://www.blogger.com/atom/ns#">JSR-311</category><category domain="http://www.blogger.com/atom/ns#">example</category><category domain="http://www.blogger.com/atom/ns#">Programming</category><category domain="http://www.blogger.com/atom/ns#">JSON</category><category domain="http://www.blogger.com/atom/ns#">JavaEE</category><category domain="http://www.blogger.com/atom/ns#">tutorial</category><category domain="http://www.blogger.com/atom/ns#">glassfish</category><category domain="http://www.blogger.com/atom/ns#">Netbeans</category><title>JAX-RS Tip of the Day: Using @CookieParam</title><description>I am not a fan of using cookies in REST based services. I think that it makes the service less usable since the client must be able to store and retrieve cookies. This limits usage of the service, and introduces state outside of the service. Even the RFC for cookies is called &lt;a href="http://www.ietf.org/rfc/rfc2109.txt"&gt;HTTP State Management Mechanism&lt;/a&gt;.&amp;nbsp;&lt;code&gt;&lt;a href="http://curl.haxx.se/docs/httpscripting.html"&gt;curl&lt;/a&gt;&lt;/code&gt; can be used to send cookies to test so not all is lost.
&lt;br /&gt;
&lt;br /&gt;
Alright, if I have not talked you out of using them yet, you must have a need for them. &amp;nbsp;(Please rethink the idea though).&lt;br /&gt;
&lt;br /&gt;
Use of cookies is accomplished by using the &lt;code&gt;@CookieParam&lt;/code&gt; annotation. Also you can return responses as shown in the code below which include cookies.&lt;br /&gt;
&lt;br /&gt;
Cookies have a limitations on the use of some characters, and names so please look at the RFC noted above for additional limitations. I demonstrate a couple of limitations which include the use of semi-colons (;), and commas(,). The nice thing about this example is you can see the output in a real browser (Internet Explorer not included) since most can handle application/json objects which are returned.&lt;br /&gt;
&lt;br /&gt;
Here is the example code developed using &lt;a href="http://www.netbeans.org/"&gt;NetBeans 7.1 RC2&lt;/a&gt; and &lt;a href="http://glassfish.java.net/"&gt;GlassFish 3.1.1&lt;/a&gt;:&amp;nbsp;&lt;a href="http://commondatastorage.googleapis.com/bluelotussoftware/code/cookie-parameters.zip"&gt;cookie-parameters.zip&lt;/a&gt;&lt;br /&gt;
&lt;h2&gt;





CookieParameterResource.java&lt;/h2&gt;
&lt;hr /&gt;
&lt;script class="brush: java" type="syntaxhighlighter"&gt;
&lt;![CDATA[
/*
 * Copyright 2012 Blue Lotus Software, LLC.
 * Copyright 2012 John Yeary &lt;jyeary@bluelotussoftware.com&gt;.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/*
 * $Id: CookieParameterResource.java,v 8aa9e8cbb19a 2012/01/05 12:47:08 jyeary $
 */
package com.bluelotussoftware.jaxrs.resources;

import java.text.DateFormat;
import java.util.Date;
import javax.enterprise.context.RequestScoped;
import javax.ws.rs.*;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.NewCookie;
import javax.ws.rs.core.Response;
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;

/**
 * An example application which demonstrates the use of {@link javax.ws.rs.CookieParam}.
 *
 * @author John Yeary &lt;jyeary@bluelotussoftware.com&gt;
 * @version 1.0
 */
@Path("example")
@RequestScoped
public class CookieParameterResource {

    @Context
    private HttpHeaders headers;

    @GET
    @Produces({MediaType.APPLICATION_JSON})
    public Response get(
            @CookieParam(value = "User-Agent") String userAgent,
            @CookieParam(value = "Last-Accessed") String lastAccessed,
            @HeaderParam(value = "User-Agent") String userAgentHeader) {
        try {

            // Cookies have restrictions on the use of semi-colons, and commas so we replace them with directives.
            NewCookie agentCookie = new NewCookie("User-Agent", 
                    userAgentHeader.replace(";", "##semicolon##").replace(",", "##comma##"));
            String accessed = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.LONG).format(new Date());
            NewCookie lastAccessedCookie = new NewCookie("Last-Accessed", accessed);

            JSONObject jsono = new JSONObject();
            jsono.append("user-agent", userAgentHeader);
            jsono.append("accessed", accessed);

            if (userAgent != null) {
                jsono.append("previous-agent", userAgent.replace("##semicolon##", ";").replace("##comma##", ","));
            } else {
                jsono.append("previous-agent", null);
            }

            jsono.append("last-accessed", lastAccessed);

            return Response.ok(jsono, MediaType.APPLICATION_JSON).cookie(agentCookie, lastAccessedCookie).build();
        } catch (JSONException ex) {
            throw new WebApplicationException(ex, Response.Status.INTERNAL_SERVER_ERROR);
        }
    }
}
]]&gt;
&lt;/script&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/36773632-5607983428376035068?l=javaevangelist.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/xyTu7ilkKmrvNhyStgR-dPQe8TE/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/xyTu7ilkKmrvNhyStgR-dPQe8TE/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/xyTu7ilkKmrvNhyStgR-dPQe8TE/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/xyTu7ilkKmrvNhyStgR-dPQe8TE/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/JavaEvangelistJohnYearysBlog/~4/Zcf13eCUD8w" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/JavaEvangelistJohnYearysBlog/~3/Zcf13eCUD8w/jax-rs-tip-of-day-using-cookieparam.html</link><author>noreply@blogger.com (John Yeary)</author><thr:total>0</thr:total><feedburner:origLink>http://javaevangelist.blogspot.com/2012/01/jax-rs-tip-of-day-using-cookieparam.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-36773632.post-7236979094763849858</guid><pubDate>Wed, 04 Jan 2012 20:04:00 +0000</pubDate><atom:updated>2012-01-04T15:04:47.524-05:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">example</category><category domain="http://www.blogger.com/atom/ns#">OS X</category><category domain="http://www.blogger.com/atom/ns#">Java</category><category domain="http://www.blogger.com/atom/ns#">JDK7</category><category domain="http://www.blogger.com/atom/ns#">tutorial</category><category domain="http://www.blogger.com/atom/ns#">OpenJDK</category><category domain="http://www.blogger.com/atom/ns#">Netbeans</category><title>OpenJDK 1.7 with NetBeans 7.1 RC on Mac OS X 10.7</title><description>A question was posed to me the other day on how to use &lt;a href="http://openjdk.java.net/"&gt;OpenJDK&lt;/a&gt; 1.7 on NetBeans on a Mac since there is only a &lt;a href="http://jdk7.java.net/macportpreview/"&gt;Developer Preview&lt;/a&gt; available. I decided that a video does a better explanation. This applies to NetBeans 6+ as well when using JDK 7 on a default platform of JDK 6.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;object class="BLOGGER-youtube-video" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" data-thumbnail-src="http://i.ytimg.com/vi/EkIS17NWC1g/0.jpg" height="266" width="320"&gt;&lt;param name="movie" value="http://www.youtube.com/v/EkIS17NWC1g?version=3&amp;f=user_uploads&amp;c=google-webdrive-0&amp;app=youtube_gdata" /&gt;


&lt;param name="bgcolor" value="#FFFFFF" /&gt;


&lt;embed width="640" height="480"  src="http://www.youtube.com/v/EkIS17NWC1g?version=3&amp;f=user_uploads&amp;c=google-webdrive-0&amp;app=youtube_gdata" type="application/x-shockwave-flash"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/36773632-7236979094763849858?l=javaevangelist.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/ifSYGmmN265OlT_UvhVPDMzic2g/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ifSYGmmN265OlT_UvhVPDMzic2g/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/ifSYGmmN265OlT_UvhVPDMzic2g/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ifSYGmmN265OlT_UvhVPDMzic2g/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/JavaEvangelistJohnYearysBlog/~4/4N2Ca4cvTn4" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/JavaEvangelistJohnYearysBlog/~3/4N2Ca4cvTn4/openjdk-17-with-netbeans-71-rc-on-mac.html</link><author>noreply@blogger.com (John Yeary)</author><thr:total>0</thr:total><feedburner:origLink>http://javaevangelist.blogspot.com/2012/01/openjdk-17-with-netbeans-71-rc-on-mac.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-36773632.post-8426043856439267888</guid><pubDate>Sat, 31 Dec 2011 17:00:00 +0000</pubDate><atom:updated>2011-12-31T12:00:08.234-05:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">AJAX</category><category domain="http://www.blogger.com/atom/ns#">JAXB</category><category domain="http://www.blogger.com/atom/ns#">JEE5</category><category domain="http://www.blogger.com/atom/ns#">Jersey</category><category domain="http://www.blogger.com/atom/ns#">JAX-RS</category><category domain="http://www.blogger.com/atom/ns#">JEE6</category><category domain="http://www.blogger.com/atom/ns#">JSR-311</category><category domain="http://www.blogger.com/atom/ns#">example</category><category domain="http://www.blogger.com/atom/ns#">Programming</category><category domain="http://www.blogger.com/atom/ns#">JSON</category><category domain="http://www.blogger.com/atom/ns#">JavaEE</category><category domain="http://www.blogger.com/atom/ns#">tutorial</category><category domain="http://www.blogger.com/atom/ns#">glassfish</category><category domain="http://www.blogger.com/atom/ns#">Netbeans</category><title>JAX-RS Tip of the Day: Using YUI2 and YUI3 DataTables with Jersey and jQuery</title><description>This is a great example (if I do say so myself) that demonstrates some really cool capabilities of Jersey combined with Yahoo User Interface versions 2 and 3 combined with &lt;a href="http://jquery.com/"&gt;jQuery&lt;/a&gt; to demonstrate&amp;nbsp;interoperability&amp;nbsp;of multiple technologies.&lt;br /&gt;
&lt;br /&gt;
The example code that I have included uses &lt;a href="http://glassfish.java.net/"&gt;GlassFish 3.1.1&lt;/a&gt; with &lt;a href="http://jersey.java.net/"&gt;Jersey 1.11&lt;/a&gt; and was developed using &lt;a href="http://netbeans.org/"&gt;NetBeans 7.1 RC2&lt;/a&gt;. The data is from the default sample database included in &lt;a href="http://netbeans.org/"&gt;NetBeans&lt;/a&gt;. Here is the code:&amp;nbsp;&lt;a href="http://commondatastorage.googleapis.com/bluelotussoftware/code/jsonp-database.zip"&gt;jsonp-database.zip&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
The &lt;a href="http://developer.yahoo.com/yui/2/"&gt;YUI2&lt;/a&gt;, &lt;a href="http://yuilibrary.com/"&gt;YUI3&lt;/a&gt;, and jQuery libraries are provided by Yahoo and Google CDN. This is a further example of a truly RESTful application where the application is provided as a mashup of multiple web resources.&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://developer.yahoo.com/yui/"&gt;Yahoo User Interface (YUI)&lt;/a&gt; is an incredibly well developed UI framework for the web. The DataSource implementation is easy to use and is extremely adaptable. It is also very stable, and Yahoo eats its own dogfood like Google so it is battle tested. YUI3 is the next generation code, and the DataTable implementation includes a number of new features.&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://jquery.com/"&gt;jQuery&lt;/a&gt; is an extremely popular Javascript framework with great AJAX functionality. I have included two examples (YUI2/YUI3) in which jQuery provides JSON data to the Yahoo DataSource.&lt;br /&gt;
&lt;br /&gt;
Jersey provides the heavy lifting. In all of the examples I provide the data in a variety of formats, but I focus on providing both &lt;a href="http://www.json.org/"&gt;JSON&lt;/a&gt; and &lt;a href="http://en.wikipedia.org/wiki/JSONP"&gt;JSONP&lt;/a&gt;. JSONP allows us to use have cross-domain capabilities. The code also demonstrates how to use &lt;a href="http://jettison.codehaus.org/"&gt;Jettison&lt;/a&gt; to encapsulate POJOs. The best part is that the data can be tested not only using your browser, but can also be tested using &lt;code&gt;curl&lt;/code&gt;. This provides a very simple visual means of verifying data.&lt;br /&gt;
&lt;br /&gt;
So what does it look like... look at the images below. The results speak for themselves.&lt;br /&gt;
&lt;br /&gt;
&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-F3mwmFajraQ/Tv6Am_c0sbI/AAAAAAAABT4/XwQNik9KqCQ/s1600/YUI2DataTableJSP.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="241" src="http://2.bp.blogspot.com/-F3mwmFajraQ/Tv6Am_c0sbI/AAAAAAAABT4/XwQNik9KqCQ/s640/YUI2DataTableJSP.png" width="640" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;YUI2 DataTable using JSP&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/--DJybA-vglo/Tv6A1rIHUUI/AAAAAAAABUE/QwB_itMsEPU/s1600/YUI3DataTableHTML.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="224" src="http://1.bp.blogspot.com/--DJybA-vglo/Tv6A1rIHUUI/AAAAAAAABUE/QwB_itMsEPU/s640/YUI3DataTableHTML.png" width="640" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;YUI3 DataTable with JSONP and JAX-RS (Jersey)&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
Now for the most important part, how do you get here.
&lt;br /&gt;
&lt;h2&gt;


Technical Details&lt;/h2&gt;
The &lt;code&gt;CustomerFacadeREST&lt;/code&gt; class is the most interesting. The JSP and HTML pages have the details of how to use the various YUI DataSources along with jQuery. I will not print the pages out, and suggest that you simply download the code and examine it.
&lt;br /&gt;
&lt;h2&gt;

CustomerFacadeREST.java&lt;/h2&gt;
&lt;hr /&gt;
&lt;script class="brush: java" type="syntaxhighlighter"&gt;
&lt;![CDATA[
/*
 * Copyright 2011 Blue Lotus Software, LLC.
 * Copyright 2011 John Yeary &lt;jyeary@bluelotussoftware.com&gt;.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.bluelotussoftware.example.jaxrs.resources;

import com.bluelotussoftware.example.jaxrs.model.Customer;
import com.sun.jersey.api.json.JSONWithPadding;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.ws.rs.*;
import javax.ws.rs.core.GenericEntity;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;

/**
 *
 * @author John Yeary &lt;jyeary@bluelotussoftware.com&gt;
 * @version 1.0
 */
@Stateless
@Path("customers")
public class CustomerFacadeREST extends AbstractFacade&lt;customer&gt; {

    @PersistenceContext(unitName = "demoPU")
    private EntityManager em;

    public CustomerFacadeREST() {
        super(Customer.class);
    }

    @POST
    @Override
    @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
    public void create(Customer entity) {
        super.create(entity);
    }

    @PUT
    @Override
    @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
    public void edit(Customer entity) {
        super.edit(entity);
    }

    @DELETE
    @Path("{id}")
    public void remove(@PathParam("id") Integer id) {
        super.remove(super.find(id));
    }

    @GET
    @Path("json/{id}")
    @Produces({MediaType.APPLICATION_JSON})
    public JSONObject findJSONObject(@PathParam("id") Integer id) {
        Customer c = super.find(id);
        JSONObject jSONObject = new JSONObject();
        try {
            jSONObject.put("customerId", c.getCustomerId());
            jSONObject.put("name", c.getName());
            jSONObject.put("addressLine1", c.getAddressline1());
            jSONObject.put("addressLine2", c.getAddressline2());
            jSONObject.put("city", c.getCity());
            jSONObject.put("state", c.getState());
            jSONObject.put("phone", c.getPhone());
            jSONObject.put("fax", c.getFax());
            jSONObject.put("email", c.getEmail());
            jSONObject.put("creditLimit", c.getCreditLimit());
        } catch (JSONException ex) {
            throw new WebApplicationException(ex, Response.Status.INTERNAL_SERVER_ERROR);
        }
        return jSONObject;
    }

    @GET
    @Path("{id}")
    @Produces({"application/javascript", "application/ecmascript", "application/x-ecmascript",
        "application/x-javascript"})
    public JSONWithPadding find(@PathParam("id") Integer id,
            @QueryParam(value = "callback") String callback) {
        return new JSONWithPadding(super.find(id), callback);
    }

    @GET
    @Produces({"application/javascript", "application/ecmascript", "application/x-ecmascript",
        "application/x-javascript"})
    public JSONWithPadding getCustomers(@QueryParam("callback") String callback) {
        return new JSONWithPadding(new GenericEntity&lt;List&lt;customer&gt;&gt;(super.findAll()) {
        }, callback);
    }

    @GET
    @Produces({MediaType.APPLICATION_JSON})
    @Path("json")
    public List&lt;customer&gt; getCustomersJSON() {
        return super.findAll();
    }

    @GET
    @Produces({"application/javascript", "application/ecmascript", "application/x-ecmascript",
        "application/x-javascript"})
    @Path("alternate")
    public JSONWithPadding getCustomersAlternate1(@QueryParam("callback") String callback) {
        return new JSONWithPadding(super.findAll(), callback);
    }

    //FIXME This returns an unexpected result of toString() on the Customer objects.
    @GET
    @Produces({"application/javascript", "application/ecmascript", "application/x-ecmascript",
        "application/x-javascript"})
    @Path("alternate2")
    public JSONWithPadding getCustomersAlternate2(@QueryParam(value = "callback") String callback) {
        JSONArray jSONArray = new JSONArray(super.findAll());
        return new JSONWithPadding(jSONArray, callback);
    }

    @GET
    @Path("{from}/{to}")
    @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
    public List&lt;customer&gt; findRange(@PathParam("from") Integer from, @PathParam("to") Integer to) {
        return super.findRange(new int[]{from, to});
    }

    @GET
    @Path("count")
    @Produces("text/plain")
    public String countREST() {
        return String.valueOf(super.count());
    }

    @java.lang.Override
    protected EntityManager getEntityManager() {
        return em;
    }
}
]]&gt;
&lt;/script&gt;

&lt;br /&gt;
&lt;h2&gt;
CODE&lt;/h2&gt;
&lt;hr/&gt;
Here is the code: &lt;a href="http://commondatastorage.googleapis.com/bluelotussoftware/code/jsonp-database.zip"&gt;jsonp-database.zip&lt;/a&gt;
&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/36773632-8426043856439267888?l=javaevangelist.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/A2Q0n2sDsBB46g5t5b6DvRXxhg0/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/A2Q0n2sDsBB46g5t5b6DvRXxhg0/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/A2Q0n2sDsBB46g5t5b6DvRXxhg0/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/A2Q0n2sDsBB46g5t5b6DvRXxhg0/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/JavaEvangelistJohnYearysBlog/~4/a6exMSoLcls" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/JavaEvangelistJohnYearysBlog/~3/a6exMSoLcls/jax-rs-tip-of-day-using-yui2-and-yui3.html</link><author>noreply@blogger.com (John Yeary)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://2.bp.blogspot.com/-F3mwmFajraQ/Tv6Am_c0sbI/AAAAAAAABT4/XwQNik9KqCQ/s72-c/YUI2DataTableJSP.png" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://javaevangelist.blogspot.com/2011/12/jax-rs-tip-of-day-using-yui2-and-yui3.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-36773632.post-6316443194075690413</guid><pubDate>Sat, 31 Dec 2011 14:00:00 +0000</pubDate><atom:updated>2011-12-31T09:00:00.793-05:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">AJAX</category><category domain="http://www.blogger.com/atom/ns#">JAXB</category><category domain="http://www.blogger.com/atom/ns#">JEE5</category><category domain="http://www.blogger.com/atom/ns#">Jersey</category><category domain="http://www.blogger.com/atom/ns#">JAX-RS</category><category domain="http://www.blogger.com/atom/ns#">JEE6</category><category domain="http://www.blogger.com/atom/ns#">JSR-311</category><category domain="http://www.blogger.com/atom/ns#">example</category><category domain="http://www.blogger.com/atom/ns#">Programming</category><category domain="http://www.blogger.com/atom/ns#">JSON</category><category domain="http://www.blogger.com/atom/ns#">JavaEE</category><category domain="http://www.blogger.com/atom/ns#">tutorial</category><category domain="http://www.blogger.com/atom/ns#">glassfish</category><category domain="http://www.blogger.com/atom/ns#">Netbeans</category><title>JAX-RS Tip of the Day: Changing JSON-JAXB Default Mapping</title><description>JSON-JAXB&amp;nbsp;marshalling&amp;nbsp;and un-marshalling&amp;nbsp;by default uses a &lt;code&gt;&lt;a href="http://jersey.java.net/nonav/apidocs/1.11/jersey/com/sun/jersey/api/json/JSONConfiguration.Notation.html#enum_constant_detail"&gt;MAPPED&lt;/a&gt;&lt;/code&gt; configuration by default. However this can be changed by creating a &lt;code&gt;&lt;a href="http://jersey.java.net/nonav/apidocs/1.11/jersey/javax/ws/rs/ext/Provider.html"&gt;@Provider&lt;/a&gt;&lt;/code&gt; which can change the default &lt;code&gt;&lt;a href="http://jersey.java.net/nonav/apidocs/1.11/jersey/com/sun/jersey/api/json/JSONConfiguration.html"&gt;JSONConfiguration&lt;/a&gt;&lt;/code&gt;.&lt;br /&gt;
&lt;br /&gt;
The example below changes the configuration to use &lt;a href="http://www.sklar.com/badgerfish/"&gt;BadgerFish&lt;/a&gt; which provides a better representation of an XML document. This representation does not provide the visual clarity that JSON generally provides, and is not generally human readable beyond basic notation. However, as noted that is not the point.&lt;br /&gt;
&lt;br /&gt;
&lt;h2&gt;
JSONJAXBContextResolver.java&lt;/h2&gt;
&lt;hr /&gt;
&lt;script class="brush: java" type="syntaxhighlighter"&gt;
&lt;![CDATA[
/*
 * Copyright 2011 Blue Lotus Software, LLC.
 * Copyright 2011 John Yeary &lt;jyeary@bluelotussoftware.com&gt;.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.bluelotussoftware.example.jaxrs.providers;

import com.bluelotussoftware.example.jaxrs.model.Customer;
import com.sun.jersey.api.json.JSONConfiguration;
import com.sun.jersey.api.json.JSONJAXBContext;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import javax.ws.rs.ext.ContextResolver;
import javax.ws.rs.ext.Provider;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;

/**
 *
 * @author John Yeary &lt;jyeary@bluelotussoftware.com&gt;
 * @version 1.0
 */
@Provider
public class JSONJAXBContextResolver implements ContextResolver&lt;JAXBContext&gt; {

    private final JAXBContext context;
    private final Set&lt;Class&gt; types;
    private final Class[] cs = {Customer.class};

    public JSONJAXBContextResolver() throws JAXBException {
        this.types = new HashSet(Arrays.asList(cs));
        //Change the JSONConfiguration below to chnage the mapping type.
        this.context = new JSONJAXBContext(JSONConfiguration.badgerFish().build(), cs);
    }

    @Override
    public JAXBContext getContext(Class&lt;?&gt; type) {
        return (types.contains(type)) ? context : null;
    }
}
]]&gt;
&lt;/script&gt;

This class specifically handles the Customer object, and maps it to use BadgerFish.

&lt;script class="brush: shell" type="syntaxhighlighter"&gt;
&lt;![CDATA[
curl -X GET -H "Accept: application/json" http://localhost:8080/jsonp-database/resources/customers/json/1
]]&gt;
&lt;/script&gt;
&lt;b&gt;Output:&lt;/b&gt;
&lt;br/&gt;
&lt;script class="brush: shell" type="syntaxhighlighter"&gt;
&lt;![CDATA[
{"customerId":1,"name":"Jumbo Eagle Corp","addressLine1":"111 E. Las Olivas Blvd","addressLine2":"Suite 51","city":"Fort Lauderdale","state":"FL","phone":"305-555-0188","fax":"305-555-0189","email":"jumboeagle@example.com","creditLimit":100000}
]]&gt;
&lt;/script&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/36773632-6316443194075690413?l=javaevangelist.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/N2ZLcDsKb3MBub609yM3Sefz2io/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/N2ZLcDsKb3MBub609yM3Sefz2io/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/N2ZLcDsKb3MBub609yM3Sefz2io/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/N2ZLcDsKb3MBub609yM3Sefz2io/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/JavaEvangelistJohnYearysBlog/~4/g0PxM-9wcD8" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/JavaEvangelistJohnYearysBlog/~3/g0PxM-9wcD8/jax-rs-tip-of-day-changing-json-jaxb.html</link><author>noreply@blogger.com (John Yeary)</author><thr:total>0</thr:total><feedburner:origLink>http://javaevangelist.blogspot.com/2011/12/jax-rs-tip-of-day-changing-json-jaxb.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-36773632.post-1182943807620998091</guid><pubDate>Sat, 31 Dec 2011 01:19:00 +0000</pubDate><atom:updated>2011-12-30T21:40:29.417-05:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">AJAX</category><category domain="http://www.blogger.com/atom/ns#">JAXB</category><category domain="http://www.blogger.com/atom/ns#">JEE5</category><category domain="http://www.blogger.com/atom/ns#">Jersey</category><category domain="http://www.blogger.com/atom/ns#">JAX-RS</category><category domain="http://www.blogger.com/atom/ns#">JEE6</category><category domain="http://www.blogger.com/atom/ns#">JSR-311</category><category domain="http://www.blogger.com/atom/ns#">example</category><category domain="http://www.blogger.com/atom/ns#">Programming</category><category domain="http://www.blogger.com/atom/ns#">JSON</category><category domain="http://www.blogger.com/atom/ns#">JavaEE</category><category domain="http://www.blogger.com/atom/ns#">tutorial</category><category domain="http://www.blogger.com/atom/ns#">glassfish</category><category domain="http://www.blogger.com/atom/ns#">Netbeans</category><title>JAX-RS Tip of the Day: Automatic Mapping of Jettison JSON Objects</title><description>One of the more interesting features in &lt;a href="http://jersey.java.net/"&gt;JAX-RS (Jersey)&lt;/a&gt; is the ability to automatically "wrap" POJOs. This combined with automatic wrapping of &lt;a href="http://jaxb.java.net/"&gt;JAXB&lt;/a&gt; annotated beans, and using &lt;a href="http://jackson.codehaus.org/"&gt;Jackson&lt;/a&gt; to create JSON objects is a powerful mix. However, sometimes we want to wrap an object, and add some additional metadata.&lt;br /&gt;
&lt;br /&gt;
This tip is a very simple tip which allows you to create &lt;a href="http://jettison.codehaus.org/Home"&gt;Jettison&lt;/a&gt; JSONObject, and JSONArray objects to create new objects, "wrap" existing objects, or add additional metadata. I mention "wrap" the objects, please don't confuse this with &lt;a href="http://en.wikipedia.org/wiki/JSONP"&gt;JSONP&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
To enable automatic POJO mapping, and Jettison objects add the following to the web.xml&lt;br /&gt;
&lt;script class="brush: xml" type="syntaxhighlighter"&gt;
&lt;![CDATA[ 
    &lt;servlet&gt;
        &lt;servlet-name&gt;ServletAdaptor&lt;/servlet-name&gt;
        &lt;servlet-class&gt;com.sun.jersey.spi.container.servlet.ServletContainer&lt;/servlet-class&gt;
        &lt;init-param&gt;
            &lt;description&gt;
                Allow automatic POJO Mapping features.
            &lt;/description&gt;
            &lt;param-name&gt;com.sun.jersey.api.json.POJOMappingFeature&lt;/param-name&gt;
            &lt;param-value&gt;true&lt;/param-value&gt;
        &lt;/init-param&gt;
        &lt;init-param&gt;
            &lt;description&gt;
                Set the packages to point to resources which you want to allow 
                mapping of Jettison based objects. Separate the values for multiple
                packages with a comma (,).
            &lt;/description&gt;
            &lt;param-name&gt;com.sun.jersey.config.property.packages&lt;/param-name&gt;
            &lt;param-value&gt;com.bluelotussoftware.example.jaxrs.resources&lt;/param-value&gt;
        &lt;/init-param&gt;
        &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
    &lt;/servlet&gt;
]]&gt;
&lt;/script&gt;

This simple configuration will give you considerable flexibility in how you handle your objects. This will now allow you to produce JSONObjects like the code example below:
&lt;script class="brush: java" type="syntaxhighlighter"&gt;
&lt;![CDATA[ 
    @GET
    @Path("{id}")
    @Produces({MediaType.APPLICATION_JSON})
    public JSONObject findJSONObject(@PathParam("id") Integer id) {
        Customer c = super.find(id);
        JSONObject jSONObject = new JSONObject();
        try {
            jSONObject.put("customerId", c.getCustomerId());
            jSONObject.put("name", c.getName());
            jSONObject.put("addressLine1", c.getAddressline1());
            jSONObject.put("addressLine2", c.getAddressline2());
            jSONObject.put("city", c.getCity());
            jSONObject.put("state", c.getState());
            jSONObject.put("phone", c.getPhone());
            jSONObject.put("fax", c.getFax());
            jSONObject.put("email", c.getEmail());
            jSONObject.put("creditLimit", c.getCreditLimit());
        } catch (JSONException ex) {
            throw new WebApplicationException(ex, Response.Status.INTERNAL_SERVER_ERROR);
        }
        return jSONObject;
    }
]]&gt;
&lt;/script&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/36773632-1182943807620998091?l=javaevangelist.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/xvnfQlTbeK23Lm3y6xQeiywngrM/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/xvnfQlTbeK23Lm3y6xQeiywngrM/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/xvnfQlTbeK23Lm3y6xQeiywngrM/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/xvnfQlTbeK23Lm3y6xQeiywngrM/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/JavaEvangelistJohnYearysBlog/~4/0-TQFzrsJr4" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/JavaEvangelistJohnYearysBlog/~3/0-TQFzrsJr4/jax-rs-tip-of-day-automatic-mapping-of.html</link><author>noreply@blogger.com (John Yeary)</author><thr:total>0</thr:total><feedburner:origLink>http://javaevangelist.blogspot.com/2011/12/jax-rs-tip-of-day-automatic-mapping-of.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-36773632.post-3815871361827368430</guid><pubDate>Wed, 28 Dec 2011 15:05:00 +0000</pubDate><atom:updated>2011-12-29T10:23:42.278-05:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">example</category><category domain="http://www.blogger.com/atom/ns#">Javascript</category><category domain="http://www.blogger.com/atom/ns#">JavaEE</category><category domain="http://www.blogger.com/atom/ns#">AJAX</category><category domain="http://www.blogger.com/atom/ns#">Internet Explorer</category><category domain="http://www.blogger.com/atom/ns#">JEE5</category><category domain="http://www.blogger.com/atom/ns#">tutorial</category><category domain="http://www.blogger.com/atom/ns#">glassfish</category><category domain="http://www.blogger.com/atom/ns#">Apache</category><category domain="http://www.blogger.com/atom/ns#">jQuery</category><category domain="http://www.blogger.com/atom/ns#">Netbeans</category><title>Multiple File Upload Examples</title><description>I received an email today from a developer who was looking for examples of how to do multiple file uploads. I had written a post previously&amp;nbsp;&lt;a href="http://javaevangelist.blogspot.com/2010/12/multiple-file-upload-options.html"&gt;Multiple File Upload Options&lt;/a&gt; which detailed some of the options available. The option I recommended was Andrew Valums &lt;a href="http://valums.com/ajax-upload/"&gt;ajax-upload&lt;/a&gt;. 

The developer had indicated that the servlet I contributed was not working with Internet Explorer correctly. He was correct.&lt;br /&gt;
&lt;br /&gt;
The code that I provided to Andrew Vallums was expecting &lt;i&gt;application/octet-stream&lt;/i&gt;. However Internet Explorer and Opera were sending &lt;i&gt;multipart/form-data&lt;/i&gt;.&amp;nbsp;This would not work with the servlet example I posted since the handling mechanism is considerably different.&lt;br /&gt;
&lt;br /&gt;
Alan O'Driscoll and I discovered the differences using Wireshark to sniff the packets and see what was being sent over the wire. As a result, I have written a new servlet to handle the differences between browsers.&lt;br /&gt;
&lt;br /&gt;
The example application I wrote has a number of different examples included with minor variations on the theme. The version most folks are interested in is example #6 which uses the ajax-upload, and the new servlet. Here is the Apache Maven project which was developed on NetBeans and tested on GlassFish v 2.1.1. Here is a link to the project:&amp;nbsp;&lt;a href="http://commondatastorage.googleapis.com/bluelotussoftware/code/ApacheFileUploadEE5.zip"&gt;ApacheFileUploadEE5.zip&lt;/a&gt;.
&lt;br /&gt;
&lt;br /&gt;
Here is another resource for file upload plugins:&amp;nbsp;&lt;a href="http://www.tutorialchip.com/jquery/9-powerful-jquery-file-upload-plugins/"&gt;9 Powerful jQuery File Upload Plugins&lt;/a&gt;. I discovered it while I was looking for something else.
&lt;br /&gt;
&lt;h2&gt;

MultiContentServlet.java&lt;/h2&gt;
&lt;hr /&gt;
&lt;script class="brush: java" type="syntaxhighlighter"&gt;
&lt;![CDATA[
/*
 * Copyright 2010-2011 Blue Lotus Software, LLC.
 * Copyright 2010-2011 John Yeary &lt;jyeary@bluelotussoftware.com&gt;.
 * Copyright 2010-2011 Alan O'Driscoll
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/*
 * $Id: MultiContentServlet.java,v 5d89d27ca0cb 2011/12/29 15:22:13 jyeary $
 */
package com.bluelotussoftware.apache.commons.fileupload.example;

import java.io.*;
import java.util.List;
import java.util.ListIterator;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.apache.commons.io.IOUtils;

/**
 *
 * @author John Yeary &lt;jyeary@bluelotussoftware.com&gt;
 * @author Allan O'Driscoll
 * @version 1.0
 */
public class MultiContentServlet extends HttpServlet {

    private static final long serialVersionUID = -2045199313944348406L;
    private static final String DESTINATION_DIR_PATH = "files";
    private static String realPath;
    private static final boolean debug = false;

    /**
     * {@inheritDoc}
     *
     * @param config
     * @throws ServletException
     */
    @Override
    public void init(ServletConfig config) throws ServletException {
        super.init(config);
        realPath = getServletContext().getRealPath(DESTINATION_DIR_PATH) + "/";
    }

    /**
     * Handles the HTTP
     * &lt;code&gt;POST&lt;/code&gt; method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        PrintWriter writer = null;
        InputStream is = null;
        FileOutputStream fos = null;

        try {
            writer = response.getWriter();
        } catch (IOException ex) {
            log(MultiContentServlet.class.getName() + "has thrown an exception: " + ex.getMessage());
        }

        boolean isMultiPart = ServletFileUpload.isMultipartContent(request);

        if (isMultiPart) {
            log("Content-Type: " + request.getContentType());
            // Create a factory for disk-based file items
            DiskFileItemFactory diskFileItemFactory = new DiskFileItemFactory();

            /*
             * Set the file size limit in bytes. This should be set as an
             * initialization parameter
             */
            diskFileItemFactory.setSizeThreshold(1024 * 1024 * 10); //10MB.


            // Create a new file upload handler
            ServletFileUpload upload = new ServletFileUpload(diskFileItemFactory);

            List items = null;

            try {
                items = upload.parseRequest(request);
            } catch (FileUploadException ex) {
                log("Could not parse request", ex);
            }

            ListIterator li = items.listIterator();

            while (li.hasNext()) {
                FileItem fileItem = (FileItem) li.next();
                if (fileItem.isFormField()) {
                    if (debug) {
                        processFormField(fileItem);
                    }
                } else {
                    writer.print(processUploadedFile(fileItem));
                }
            }
        }

        if ("application/octet-stream".equals(request.getContentType())) {
            log("Content-Type: " + request.getContentType());
            String filename = request.getHeader("X-File-Name");

            try {
                is = request.getInputStream();
                fos = new FileOutputStream(new File(realPath + filename));
                IOUtils.copy(is, fos);
                response.setStatus(HttpServletResponse.SC_OK);
                writer.print("{success: true}");
            } catch (FileNotFoundException ex) {
                response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
                writer.print("{success: false}");
                log(MultiContentServlet.class.getName() + "has thrown an exception: " + ex.getMessage());
            } catch (IOException ex) {
                response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
                writer.print("{success: false}");
                log(MultiContentServlet.class.getName() + "has thrown an exception: " + ex.getMessage());
            } finally {
                try {
                    fos.close();
                    is.close();
                } catch (IOException ignored) {
                }
            }

            writer.flush();
            writer.close();
        }
    }

    private void processFormField(FileItem item) {
        // Process a regular form field
        if (item.isFormField()) {
            String name = item.getFieldName();
            String value = item.getString();
            log("name: " + name + " value: " + value);
        }
    }

    private String processUploadedFile(FileItem item) {
        // Process a file upload
        if (!item.isFormField()) {
            try {
                item.write(new File(realPath + item.getName()));
                return "{success:true}";
            } catch (Exception ex) {
                log(FileUploadServlet.class.getName() + " has thrown an exception: " + ex.getMessage());
            }
        }
        return "{success:false}";
    }

    /**
     * Returns a short description of the servlet.
     *
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Handles file upload data from application/octet-stream, and multipart/form-data.";
    }
}
]]&gt;
&lt;/script&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/36773632-3815871361827368430?l=javaevangelist.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/PSrkR0UtS7RrJubGm0S0Y3lckcs/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/PSrkR0UtS7RrJubGm0S0Y3lckcs/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/PSrkR0UtS7RrJubGm0S0Y3lckcs/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/PSrkR0UtS7RrJubGm0S0Y3lckcs/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/JavaEvangelistJohnYearysBlog/~4/3rcCBHmuk6Q" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/JavaEvangelistJohnYearysBlog/~3/3rcCBHmuk6Q/multiple-file-upload-examples.html</link><author>noreply@blogger.com (John Yeary)</author><thr:total>0</thr:total><feedburner:origLink>http://javaevangelist.blogspot.com/2011/12/multiple-file-upload-examples.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-36773632.post-5842581159450964186</guid><pubDate>Sun, 18 Dec 2011 15:53:00 +0000</pubDate><atom:updated>2011-12-18T10:53:18.080-05:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Web</category><category domain="http://www.blogger.com/atom/ns#">example</category><category domain="http://www.blogger.com/atom/ns#">Programming</category><category domain="http://www.blogger.com/atom/ns#">JavaEE</category><category domain="http://www.blogger.com/atom/ns#">JSF</category><category domain="http://www.blogger.com/atom/ns#">tutorial</category><category domain="http://www.blogger.com/atom/ns#">glassfish</category><category domain="http://www.blogger.com/atom/ns#">RichFaces</category><category domain="http://www.blogger.com/atom/ns#">Netbeans</category><category domain="http://www.blogger.com/atom/ns#">JEE6</category><title>RichFaces 4.1.0 Final on NetBeans 7.1 IDE</title><description>I created a video which demonstrates how to add RichFaces 4.1.0 Final as a component library in NetBeans 7.1. The video details how to add the required jars to create the library, demonstrates code completion, and finally deployment to GlassFish 3.1.1 for display.&lt;br /&gt;
&lt;br /&gt;
In the video I take advantage of using my local Apache Maven repository which includes all of the dependencies required.&lt;br /&gt;
&lt;br /&gt;
The list below includes references to the required libraries and versions. There is a link to the video as well.&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;sac-1.3.jar&lt;/li&gt;
&lt;li&gt;guava-r08.jar&lt;/li&gt;
&lt;li&gt;cssparser-0.9.5.jar&lt;/li&gt;
&lt;li&gt;richfaces-core-api-4.1.0.Final.jar&lt;/li&gt;
&lt;li&gt;richfaces-core-impl-4.1.0.Final.jar&lt;/li&gt;
&lt;li&gt;richfaces-components-api-4.1.0.Final.jar&lt;/li&gt;
&lt;li&gt;richfaces-components-ui-4.1.0.Final.jar&lt;/li&gt;
&lt;/ul&gt;
&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-d0ug2rhmn9w/Tu4KxIQOdjI/AAAAAAAABTs/7HvfozRw42Q/s1600/RichFaces410Library.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="265" src="http://1.bp.blogspot.com/-d0ug2rhmn9w/Tu4KxIQOdjI/AAAAAAAABTs/7HvfozRw42Q/s640/RichFaces410Library.png" width="640" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;NetBeans 7.1 Library Manager&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;object width="320" height="266" class="BLOGGER-youtube-video" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" data-thumbnail-src="http://i.ytimg.com/vi/SghIy4ARuMk/0.jpg"&gt;&lt;param name="movie" value="http://www.youtube.com/v/SghIy4ARuMk?version=3&amp;f=user_uploads&amp;c=google-webdrive-0&amp;app=youtube_gdata" /&gt;
&lt;param name="bgcolor" value="#FFFFFF" /&gt;
&lt;embed width="320" height="266"  src="http://www.youtube.com/v/SghIy4ARuMk?version=3&amp;f=user_uploads&amp;c=google-webdrive-0&amp;app=youtube_gdata" type="application/x-shockwave-flash"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;/div&gt;
&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/36773632-5842581159450964186?l=javaevangelist.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/rFUUFc9XsVYoWmYGVzko1GIuss0/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/rFUUFc9XsVYoWmYGVzko1GIuss0/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/rFUUFc9XsVYoWmYGVzko1GIuss0/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/rFUUFc9XsVYoWmYGVzko1GIuss0/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/JavaEvangelistJohnYearysBlog/~4/6FfOupMCy5g" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/JavaEvangelistJohnYearysBlog/~3/6FfOupMCy5g/richfaces-410-final-on-netbeans-71-ide.html</link><author>noreply@blogger.com (John Yeary)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/-d0ug2rhmn9w/Tu4KxIQOdjI/AAAAAAAABTs/7HvfozRw42Q/s72-c/RichFaces410Library.png" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://javaevangelist.blogspot.com/2011/12/richfaces-410-final-on-netbeans-71-ide.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-36773632.post-7341074692179410439</guid><pubDate>Sat, 17 Dec 2011 03:10:00 +0000</pubDate><atom:updated>2011-12-16T23:00:57.986-05:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">example</category><category domain="http://www.blogger.com/atom/ns#">REST</category><category domain="http://www.blogger.com/atom/ns#">tutorial</category><category domain="http://www.blogger.com/atom/ns#">Jersey</category><category domain="http://www.blogger.com/atom/ns#">glassfish</category><category domain="http://www.blogger.com/atom/ns#">JAX-RS</category><category domain="http://www.blogger.com/atom/ns#">Netbeans</category><category domain="http://www.blogger.com/atom/ns#">JSR-311</category><title>JAX-RS Tip of the Day: NetBeans Project Layout Recommendations</title><description>When developing a JAX-RS project using NetBeans, I have a couple of simple recommendations. This will hopefully save you some time up front.&lt;br /&gt;
&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;First create a &lt;i&gt;Java&lt;/i&gt; → &lt;i&gt;Java Class Library&lt;/i&gt; project.&lt;br /&gt;This project will be used to contain classes we expect to share between the service and the client.&lt;/li&gt;
&lt;li&gt;Create a second project &lt;i&gt;Java Web&lt;/i&gt; → &lt;i&gt;Web Application&lt;/i&gt;.&lt;br /&gt;This project will serve as our REST service application.&lt;/li&gt;
&lt;li&gt;Add the first project to the second project.&lt;/li&gt;
&lt;li&gt;(Optional) Create a &lt;i&gt;Java&lt;/i&gt; → &lt;i&gt;Java Application&lt;/i&gt;&lt;br /&gt;This final project will be used for as our client application.&lt;/li&gt;
&lt;li&gt;(Optional) Add the first project to the client project.&lt;/li&gt;
&lt;/ol&gt;
&lt;br /&gt;
The most important part of the recommendation is to make sure that you have a separate library project. The shared code can later be used in multiple projects without refactoring later.&lt;br /&gt;
&lt;br /&gt;
Here is an example project that meets the recommendations above. It was created with NetBeans 7.1 RC2.
&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://commondatastorage.googleapis.com/bluelotussoftware/code/RESTWidgets.zip" target="_blank"&gt;RESTWidgets.zip&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://commondatastorage.googleapis.com/bluelotussoftware/code/RESTWidgetService.zip" target="_blank"&gt;RESTWidgetsService.zip&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://commondatastorage.googleapis.com/bluelotussoftware/code/WidgetClient.zip" target="_blank"&gt;WidgetClient.zip&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/36773632-7341074692179410439?l=javaevangelist.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/ZzVg1lGHJv6qdMz030D2qkNrxTc/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ZzVg1lGHJv6qdMz030D2qkNrxTc/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/ZzVg1lGHJv6qdMz030D2qkNrxTc/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ZzVg1lGHJv6qdMz030D2qkNrxTc/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/JavaEvangelistJohnYearysBlog/~4/eZZVC5rChHI" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/JavaEvangelistJohnYearysBlog/~3/eZZVC5rChHI/jax-rs-tip-of-day-netbeans-project.html</link><author>noreply@blogger.com (John Yeary)</author><thr:total>0</thr:total><feedburner:origLink>http://javaevangelist.blogspot.com/2011/12/jax-rs-tip-of-day-netbeans-project.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-36773632.post-5692142846891167967</guid><pubDate>Sat, 17 Dec 2011 03:10:00 +0000</pubDate><atom:updated>2011-12-16T22:10:10.103-05:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">example</category><category domain="http://www.blogger.com/atom/ns#">REST</category><category domain="http://www.blogger.com/atom/ns#">tutorial</category><category domain="http://www.blogger.com/atom/ns#">Jersey</category><category domain="http://www.blogger.com/atom/ns#">glassfish</category><category domain="http://www.blogger.com/atom/ns#">JAX-RS</category><category domain="http://www.blogger.com/atom/ns#">Netbeans</category><category domain="http://www.blogger.com/atom/ns#">JSR-311</category><title>JAX-RS Tip of the Day: Use GenericEntity&lt;T&gt; for Collections</title><description>A common requirement is to generate &lt;code&gt;List&amp;lt;T&amp;gt;&lt;/code&gt; for a REST service. The JAX-RS client must retrieve this, but the question is how to use it. The easiest method to use a &lt;a href="http://jersey.java.net/nonav/apidocs/1.8/jersey/javax/ws/rs/core/GenericEntity.html" target="_blank"&gt;&lt;code&gt;GenericType&amp;lt;T&amp;gt;&lt;/code&gt;&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
As an example, we have a service which returns a &lt;code&gt;List&amp;lt;Widget&amp;gt;&lt;/code&gt;;. The client application will need to wrap the returned &lt;code&gt;List&amp;lt;Widget&amp;gt;&lt;/code&gt;. We accomplish this as shown below using &lt;code&gt;GenericType&amp;lt;List&amp;lt;Widget&amp;gt;&amp;gt;(){}&lt;/code&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;hr /&gt;
&lt;script class="brush: java" type="syntaxhighlighter"&gt;
&lt;![CDATA[
  public List&lt;widget&gt; getXml_XML() throws UniformInterfaceException {
            WebResource resource = webResource;
            return resource.accept(MediaType.APPLICATION_XML).
                    get(new GenericType&lt;List&lt;widget&gt;&gt;() {
            });
        }
]]&gt;
&lt;/script&gt;
&lt;hr /&gt;
&lt;br /&gt;
The &lt;code&gt;GenericType&amp;lt;List&amp;lt;Widget&amp;gt;&amp;gt;(){}&lt;/code&gt; allows us to wrap the &lt;code&gt;List&amp;lt;Widget&amp;gt;&lt;/code&gt;, and return the &amp;lt;code&amp;gt;Collection&amp;lt;/code&amp;gt; object we are really interested in. So remember, if you need to wrap a &amp;lt;code&amp;gt;Collection&amp;lt;/code&amp;gt; use &lt;a href="http://jersey.java.net/nonav/apidocs/1.8/jersey/javax/ws/rs/core/GenericEntity.html" target="_blank"&gt;&lt;code&gt;GenericType&amp;lt;T&amp;gt;&lt;/code&gt;&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/36773632-5692142846891167967?l=javaevangelist.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/4NJCuB8ybTcdU0jUagLTMsP0vFs/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/4NJCuB8ybTcdU0jUagLTMsP0vFs/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/4NJCuB8ybTcdU0jUagLTMsP0vFs/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/4NJCuB8ybTcdU0jUagLTMsP0vFs/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/JavaEvangelistJohnYearysBlog/~4/FeyFdiLdJJ0" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/JavaEvangelistJohnYearysBlog/~3/FeyFdiLdJJ0/jax-rs-tip-of-day-use-genericentity-for.html</link><author>noreply@blogger.com (John Yeary)</author><thr:total>1</thr:total><feedburner:origLink>http://javaevangelist.blogspot.com/2011/12/jax-rs-tip-of-day-use-genericentity-for.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-36773632.post-6388380128057027749</guid><pubDate>Thu, 15 Dec 2011 13:42:00 +0000</pubDate><atom:updated>2011-12-15T08:42:35.323-05:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">example</category><category domain="http://www.blogger.com/atom/ns#">Java</category><category domain="http://www.blogger.com/atom/ns#">JDK7</category><category domain="http://www.blogger.com/atom/ns#">tutorial</category><category domain="http://www.blogger.com/atom/ns#">JSE6</category><category domain="http://www.blogger.com/atom/ns#">JSE5</category><category domain="http://www.blogger.com/atom/ns#">maven</category><category domain="http://www.blogger.com/atom/ns#">Apache</category><category domain="http://www.blogger.com/atom/ns#">JSE7</category><category domain="http://www.blogger.com/atom/ns#">Netbeans</category><title>Java Tip of the Day: Using ProcessBuilder to Make System Calls</title><description>A few years ago I posted an article on how to execute OS level system calls using the &lt;code&gt;Runtime&lt;/code&gt; class. When I wrote that article I was using a methodology which has been around since the 1.0 days of Java. In Java 5 Standard Edition, and subsequently improved in Java 6 and Java 7, is a class called &lt;code&gt;&lt;a href="http://docs.oracle.com/javase/7/docs/api/index.html" target="_blank"&gt;ProcessBuilder&lt;/a&gt;&lt;/code&gt;. This class is a significant improvement over using the &lt;code&gt;Runtime&lt;/code&gt; class. It provides complete flexibilty around the system call in terms of environment including directories, input and output streams, and execution.&lt;br /&gt;
&lt;br /&gt;
Here is the &lt;a href="http://www.netbeans.org/" target="_blank"&gt;NetBeans&lt;/a&gt; 7.1 &lt;a href="http://maven.apache.org/" target="_blank"&gt;Apache Maven&lt;/a&gt; project: &lt;a href="http://commondatastorage.googleapis.com/bluelotussoftware/code/process-builder-example.zip" target="_blank"&gt;process-builder-example.zip  &lt;/a&gt;&lt;br /&gt;
&lt;hr /&gt;
&lt;script class="brush: java" type="syntaxhighlighter"&gt;
&lt;![CDATA[
/*
 * Copyright 2011 Blue Lotus Software, LLC.
 * Copyright 2011 John Yeary &lt;jyeary@bluelotussoftware.com&gt;.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.bluelotussoftware.example;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

/**
 * &lt;p&gt;
{@link java.lang.ProcessBuilder} Example Application to execute commands
 * from command line arguments.&lt;/p&gt;
*
 * @author John Yeary &lt;jyeary@bluelotussoftware.com&gt;
 * @version 1.0
 */
public class App {

    private static void copy(InputStream in, OutputStream out) throws IOException {
        while (true) {
            int c = in.read();
            if (c == -1) {
                break;
            }
            out.write((char) c);
        }
    }

    public static void main(String[] args) throws IOException, InterruptedException {

        if (args.length == 0) {
            System.out.println("You must supply at least one argument.");
            return;
        }

        ProcessBuilder processBuilder = new ProcessBuilder(args);
        processBuilder.redirectErrorStream(true);

        Process process = processBuilder.start();
        copy(process.getInputStream(), System.out);
        process.waitFor();
        System.out.println("Exit Status : " + process.exitValue());
    }
}
]]&gt;
&lt;/script&gt;
&lt;br /&gt;
When I execute it from &lt;a href="http://www.netbeans.org/" target="_blank"&gt;NetBeans&lt;/a&gt; I get something like this:

&lt;br /&gt;
&lt;pre&gt;[exec:exec]
total 24
drwxr-xr-x  12 jyeary  staff   408B Dec 15 08:19 .hg
-rw-r--r--   1 jyeary  staff    52B Dec 15 08:08 .hgignore
-rw-r--r--   1 jyeary  staff   1.7K Dec 15 07:59 nbactions.xml
-rw-r--r--   1 jyeary  staff   2.0K Dec 15 08:19 pom.xml
drwxr-xr-x   4 jyeary  staff   136B Dec 14 23:31 src
drwxr-xr-x   4 jyeary  staff   136B Dec 15 08:35 target
Exit Status : 0
&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/36773632-6388380128057027749?l=javaevangelist.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/oLAcBUXf3o0GNB5cpooTQDGfZt8/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/oLAcBUXf3o0GNB5cpooTQDGfZt8/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/oLAcBUXf3o0GNB5cpooTQDGfZt8/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/oLAcBUXf3o0GNB5cpooTQDGfZt8/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/JavaEvangelistJohnYearysBlog/~4/Dc8A86yqv0Q" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/JavaEvangelistJohnYearysBlog/~3/Dc8A86yqv0Q/java-tip-of-day-using-processbuilder-to.html</link><author>noreply@blogger.com (John Yeary)</author><thr:total>0</thr:total><feedburner:origLink>http://javaevangelist.blogspot.com/2011/12/java-tip-of-day-using-processbuilder-to.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-36773632.post-584919758592238123</guid><pubDate>Wed, 14 Dec 2011 05:07:00 +0000</pubDate><atom:updated>2011-12-14T00:16:58.872-05:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">example</category><category domain="http://www.blogger.com/atom/ns#">mercurial</category><category domain="http://www.blogger.com/atom/ns#">tutorial</category><category domain="http://www.blogger.com/atom/ns#">source control</category><title>Subversion to Mercurial Migration: Using --splicemap to Map Branches and Merges</title><description>I am in the process of migrating all of my existing code projects to Mercurial from Subversion. However, the process has some snags associated with it. The biggest snag is that Mercurial does not understand the branching and merging process which is common in most Subversion repositories.&amp;nbsp; If you convert a repository from Subversion to Mercurial the timeline indicates the branch, but does not associate it with the parent (default head). This results in "floating" heads (branches). One blogger I found called it a &lt;a href="http://thoughts.rockhymas.com/post/573231323/branches-subversion-conversion-to-mercurial-part-2" target="_blank"&gt;multi-headed Hydra&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-fLjczyDX6rs/Tuga92Hp3MI/AAAAAAAABTI/I29arB3x7kE/s1600/FloatingHeads.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="342" src="http://2.bp.blogspot.com/-fLjczyDX6rs/Tuga92Hp3MI/AAAAAAAABTI/I29arB3x7kE/s640/FloatingHeads.png" width="640" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;Floating Heads (Branches)&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
What we really want is to show consistency, and progression. We want to show the branches and merges that are stored Subversion in Mercurial. We don't want to lose that vital historical information.&lt;br /&gt;
&lt;br /&gt;
So we now know what the problem is, but how do we fix it. It turns out that the &lt;a href="http://mercurial.selenic.com/wiki/ConvertExtension" target="_blank"&gt;convert&lt;/a&gt; extension method has a very poorly (&lt;b&gt;read not useful at all&lt;/b&gt;) documented switch called &lt;a href="http://mercurial.selenic.com/wiki/ConvertExtension#A--splicemap" target="_blank"&gt;splicemap&lt;/a&gt;. This allows us to map specific revisions in parent-child relationships.&lt;br /&gt;
&lt;br /&gt;
In the &lt;a href="http://thoughts.rockhymas.com/post/573231323/branches-subversion-conversion-to-mercurial-part-2" target="_blank"&gt;Rock Hymas blog&lt;/a&gt;, they give an example of the format for our splicemap for Subversion. It looks like the following:&lt;br /&gt;
&lt;blockquote class="tr_bq"&gt;
svn:&amp;lt;uuid&amp;gt;/path/to/module@revnum&lt;/blockquote&gt;
However, he ends short of what to do with this information, or how to obtain it. The article is good on explanation of the issue, but not on how to solve it. I will detail a solution and show you how I did it. I will also show how to use a splicemap "so that others may live"... oh wait that is the US Air Force Pararescue motto. I will show a working example to make a point.&lt;br /&gt;
&lt;h2&gt;
Process&lt;/h2&gt;
The first thing we will need is the UUID from Subversion. This can be obtained using the &lt;b&gt;svnlook&lt;/b&gt; command.
&lt;br /&gt;
&lt;blockquote class="tr_bq"&gt;
apple1:~ root# svnlook uuid /usr/local/svnhome/&lt;br /&gt;
&lt;b&gt;dbc3d074-2bd0-48a6-aa6f-e69526dc1c92&lt;/b&gt;
&lt;/blockquote&gt;
The UUID is absolutely vital. It will be different for every repository.&lt;br /&gt;
&lt;br /&gt;
Next, we need a log of the activity for the project we are interested in mapping. We will use the &lt;b&gt;svn log -v&lt;/b&gt; command to get the details. The results will look something like this.&amp;nbsp; I have shortened my output to just a couple of relevant versions which we will need.&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;------------------------------------------------------------------------
r417 | jyeary | 2011-12-11 06:28:21 -0500 (Sun, 11 Dec 2011) | 1 line
Changed paths:
   M /MailService/trunk/MailService/build.xml
   M /MailService/trunk/MailService/nbproject/build-impl.xml
   M /MailService/trunk/MailService/nbproject/genfiles.properties
   A /MailService/trunk/MailService/nbproject/jaxws-build.xml
   M /MailService/trunk/MailService/nbproject/project.properties&amp;nbsp;&lt;/pre&gt;
&lt;pre&gt;&amp;nbsp; &lt;/pre&gt;
&lt;pre&gt;Merged 3.0 tag to trunk, and updated NetBeans project files.&amp;nbsp;&lt;/pre&gt;
&lt;pre&gt;------------------------------------------------------------------------
r137 | jyeary | 2008-09-05 19:15:25 -0400 (Fri, 05 Sep 2008) | 1 line
Changed paths:
   M /MailService/branches/3.0-DEV/MailService/src/java/com/bluelotussoftware/mail/ee/ssb/MailServiceBean.java

Updated properties.
------------------------------------------------------------------------
r128 | jyeary | 2008-09-02 17:51:49 -0400 (Tue, 02 Sep 2008) | 1 line
Changed paths:
   M /MailService/trunk/MailService
   M /MailService/trunk/MailService/nbproject/project.properties
   M /MailService/trunk/MailService/src/conf/sun-ejb-jar.xml
   D /MailService/trunk/MailService/src/java/com/bluelotussoftware/mail/ee/ssb/MailService.java
   M /MailService/trunk/MailService/src/java/com/bluelotussoftware/mail/ee/ssb/MailServiceBean.java
   D /MailService/trunk/MailService/src/java/com/bluelotussoftware/mail/ee/ssb/MailServiceRemote.java
   A /MailService/trunk/MailService/src/java/com/bluelotussoftware/mail/ee/ssb/local (from /MailService/branches/2.0-DEV/MailService/src/java/com/bluelotussoftware/mail/ee/ssb/local:124)
   R /MailService/trunk/MailService/src/java/com/bluelotussoftware/mail/ee/ssb/local/MailServiceLocal.java (from /MailService/branches/2.0-DEV/MailService/src/java/com/bluelotussoftware/mail/ee/ssb/local/MailServiceLocal.java:124)
   A /MailService/trunk/MailService/src/java/com/bluelotussoftware/mail/ee/ssb/remote (from /MailService/branches/2.0-DEV/MailService/src/java/com/bluelotussoftware/mail/ee/ssb/remote:124)
   R /MailService/trunk/MailService/src/java/com/bluelotussoftware/mail/ee/ssb/remote/MailServiceRemote.java (from /MailService/branches/2.0-DEV/MailService/src/java/com/bluelotussoftware/mail/ee/ssb/remote/MailServiceRemote.java:124)

merged 2.0 changes into trunk.
------------------------------------------------------------------------
&lt;/pre&gt;
&lt;br /&gt;
Next we determine how to splice it together. We want to ensure that the parents, and children match up.&amp;nbsp; The file format is: &lt;b&gt;child parent&lt;/b&gt; with a space between the child and parent. We may also provide an additional parent which is separated by a comma such as &lt;b&gt;child parent1,parent2&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
So the first splice in the splicemap for the 2.0-DEV branch looks like this:&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;svn:dbc3d074-2bd0-48a6-aa6f-e69526dc1c92/MailService/branches/2.0-DEV@95 svn:dbc3d074-2bd0-48a6-aa6f-e69526dc1c92/MailService/trunk@57
&lt;/pre&gt;
&lt;br /&gt;
&lt;b&gt;Note:&lt;/b&gt; I am splicing the branch to the trunk (parent). &lt;br /&gt;
&lt;br /&gt;
Using the &lt;b&gt;hg convert --datesort --splicemap splicemap1 http://10.0.1.2/svn/MailService&lt;/b&gt; resulted in the following output:&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;assuming destination MailService-hg
initializing destination MailService-hg repository
svn: cannot probe remote repository, assume it could be a subversion repository. Use --source-type if you know better.
scanning source...
sorting...
converting...
21 creating structure
20 Moving project out of MailServiceApplication
19 Fixed javadoc
18 [Netbeans SVN client generated message: create a new folder for the copy]: '
spliced in ['svn:dbc3d074-2bd0-48a6-aa6f-e69526dc1c92/MailService/trunk@57'] as parents of svn:dbc3d074-2bd0-48a6-aa6f-e69526dc1c92/MailService/branches/2.0-DEV@95
17 2.0 development branch
16 1. Updated version numbers.
15 Added new sendMessage() method that allows for different MIME types.
14 1.Added new MimeMessage format to @Remote
13 1.Added new MimeMessage format to @Local
12 1. Added new MimeMessage format
11 Updated project properties
10 1. Created a new local package
9 1. Updated Javadocs
8 Updated project properties
7 merged 2.0 changes into trunk.
6 Adding new development branch
5 Adding trunk to 3.0 Development branch
4 Removed @Local interface implementation from bean.
3 Removed @Local interface.
2 Removed directory.
1 Updated properties.
0 Merged 3.0 tag to trunk, and updated NetBeans project files.
updating tags
&lt;/pre&gt;
&lt;br /&gt;
More importantly, the result is what we are looking for. See the image below.&lt;br /&gt;
&lt;br /&gt;
&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-Z97QfJbbLDs/TugocYmVg1I/AAAAAAAABTQ/tbKa0Yx1FNs/s1600/Branch.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="342" src="http://4.bp.blogspot.com/-Z97QfJbbLDs/TugocYmVg1I/AAAAAAAABTQ/tbKa0Yx1FNs/s640/Branch.png" width="640" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;Branch&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
Alright, that solved the branching problem, but the more difficult issue is the merge. I was banging my head on my desk when I came across this &lt;a href="http://www.selenic.com/pipermail/mercurial/2009-July/026961.html" target="_blank"&gt;Nabble post by Bruce Frederiksen&lt;/a&gt; which gave me the clue I needed to merge the branch back to the default head.&lt;br /&gt;
&lt;br /&gt;
We need to tell Mercurial what the parent branches are for the merge from the perspective of the repository. In this case we want the revision at 57 as one parent from the branch above, and the other to be the revision we merge at on the default head. In this case revision 123. We also need to reverse the order (remember what I said about perspective... thanks Bruce). Our new splice looks like:&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;svn:dbc3d074-2bd0-48a6-aa6f-e69526dc1c92/MailService/branches/2.0-DEV@95 svn:dbc3d074-2bd0-48a6-aa6f-e69526dc1c92/MailService/trunk@57
svn:dbc3d074-2bd0-48a6-aa6f-e69526dc1c92/MailService/trunk@127 svn:dbc3d074-2bd0-48a6-aa6f-e69526dc1c92/MailService/trunk@57,\
svn:dbc3d074-2bd0-48a6-aa6f-e69526dc1c92/MailService/branches/2.0-DEV@123
&lt;/pre&gt;
&lt;br /&gt;
&lt;b&gt;Note:&lt;/b&gt; I am splicing the trunk@127 to the trunk@57 and branch@123. This is the trick.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Note:&lt;/b&gt; The splices are wrapped to fit on the page, the actual file requires each complete splice to be on a new line. &lt;br /&gt;
&lt;br /&gt;
The result when we run the hg convert command again results in &lt;b&gt;merging&lt;/b&gt;&amp;nbsp; the branch back to the default head.&lt;br /&gt;
&lt;br /&gt;
&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-nHuZUCzbPeY/TugsMB1AeFI/AAAAAAAABTY/8J6JbXqPPuM/s1600/BranchMerge.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="342" src="http://2.bp.blogspot.com/-nHuZUCzbPeY/TugsMB1AeFI/AAAAAAAABTY/8J6JbXqPPuM/s640/BranchMerge.png" width="640" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;Branch-Merge&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
Finally, I make the remaining splices to complete the mapping which look like:&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;svn:dbc3d074-2bd0-48a6-aa6f-e69526dc1c92/MailService/branches/2.0-DEV@95 svn:dbc3d074-2bd0-48a6-aa6f-e69526dc1c92/MailService/trunk@57
svn:dbc3d074-2bd0-48a6-aa6f-e69526dc1c92/MailService/trunk@127 svn:dbc3d074-2bd0-48a6-aa6f-e69526dc1c92/MailService/trunk@57,\
svn:dbc3d074-2bd0-48a6-aa6f-e69526dc1c92/MailService/branches/2.0-DEV@123
svn:dbc3d074-2bd0-48a6-aa6f-e69526dc1c92/MailService/branches/3.0-DEV@129 svn:dbc3d074-2bd0-48a6-aa6f-e69526dc1c92/MailService/trunk@128
svn:dbc3d074-2bd0-48a6-aa6f-e69526dc1c92/MailService/trunk@417 svn:dbc3d074-2bd0-48a6-aa6f-e69526dc1c92/MailService/trunk@128,\
svn:dbc3d074-2bd0-48a6-aa6f-e69526dc1c92/MailService/branches/3.0-DEV@137
&lt;/pre&gt;
&lt;br /&gt;
&lt;b&gt;Note:&lt;/b&gt; The splices are wrapped to fit on the page, the actual file requires each complete splice to be on a new line. &lt;br /&gt;
&lt;br /&gt;
This results in the final completed completed product.&lt;br /&gt;
&lt;br /&gt;
&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-i0xcS2wWMSI/TugtTGigVnI/AAAAAAAABTg/K4FRp5Splgs/s1600/FinalBranchMerge.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="342" src="http://3.bp.blogspot.com/-i0xcS2wWMSI/TugtTGigVnI/AAAAAAAABTg/K4FRp5Splgs/s640/FinalBranchMerge.png" width="640" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;Completed&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;h2&gt;


Conclusion&lt;/h2&gt;
I hope that this explains how to effectively use a splicemap to branch and merge your Subversion repository into Mercurial. I hope that this saves some other unfortunate developers from trying to figure out a really cool, but poorly documented feature of the convert extension.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/36773632-584919758592238123?l=javaevangelist.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/V7Mo_Y1yALYMsHsELHiNhT96gvo/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/V7Mo_Y1yALYMsHsELHiNhT96gvo/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/V7Mo_Y1yALYMsHsELHiNhT96gvo/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/V7Mo_Y1yALYMsHsELHiNhT96gvo/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/JavaEvangelistJohnYearysBlog/~4/nqK290ru-_M" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/JavaEvangelistJohnYearysBlog/~3/nqK290ru-_M/subversion-to-mercurial-migration-using.html</link><author>noreply@blogger.com (John Yeary)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://2.bp.blogspot.com/-fLjczyDX6rs/Tuga92Hp3MI/AAAAAAAABTI/I29arB3x7kE/s72-c/FloatingHeads.png" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://javaevangelist.blogspot.com/2011/12/subversion-to-mercurial-migration-using.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-36773632.post-6837819382451045212</guid><pubDate>Wed, 14 Dec 2011 03:00:00 +0000</pubDate><atom:updated>2011-12-13T22:13:51.502-05:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">open source</category><category domain="http://www.blogger.com/atom/ns#">SSL</category><category domain="http://www.blogger.com/atom/ns#">example</category><category domain="http://www.blogger.com/atom/ns#">mercurial</category><category domain="http://www.blogger.com/atom/ns#">JavaEE</category><category domain="http://www.blogger.com/atom/ns#">tutorial</category><category domain="http://www.blogger.com/atom/ns#">glassfish</category><category domain="http://www.blogger.com/atom/ns#">source control</category><category domain="http://www.blogger.com/atom/ns#">Netbeans</category><category domain="http://www.blogger.com/atom/ns#">JEE6</category><title>Secure Mercurial in GlassFish using SSL</title><description>&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://www.selenic.com/hg-logo/logo-droplets-200.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://www.selenic.com/hg-logo/logo-droplets-200.png" /&gt;&lt;/a&gt;&lt;/div&gt;
A friend of mine, Wade Chandler, contacted me the other day to ask about implementing security (SSL) for Mercurial on GlassFish. Wade is NetBeans Dream Team member, and all-around great guy. I told him I would figure it out, and tell him how to do it. I also decided that I would explain to everyone how to take advantage of this cool functionality using GlassFish 3.1.1 and NetBeans 7.1 RC 2.&amp;nbsp; &lt;br /&gt;
&lt;br /&gt;
In&amp;nbsp; a previous blog entry, &lt;a href="http://javaevangelist.blogspot.com/2009/05/mercurial-on-glassfish-21-using.html"&gt;Mercurial on GlassFish 2.1 Using Multiple Repositories&lt;/a&gt;, I successfully deployed Mercurial repositories on GlassFish. This time I have given everything a Java EE 6 upgrade.&lt;br /&gt;
&lt;br /&gt;
One of the great aspects of using GlassFish to provide SSL is that we don't require messy configuration in Python and Mercurial to implement SSL. GlassFish handles the security for us. The only thing that the end client users will want to do is add the server fingerprint to the .hgrc file in their home directory. This will remove any warnings about a missing server fingerprint, or cacerts file.&lt;br /&gt;
&lt;br /&gt;
If you have used Mercurial on Apache HTTPD Server, along with cacerts, and client certificates... this will make you make the switch immediately.&lt;br /&gt;
&lt;h2&gt;




















Requirements:&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://glassfish.java.net/"&gt;GlassFish 3.1.1&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://netbeans.org/"&gt;NetBeans 7.1 RC2 +&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://mercurial.selenic.com/"&gt;Mercurial 1.9.3+&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://commondatastorage.googleapis.com/bluelotussoftware/code/Mercurial.zip"&gt;Mercurial.zip&lt;/a&gt; (Required)&lt;/li&gt;
&lt;li&gt;&lt;a href="http://commondatastorage.googleapis.com/bluelotussoftware/code/repos.zip"&gt;repos.zip&lt;/a&gt; (Optional)&lt;/li&gt;
&lt;/ul&gt;
You can create your own web project in NetBeans, but the Mercurial.zip is a self-contained Mercurial repository, and NetBeans project which can serve as the basis for your own server with very little modification. I would simply use my project as the basis for your own deployment.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Note:&lt;/b&gt; The requirements include repos.zip which is optional. The repos.zip contains sample mercurial repos which are required for the demo.&lt;br /&gt;
&lt;br /&gt;
&lt;h2&gt;




Procedures&lt;/h2&gt;
&lt;h3&gt;




Configure GlassFish&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;Start the GlassFish administration console.&lt;/li&gt;
&lt;li&gt;Go to &lt;i&gt;Configuration&lt;/i&gt; → &lt;i&gt;server-config&lt;/i&gt; → &lt;i&gt;Security&lt;/i&gt; → &lt;i&gt;Realms&lt;/i&gt; → &lt;i&gt;file&lt;/i&gt;. &lt;br /&gt;&lt;b&gt;Note:&lt;/b&gt; You may create your own realm, this is just for demonstration purposes.&lt;/li&gt;
&lt;li&gt;Click on &lt;i&gt;Manage Users&lt;/i&gt;.&lt;br /&gt;
&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-D3IBXX1FqTU/TugADgRc7BI/AAAAAAAABS0/6uThc9yrYCM/s1600/FileRealm.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="212" src="http://1.bp.blogspot.com/-D3IBXX1FqTU/TugADgRc7BI/AAAAAAAABS0/6uThc9yrYCM/s400/FileRealm.png" width="400" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;GlassFish Security Configuration&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/li&gt;
&lt;li&gt;Click on &lt;i&gt;New&lt;/i&gt;. Add a user called &lt;b&gt;mercurial&lt;/b&gt; in a group called &lt;b&gt;Mercurial Users&lt;/b&gt; with the password &lt;b&gt;hg&lt;/b&gt;.&lt;br /&gt;&lt;b&gt;Note:&lt;/b&gt; Please change the username, group, and password for production.&lt;/li&gt;
&lt;li&gt;The server configuration is complete.&lt;/li&gt;
&lt;/ol&gt;
&lt;br /&gt;
&lt;h3&gt;




NetBeans&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;Using NetBeans open the &lt;b&gt;Mercurial&lt;/b&gt; project from the requirements link above.&lt;/li&gt;
&lt;li&gt;There are four files in the project (simple huh?) which control the behavior of the Mercurial repository on GlassFish: &lt;i&gt;hgweb.cgi&lt;/i&gt;, &lt;i&gt;hgweb.config&lt;/i&gt;, &lt;i&gt;web.xml&lt;/i&gt;, and &lt;i&gt;glassfish-web.xml&lt;/i&gt;.&lt;/li&gt;
&lt;li&gt;The &lt;i&gt;hgweb.cgi&lt;/i&gt; should not need to be modified under normal circumstances.&lt;/li&gt;
&lt;li&gt;Open the &lt;i&gt;hgweb.config&lt;/i&gt; file. Make any changes that you would like to customize the application. Pay particular attention to the location of the repositories.&lt;br /&gt;There are two examples: (1) using the "/" along with a * on the end of the file path will list all repositories in the specified directory, and (2) a specific listing.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Note:&lt;/b&gt; Please note that &lt;b&gt;allow_push = *&lt;/b&gt; and &lt;b&gt;push_ssl = false&lt;/b&gt; are set. This will allow push to the server and let GlassFish take care of the SSL.&lt;/li&gt;
&lt;li&gt;The &lt;i&gt;web.xml&lt;/i&gt; file has been modified to add security constraints for the alpha, and beta example repositories.&lt;br /&gt;The alpha repository has security only on PUT, POST, and DELETE.&lt;br /&gt; The beta repository will not allow you to perform any actions without logging into the server.&lt;br /&gt;The gamma repository has no security constraints.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Note:&lt;/b&gt; You will need to modify the security constraints to meet your requirements.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Note:&lt;/b&gt; You secure the entire repository by adding:&lt;br /&gt;&lt;code&gt;&amp;lt;url-pattern&amp;gt;/cgi-bin/hgweb.cgi/*&amp;lt;/url-pattern&amp;gt;&lt;/code&gt;.&lt;br /&gt;&lt;br /&gt;
&lt;script class="brush: xml" type="syntaxhighlighter"&gt;
&lt;![CDATA[
&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;web-app xmlns="http://java.sun.com/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
         version="3.0"&gt;
    &lt;servlet&gt;
        &lt;servlet-name&gt;cgi&lt;/servlet-name&gt;
        &lt;servlet-class&gt;org.apache.catalina.servlets.CGIServlet&lt;/servlet-class&gt;
        &lt;init-param&gt;
            &lt;param-name&gt;debug&lt;/param-name&gt;
            &lt;param-value&gt;1&lt;/param-value&gt;
        &lt;/init-param&gt;
        &lt;init-param&gt;
            &lt;param-name&gt;cgiPathPrefix&lt;/param-name&gt;
            &lt;param-value&gt;WEB-INF/cgi&lt;/param-value&gt;
        &lt;/init-param&gt;
        &lt;load-on-startup&gt;5&lt;/load-on-startup&gt;
    &lt;/servlet&gt;
    &lt;servlet-mapping&gt;
        &lt;servlet-name&gt;cgi&lt;/servlet-name&gt;
        &lt;url-pattern&gt;/cgi-bin/*&lt;/url-pattern&gt;
    &lt;/servlet-mapping&gt;
    &lt;session-config&gt;
        &lt;session-timeout&gt;
            30
        &lt;/session-timeout&gt;
    &lt;/session-config&gt;
    &lt;welcome-file-list&gt;
        &lt;welcome-file&gt;cgi-bin/hgweb.cgi&lt;/welcome-file&gt;
    &lt;/welcome-file-list&gt;
    &lt;security-constraint&gt;
        &lt;display-name&gt;Alpha&lt;/display-name&gt;
        &lt;web-resource-collection&gt;
            &lt;web-resource-name&gt;alpha&lt;/web-resource-name&gt;
            &lt;description/&gt;
            &lt;url-pattern&gt;/cgi-bin/hgweb.cgi/alpha/*&lt;/url-pattern&gt;
            &lt;http-method&gt;PUT&lt;/http-method&gt;
            &lt;http-method&gt;POST&lt;/http-method&gt;
            &lt;http-method&gt;DELETE&lt;/http-method&gt;
        &lt;/web-resource-collection&gt;
        &lt;auth-constraint&gt;
            &lt;description/&gt;
            &lt;role-name&gt;Mercurial Users&lt;/role-name&gt;
        &lt;/auth-constraint&gt;
    &lt;/security-constraint&gt;
    &lt;security-constraint&gt;
        &lt;display-name&gt;Beta&lt;/display-name&gt;
        &lt;web-resource-collection&gt;
            &lt;web-resource-name&gt;beta&lt;/web-resource-name&gt;
            &lt;description/&gt;
            &lt;url-pattern&gt;/cgi-bin/hgweb.cgi/beta/*&lt;/url-pattern&gt;
        &lt;/web-resource-collection&gt;
        &lt;auth-constraint&gt;
            &lt;description/&gt;
            &lt;role-name&gt;Mercurial Users&lt;/role-name&gt;
        &lt;/auth-constraint&gt;
    &lt;/security-constraint&gt;
    &lt;login-config&gt;
        &lt;auth-method&gt;BASIC&lt;/auth-method&gt;
        &lt;realm-name&gt;file&lt;/realm-name&gt;
    &lt;/login-config&gt;
    &lt;security-role&gt;
        &lt;description/&gt;
        &lt;role-name&gt;Mercurial Users&lt;/role-name&gt;
    &lt;/security-role&gt;
&lt;/web-app&gt;
]]&gt;
&lt;/script&gt;
&lt;/li&gt;
&lt;li&gt;The &lt;i&gt;glassfish-web.xml&lt;/i&gt; is used to map the security role(s) to the &lt;i&gt;file&lt;/i&gt; realm on the GlassFish server.&lt;br /&gt;
&lt;script class="brush: xml" type="syntaxhighlighter"&gt;
&lt;![CDATA[
  &lt;security-role-mapping&gt;
    &lt;role-name&gt;Mercurial Users&lt;/role-name&gt;
    &lt;group-name&gt;Mercurial Users&lt;/group-name&gt;
  &lt;/security-role-mapping&gt;
]]&gt;
&lt;/script&gt;&lt;/li&gt;
&lt;li&gt;Clean, build, and Run the application.&lt;/li&gt;
&lt;li&gt;When the application successfully deploys, go to the secure connection on &lt;a href="https://localhost:8181/Mercurial"&gt;https://localhost:8181/Mercurial&lt;/a&gt;. It may prompt you to accept the server certificate. Accept it.&lt;/li&gt;
&lt;li&gt;You should see something like the image below:&lt;br /&gt;
&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-Ok6ChjfRlX8/TugK8B_FaWI/AAAAAAAABTA/JSa9FOAwpmY/s1600/HgRepos.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="66" src="http://4.bp.blogspot.com/-Ok6ChjfRlX8/TugK8B_FaWI/AAAAAAAABTA/JSa9FOAwpmY/s640/HgRepos.png" width="640" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;Mercurial Repositories&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/li&gt;
&lt;li&gt;Click on the &lt;i&gt;beta&lt;/i&gt; repository. It should prompt you to login.
&lt;/li&gt;
&lt;li&gt;&lt;b&gt;Congratulations&lt;/b&gt; you are running Mercurial on GlassFish securely.&lt;/li&gt;
&lt;/ol&gt;
&lt;br /&gt;
&lt;b&gt;Note:&lt;/b&gt; To secure the application completely, you should disable the non-secure http port listener on port 8080, or redirect requests to the secure port.&amp;nbsp; &lt;br /&gt;
&lt;h2&gt;






Verification&lt;/h2&gt;
It would be unwise to accept that the application is secure without verification.&lt;br /&gt;
&lt;br /&gt;
I made this demonstration video to prove the connection is secure. The demonstration shows both insecure and secure connections to the repository. I use &lt;a href="http://www.wireshark.org/"&gt;Wireshark&lt;/a&gt; to sniff the connection, and pull the repository from the command line using &lt;code&gt;hg clone&lt;/code&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;iframe allowfullscreen="" frameborder="0" height="720" src="http://www.youtube.com/embed/hirHBnBYTX8?hd=1" width="960"&gt;&lt;/iframe&gt;
&lt;br /&gt;
&lt;h2&gt;





Conclusion&lt;/h2&gt;
Mercurial is a great distributed source control system. Its ease of use is further enhanced by using GlassFish 3.1.1 to provide the front end to your repository. It also simplifies the deployment, and use models.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/36773632-6837819382451045212?l=javaevangelist.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/-a2btcEm_-Mlzl6ileuWxCfT_E8/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/-a2btcEm_-Mlzl6ileuWxCfT_E8/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/-a2btcEm_-Mlzl6ileuWxCfT_E8/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/-a2btcEm_-Mlzl6ileuWxCfT_E8/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/JavaEvangelistJohnYearysBlog/~4/2RRt7ydocRc" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/JavaEvangelistJohnYearysBlog/~3/2RRt7ydocRc/secure-mercurial-in-glassfish-using-ssl.html</link><author>noreply@blogger.com (John Yeary)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/-D3IBXX1FqTU/TugADgRc7BI/AAAAAAAABS0/6uThc9yrYCM/s72-c/FileRealm.png" height="72" width="72" /><thr:total>2</thr:total><feedburner:origLink>http://javaevangelist.blogspot.com/2009/05/secure-mercurial-in-glassfish-using-ssl.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-36773632.post-4343971470213755412</guid><pubDate>Sat, 03 Dec 2011 04:27:00 +0000</pubDate><atom:updated>2011-12-05T11:19:51.352-05:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">example</category><category domain="http://www.blogger.com/atom/ns#">Java</category><category domain="http://www.blogger.com/atom/ns#">JAXB</category><category domain="http://www.blogger.com/atom/ns#">JavaEE</category><category domain="http://www.blogger.com/atom/ns#">tutorial</category><category domain="http://www.blogger.com/atom/ns#">Collections</category><category domain="http://www.blogger.com/atom/ns#">Netbeans</category><category domain="http://www.blogger.com/atom/ns#">JEE6</category><title>Java Tip of the Day: Generic JAXB Map&lt;K, V&gt;  XmlAdapter</title><description>There are a couple of well-known issues with using &lt;code&gt;Map&amp;lt;K,V&amp;gt;&lt;/code&gt; with JAXB. First, JAXB does not like interfaces. Second, it considers a &lt;code&gt;Map&amp;lt;K,V&amp;gt;&lt;/code&gt; to be a bean so it does not handle the internal implementation. The JAXB JIRA Issue is here &lt;a href="http://java.net/jira/browse/JAXB-223"&gt;JAXB-223&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
There are a number of articles published about how to adapt a &lt;code&gt;Map&amp;lt;K,V&amp;gt;&lt;/code&gt; to work in JAXB. However, all of them I have seen are very specific mappings like &lt;code&gt;Map&amp;lt;String,String&amp;gt;&lt;/code&gt;, or &lt;code&gt;Map&amp;lt;Integer,String&amp;gt;&lt;/code&gt;, etc. None of them address the more specific generic case &lt;code&gt;Map&amp;lt;K,V&amp;gt;&lt;/code&gt;. This example handles the more general case using generics. All the other examples I looked at online generally follow the example code from the &lt;a href="http://docs.oracle.com/javase/6/docs/api/javax/xml/bind/annotation/adapters/XmlAdapter.html"&gt;&lt;code&gt;XmlAdapter&lt;/code&gt;&lt;/a&gt; javadoc. The code snippet does not encapsulate the values, and generally does not adhere to good coding practices.&lt;br /&gt;
&lt;br /&gt;
The process is to create an adapter is as follows:&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;Create an mapping entry for &lt;code&gt;Map&amp;lt;K,V&amp;gt;&lt;/code&gt;. In our case, we will create one called: &lt;code&gt;MapEntryType&amp;lt;K, V&amp;gt;&lt;/code&gt; which will map our generic types.&lt;/li&gt;
&lt;li&gt;Next we create a value holder for our &lt;code&gt;Map&amp;lt;K,V&amp;gt;&lt;/code&gt; which contains a &lt;code&gt;List&amp;lt;MapEntryType&amp;lt;K, V&amp;gt;&amp;gt;&lt;/code&gt; of our entries. The value holder looks like &lt;code&gt;MapType&amp;lt;K, V&amp;gt;&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Finally, we create an adapter which extends &lt;a href="http://docs.oracle.com/javase/6/docs/api/javax/xml/bind/annotation/adapters/XmlAdapter.html"&gt;&lt;code&gt;XmlAdapter&lt;/code&gt;&lt;/a&gt;. In our case, it is very long since I am using Java 6. In Java 7, we can use the diamond &amp;lt;&amp;gt; operator to shorten it. The adapter is &lt;code&gt;XmlGenericMapAdapter&amp;lt;K, V&amp;gt; extends XmlAdapter&amp;lt;MapType&amp;lt;K, V&amp;gt;, Map&amp;lt;K, V&amp;gt;&amp;gt;&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;b&gt;Note:&lt;/b&gt; Please note that the &lt;code&gt;MapEntryType&amp;lt;K, V&amp;gt;&lt;/code&gt; has the &lt;code&gt;@XmlAccessorType(XmlAccessType.PROPERTY)&lt;/code&gt; set to property and the getters are annotated as &lt;code&gt;@XmlElement&lt;/code&gt;.&lt;br /&gt;
&lt;br /&gt;
The &lt;a href="http://www.netbeans.org/"&gt;NetBeans 7.1 RC1&lt;/a&gt; &lt;a href="http://maven.apache.org/"&gt;Apache Maven&lt;/a&gt; project can be downloaded here: &lt;a href="http://commondatastorage.googleapis.com/bluelotussoftware/code/generic-jaxb-map-adapter.zip"&gt;generic-jaxb-map-adapter.zip&lt;/a&gt;
&lt;br /&gt;
&lt;h2&gt;








MapEntryType&amp;lt;K, V&amp;gt;&lt;/h2&gt;
&lt;hr /&gt;
&lt;script class="brush: java" type="syntaxhighlighter"&gt;
&lt;![CDATA[
/*
 * Copyright 2011 John Yeary &lt;jyeary@bluelotussoftware.com&gt;.
 * Copyright 2011 Bluelotus Software, LLC.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/*
 * $Id: MapEntryType.java 399 2011-12-03 04:22:50Z jyeary $
 */
package com.bluelotussoftware.jaxb.adapter;

import java.util.Map;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;

/**
 *
 * @author John Yeary &lt;jyeary@bluelotussoftware.com&gt;
 * @version 1.0
 */
@XmlAccessorType(XmlAccessType.PROPERTY)
public class MapEntryType&lt;K, V&gt; {

    private K key;
    private V value;

    public MapEntryType() {
    }

    public MapEntryType(Map.Entry&lt;K, V&gt; e) {
        key = e.getKey();
        value = e.getValue();
    }

    @XmlElement
    public K getKey() {
        return key;
    }

    public void setKey(K key) {
        this.key = key;
    }

    @XmlElement
    public V getValue() {
        return value;
    }

    public void setValue(V value) {
        this.value = value;
    }
}
]]&gt;
&lt;/script&gt;
&lt;br /&gt;
&lt;h2&gt;






MapType&amp;lt;K, V&amp;gt;&lt;/h2&gt;
&lt;hr /&gt;
&lt;script class="brush: java" type="syntaxhighlighter"&gt;
&lt;![CDATA[
/*
 * Copyright 2011 John Yeary &lt;jyeary@bluelotussoftware.com&gt;.
 * Copyright 2011 Bluelotus Software, LLC.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/*
 * $Id: MapType.java 399 2011-12-03 04:22:50Z jyeary $
 */
package com.bluelotussoftware.jaxb.adapter;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 *
 * @author John Yeary &lt;jyeary@bluelotussoftware.com&gt;
 * @version 1.0
 */
public class MapType&lt;K, V&gt; {

    private List&lt;MapEntryType&lt;K, V&gt;&gt; entry = new ArrayList&lt;MapEntryType&lt;K, V&gt;&gt;();

    public MapType() {
    }

    public MapType(Map&lt;K, V&gt; map) {
        for (Map.Entry&lt;K, V&gt; e : map.entrySet()) {
            entry.add(new MapEntryType&lt;K, V&gt;(e));
        }
    }

    public List&lt;MapEntryType&lt;K, V&gt;&gt; getEntry() {
        return entry;
    }

    public void setEntry(List&lt;MapEntryType&lt;K, V&gt;&gt; entry) {
        this.entry = entry;
    }
}
]]&gt;
&lt;/script&gt;
&lt;br /&gt;
&lt;h2&gt;






XmlGenericMapAdapter&amp;lt;K, V&amp;gt; extends XmlAdapter&amp;lt;MapType&amp;lt;K, V&amp;gt;, Map&amp;lt;K, V&amp;gt;&amp;gt;&lt;/h2&gt;
&lt;hr /&gt;
&lt;script class="brush: java" type="syntaxhighlighter"&gt;
&lt;![CDATA[
/*
 * Copyright 2011 John Yeary &lt;jyeary@bluelotussoftware.com&gt;.
 * Copyright 2011 Bluelotus Software, LLC.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/*
 * $Id: XmlGenericMapAdapter.java 399 2011-12-03 04:22:50Z jyeary $
 */
package com.bluelotussoftware.jaxb.adapter;

import java.util.HashMap;
import java.util.Map;
import javax.xml.bind.annotation.adapters.XmlAdapter;

/**
 *
 * @author John Yeary &lt;jyeary@bluelotussoftware.com&gt;
 * @version 1.0
 */
public class XmlGenericMapAdapter&lt;K, V&gt; extends XmlAdapter&lt;MapType&lt;K, V&gt;, Map&lt;K, V&gt;&gt; {

    @Override
    public Map&lt;K, V&gt; unmarshal(MapType&lt;K, V&gt; v) throws Exception {
        HashMap&lt;K, V&gt; map = new HashMap&lt;K, V&gt;();

        for (MapEntryType&lt;K, V&gt; mapEntryType : v.getEntry()) {
            map.put(mapEntryType.getKey(), mapEntryType.getValue());
        }
        return map;
    }

    @Override
    public MapType marshal(Map&lt;K, V&gt; v) throws Exception {
        MapType&lt;K, V&gt; mapType = new MapType&lt;K, V&gt;();

        for (Map.Entry&lt;K, V&gt; entry : v.entrySet()) {
            MapEntryType&lt;K, V&gt; mapEntryType = new MapEntryType&lt;K, V&gt;();
            mapEntryType.setKey(entry.getKey());
            mapEntryType.setValue(entry.getValue());
            mapType.getEntry().add(mapEntryType);
        }
        return mapType;
    }
}
]]&gt;
&lt;/script&gt;
&lt;br /&gt;
Here is the output from our adapter.&lt;br /&gt;
&lt;script class="brush: xml" type="syntaxhighlighter"&gt;
&lt;![CDATA[
&lt;?xml version="1.0" encoding="UTF-8" standalone="yes"?&gt;
&lt;mapvalueholder&gt;
    &lt;map&gt;
        &lt;entry&gt;
            &lt;key xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:string"&gt;Beta&lt;/key&gt;
            &lt;value xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:string"&gt;Beta&lt;/value&gt;
        &lt;/entry&gt;
        &lt;entry&gt;
            &lt;key xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:string"&gt;Alpha&lt;/key&gt;
            &lt;value xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:string"&gt;Alpha&lt;/value&gt;
        &lt;/entry&gt;
        &lt;entry&gt;
            &lt;key xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:string"&gt;Delta&lt;/key&gt;
            &lt;value xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:string"&gt;Delta&lt;/value&gt;
        &lt;/entry&gt;
        &lt;entry&gt;
            &lt;key xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:string"&gt;Epsilon&lt;/key&gt;
            &lt;value xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:string"&gt;Epsilon&lt;/value&gt;
        &lt;/entry&gt;
        &lt;entry&gt;
            &lt;key xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:string"&gt;Gamma&lt;/key&gt;
            &lt;value xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:string"&gt;Gamma&lt;/value&gt;
        &lt;/entry&gt;
    &lt;/map&gt;
&lt;/mapValueHolder&gt;
]]&gt;
&lt;/script&gt;
&lt;br /&gt;
We take advantage of JAXB to provide automatic XML Schema definitions for our keys and values. The only problem with this approach is that it is very "chatty". It provides a schema definition for each key and value.&lt;br /&gt;
&lt;br /&gt;
If you know that you are going to be using simple types, it is more appropriate to use a specific type rather than using generics. We would replace all of the &amp;lt;K, V&amp;gt; with &amp;lt;String, String&amp;gt;. This will remove all of the schema definitions and produce an output which is much cleaner. The &lt;code&gt;String&lt;/code&gt; adapters are included in the source code for further review.&lt;br /&gt;
&lt;script class="brush: xml" type="syntaxhighlighter"&gt;
&lt;![CDATA[
&lt;?xml version="1.0" encoding="UTF-8" standalone="yes"?&gt;
&lt;mapvalueholder&gt;
    &lt;map&gt;
        &lt;entry&gt;
            &lt;key&gt;Beta&lt;/key&gt;
            &lt;value&gt;Beta&lt;/value&gt;
        &lt;/entry&gt;
        &lt;entry&gt;
            &lt;key&gt;Alpha&lt;/key&gt;
            &lt;value&gt;Alpha&lt;/value&gt;
        &lt;/entry&gt;
        &lt;entry&gt;
            &lt;key&gt;Delta&lt;/key&gt;
            &lt;value&gt;Delta&lt;/value&gt;
        &lt;/entry&gt;
        &lt;entry&gt;
            &lt;key&gt;Epsilon&lt;/key&gt;
            &lt;value&gt;Epsilon&lt;/value&gt;
        &lt;/entry&gt;
        &lt;entry&gt;
            &lt;key&gt;Gamma&lt;/key&gt;
            &lt;value&gt;Gamma&lt;/value&gt;
        &lt;/entry&gt;
    &lt;/map&gt;
&lt;/mapValueHolder&gt;
]]&gt;
&lt;/script&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/36773632-4343971470213755412?l=javaevangelist.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/Gmjz0kczF5hQlwtF-WDUNT0mrlo/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Gmjz0kczF5hQlwtF-WDUNT0mrlo/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/Gmjz0kczF5hQlwtF-WDUNT0mrlo/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Gmjz0kczF5hQlwtF-WDUNT0mrlo/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/JavaEvangelistJohnYearysBlog/~4/xsBA5XtiAQ8" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/JavaEvangelistJohnYearysBlog/~3/xsBA5XtiAQ8/java-tip-of-day-generic-jaxb-map-v.html</link><author>noreply@blogger.com (John Yeary)</author><thr:total>0</thr:total><feedburner:origLink>http://javaevangelist.blogspot.com/2011/12/java-tip-of-day-generic-jaxb-map-v.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-36773632.post-8167248413950733396</guid><pubDate>Fri, 02 Dec 2011 20:12:00 +0000</pubDate><atom:updated>2011-12-02T21:42:49.873-05:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">example</category><category domain="http://www.blogger.com/atom/ns#">Java</category><category domain="http://www.blogger.com/atom/ns#">tutorial</category><category domain="http://www.blogger.com/atom/ns#">Collections</category><category domain="http://www.blogger.com/atom/ns#">maven</category><category domain="http://www.blogger.com/atom/ns#">Netbeans</category><title>Coding Tip of the Day: Using Map&lt;?,?&gt; Collections</title><description>I was working on some code in the last few days where I came across a &lt;code&gt;protected Map map&lt;/code&gt; instance variable. I examined the code and javadocs which indicated that the intent was to provide a mapping of keys and values. However the actual implementation was setting the keys and values to the same value. This again is not really an issue. However, the usage of the &lt;code&gt;Map&lt;/code&gt; was incorrect.&lt;br /&gt;
&lt;br /&gt;
See if you can determine the issue from the code below.&lt;br /&gt;
&lt;script class="brush: java" type="syntaxhighlighter"&gt;
&lt;![CDATA[
...

private static MapValueHolder&lt;String, String&gt; me;

    public static void main(String[] args) {

        me = new MapValueHolderImpl&lt;String, String&gt;();
        Map&lt;String, String&gt; mx = new HashMap&lt;String, String&gt;();
        mx.put("A", "A");
        mx.put("B", "B");
        mx.put("C", "C");
        me.setMap(mx);


        for (String key : me.getMap().keySet()) {
            System.out.println("MapValueHolder Key --&gt; " + key);
        }

        for (String key : me.getMap().keySet()) {
            System.out.println(key + " --&gt; " + me.getMap().get(key));
        }
...
]]&gt;
&lt;/script&gt;

The &lt;code&gt;MapValueHolder&amp;lt;K,V&amp;gt;&lt;/code&gt; looks like the following.

&lt;script class="brush: java" type="syntaxhighlighter"&gt;
&lt;![CDATA[
/*
 * Copyright 2011 John Yeary &lt;jyeary@bluelotussoftware.com&gt;.
 * Copyright 2011 Bluelotus Software, LLC.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.bluelotussoftware.example;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

/**
 *
 * @author John Yeary &lt;jyeary@bluelotussoftware.com&gt;
 * @version 1.0
 */
public abstract class MapValueHolder&lt;K, V&gt; {

    protected Map&lt;K, V&gt; map = new HashMap&lt;K, V&gt;();

    public MapValueHolder() {
    }

    public Map&lt;K, V&gt; getMap() {
        return Collections.unmodifiableMap(map);
    }

    public void setMap(Map&lt;K, V&gt; map) {
        this.map = new HashMap&lt;K, V&gt;(map);
    }
}
]]&gt;
&lt;/script&gt;

Here is the implementation.

&lt;script class="brush: java" type="syntaxhighlighter"&gt;
&lt;![CDATA[
/*
 * Copyright 2011 John Yeary &lt;jyeary@bluelotussoftware.com&gt;.
 * Copyright 2011 Bluelotus Software, LLC.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.bluelotussoftware.example;

/**
 *
 * @author John Yeary &lt;jyeary@bluelotussoftware.com&gt;
 * @version 1.0
 */
public class MapValueHolderImpl&lt;K, V&gt; extends MapValueHolder&lt;K, V&gt; {
}
]]&gt;
&lt;/script&gt;

&lt;br /&gt;
As a general rule, you should use the key to fetch the value. Even if you expect that the values are the same. Since the instance variable is protected it can be modified in a sub-class, or any class in the same package. Since we code to interfaces, or abstractions (super classes). We can not be sure that the implementation class we are provided does what we expect. In this case, it does what we expect.

&lt;br /&gt;
&lt;pre&gt;MapValueHolder Key --&amp;gt; A
MapValueHolder Key --&amp;gt; B
MapValueHolder Key --&amp;gt; C
A --&amp;gt; A
B --&amp;gt; B
C --&amp;gt; C
&lt;/pre&gt;
&lt;pre&gt;
&lt;/pre&gt;
Here we continue using another implementation.
&lt;script class="brush: java" type="syntaxhighlighter"&gt;
&lt;![CDATA[
...
        me = new KeyValueHolder&lt;String, String&gt;();
        me.setMap(mx);


        for (String key : me.getMap().keySet()) {
            System.out.println("MapValueHolder Key --&gt; " + key);
        }

        for (String key : me.getMap().keySet()) {
            System.out.println(key + " --&gt; " + me.getMap().get(key));
        }
...
]]&gt;
&lt;/script&gt;

This time the result looks different.

&lt;br /&gt;
&lt;pre&gt;MapValueHolder Key --&amp;gt; A
MapValueHolder Key --&amp;gt; B
MapValueHolder Key --&amp;gt; C
A --&amp;gt; null
B --&amp;gt; null
C --&amp;gt; null
&lt;/pre&gt;
&lt;pre&gt;
&lt;/pre&gt;
This is because our &lt;code&gt;MapValueHolder&amp;lt;K,V&amp;gt;&lt;/code&gt; is different.
&lt;script class="brush: java" type="syntaxhighlighter"&gt;
&lt;![CDATA[
/*
 * Copyright 2011 John Yeary &lt;jyeary@bluelotussoftware.com&gt;.
 * Copyright 2011 Bluelotus Software, LLC.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.bluelotussoftware.example;

import java.util.HashMap;
import java.util.Map;

/**
 *
 * @author John Yeary &lt;jyeary@bluelotussoftware.com&gt;
 * @version 1.0
 */
public class KeyValueHolder&lt;K, V&gt; extends MapValueHolder&lt;K, V&gt; {

    public KeyValueHolder() {
    }

    @Override
    public void setMap(Map&lt;K, V&gt; map) {
        Map&lt;K, V&gt; mx = new HashMap&lt;K, V&gt;(map);
        for (K k : map.keySet()) {
            mx.put(k, null);
        }
        this.map = mx;
    }
}
]]&gt;
&lt;/script&gt;

Admittedly, the implementation above is a bit contrived. We really are getting is a &lt;code&gt;Set&amp;lt;K&amp;gt;&lt;/code&gt;. In the next example, we get another result.
&lt;script class="brush: java" type="syntaxhighlighter"&gt;
&lt;![CDATA[
...
        me = new SingletonMapValueHolder&lt;String, String&gt;();
        me.setMap(mx);

        for (String key : me.getMap().keySet()) {
            System.out.println("MapValueHolder Key --&gt; " + key);
        }
...
]]&gt;
&lt;/script&gt;

The result is considerably different.
&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;MapValueHolder Key --&amp;gt; A
A --&amp;gt; A
&lt;/pre&gt;
&lt;br /&gt;
Here is the implementation.
&lt;script class="brush: java" type="syntaxhighlighter"&gt;
&lt;![CDATA[
/*
 * Copyright 2011 John Yeary &lt;jyeary@bluelotussoftware.com&gt;.
 * Copyright 2011 Bluelotus Software, LLC.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.bluelotussoftware.example;

import java.util.Collections;
import java.util.Map;

/**
 *
 * @author John Yeary &lt;jyeary@bluelotussoftware.com&gt;
 * @version 1.0
 */
public class SingletonMapValueHolder&lt;K, V&gt; extends MapValueHolder&lt;K, V&gt; {

    public SingletonMapValueHolder() {
    }

    @Override
    public void setMap(Map&lt;K, V&gt; map) {
        this.map = Collections.singletonMap(
                map.entrySet().iterator().next().getKey(),
                map.entrySet().iterator().next().getValue());
    }
}
]]&gt;
&lt;/script&gt;
Again, this is a contrived result where we are just returning the first key and value in a &lt;code&gt;Map&amp;lt;K,V&amp;gt;&lt;/code&gt;.

Here is another example which demonstrates unexpected results.
&lt;script class="brush: java" type="syntaxhighlighter"&gt;
&lt;![CDATA[
     System.out.println(new Mod().MAP + " --&gt; " + me.map.toString());
]]&gt;
&lt;/script&gt;

This results in this very strange result.
&lt;br /&gt;
&lt;pre&gt;
&lt;/pre&gt;
&lt;pre&gt;Map --&amp;gt; {}
&lt;/pre&gt;
&lt;br /&gt;
Here I use reflection to modify the expected result.
&lt;script class="brush: java" type="syntaxhighlighter"&gt;
&lt;![CDATA[
/*
 * Copyright 2011 John Yeary &lt;jyeary@bluelotussoftware.com&gt;.
 * Copyright 2011 Bluelotus Software, LLC.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.bluelotussoftware.example;

import java.lang.reflect.Field;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author John Yeary &lt;jyeary@bluelotussoftware.com&gt;
 * @version 1.0
 */
public final class Mod {

    public static final String MAP = "Map";

    static {
        try {
            Field[] fx = App.class.newInstance().getClass().getDeclaredFields();
            Field f = fx[0];
            f.setAccessible(true);
            MapValueHolder&lt;String, String&gt; mvh = new MapValueHolderImpl&lt;String, String&gt;();
            f.set(null, mvh);
        } catch (Throwable ex) {
            Logger.getLogger(Mod.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
]]&gt;
&lt;/script&gt;

If you have followed me to this point, you will have learned a little bit about the Java Type system, reflection, abstraction, and Collections. Yet, you may be asking what is the tip?

Here are some rules:
&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;Use the keys to fetch values.&lt;/li&gt;
&lt;li&gt;Check for &lt;code&gt;null&lt;/code&gt; values. In my examples, I did not check for &lt;code&gt;null&lt;/code&gt; values.&lt;/li&gt;
&lt;li&gt;Use the correct Java Collection.&lt;/li&gt;
&lt;/ol&gt;
The Java Collection Framework covers most common cases. Take the time to read about them. The code above was based on a couple of issues I discovered: (1) Using keys for values, and (2) not using the correct collection. In this case, they should have used a &lt;code&gt;List&amp;lt;V&amp;gt;&lt;/code&gt;. If they wanted to use an ordered &lt;code&gt;Map&amp;lt;K,V&amp;gt;&lt;/code&gt;, they should have used a &lt;code&gt;LinkedHashmap&amp;lt;K,V&amp;gt;&lt;/code&gt;.&amp;nbsp;
&lt;br /&gt;
&lt;br /&gt;
The code for the examples are here: &lt;a href="http://commondatastorage.googleapis.com/bluelotussoftware/code/bad-mapping-implementation.zip"&gt;bad-mapping.implementation.zip&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
The code was developed using &lt;a href="http://www.netbeans.org/"&gt;NetBeans 7.1 RC1&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/36773632-8167248413950733396?l=javaevangelist.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/u5dTqwQdK8YPASSK2fmYAgUfWPU/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/u5dTqwQdK8YPASSK2fmYAgUfWPU/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/u5dTqwQdK8YPASSK2fmYAgUfWPU/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/u5dTqwQdK8YPASSK2fmYAgUfWPU/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/JavaEvangelistJohnYearysBlog/~4/iW2O9Ca0x1c" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/JavaEvangelistJohnYearysBlog/~3/iW2O9Ca0x1c/coding-tip-of-day-using-map-collections.html</link><author>noreply@blogger.com (John Yeary)</author><thr:total>0</thr:total><feedburner:origLink>http://javaevangelist.blogspot.com/2011/12/coding-tip-of-day-using-map-collections.html</feedburner:origLink></item></channel></rss>

