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

<channel>
	<title>Miles to go ...</title>
	<atom:link href="/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.arungupta.me</link>
	<description>Arun Gupta is a technology enthusiast, a passionate runner, and a community guy who works for Sun Microsystems. And this is his blog!</description>
	<lastBuildDate>Sun, 30 Aug 2009 18:00:30 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>TOTD #99: Creating a Java EE 6 application using MySQL, JPA 2.0 and Servlet 3.0 with GlassFish Tools Bundle for Eclipse</title>
		<link>http://blog.arungupta.me/2009/08/totd-99-creating-a-java-ee-6-application-using-mysql-jpa-2-0-and-servlet-3-0-with-glassfish-tools-bundle-for-eclipse/</link>
		<comments>http://blog.arungupta.me/2009/08/totd-99-creating-a-java-ee-6-application-using-mysql-jpa-2-0-and-servlet-3-0-with-glassfish-tools-bundle-for-eclipse/#comments</comments>
		<pubDate>Sun, 30 Aug 2009 18:00:30 +0000</pubDate>
		<dc:creator>arungupta</dc:creator>
				<category><![CDATA[eclipse]]></category>
		<category><![CDATA[general]]></category>
		<category><![CDATA[javaee]]></category>

		<guid isPermaLink="false">http://blog.arungupta.me/2009/08/totd-99-creating-a-java-ee-6-application-using-mysql-jpa-2-0-and-servlet-3-0-with-glassfish-tools-bundle-for-eclipse/</guid>
		<description><![CDATA[TOTD #97 showed how to install GlassFish Tools Bundle for Eclipse 1.1. Basically there are two options &#8211; either install Eclipse 3.4.2 with WTP and pre-bundled/configured with GlassFish v2/v3, MySQL JDBC driver and other features. Or if you are using Eclipse 3.5, then you can install the plug-in separately and get most of the functionality.
TOTD [...]


Related posts:<ol><li><a href='/2009/08/totd-98-create-a-metro-jax-ws-web-service-using-glassfish-tools-bundle-for-eclipse/' rel='bookmark' title='Permanent Link: TOTD #98: Create a Metro JAX-WS Web service using GlassFish Tools Bundle for Eclipse'>TOTD #98: Create a Metro JAX-WS Web service using GlassFish Tools Bundle for Eclipse</a></li><li><a href='/2009/04/lotd-20-how-to-create-a-jpa-application-using-glassfish-tools-bundle-for-eclipse/' rel='bookmark' title='Permanent Link: LOTD #20: How to create a JPA application using GlassFish Tools Bundle for Eclipse ?'>LOTD #20: How to create a JPA application using GlassFish Tools Bundle for Eclipse ?</a></li><li><a href='/2009/08/totd-94-a-simple-java-server-faces-2-0-jpa-2-0-application-getting-started-with-java-ee-6-using-netbeans-6-8-m1-glassfish-v3/' rel='bookmark' title='Permanent Link: TOTD #94: A simple Java Server Faces 2.0 + JPA 2.0 application &#8211; Getting Started with Java EE 6 using NetBeans 6.8 M1 &#038; GlassFish v3'>TOTD #94: A simple Java Server Faces 2.0 + JPA 2.0 application &#8211; Getting Started with Java EE 6 using NetBeans 6.8 M1 &#038; GlassFish v3</a></li></ol>]]></description>
			<content:encoded><![CDATA[<p><a href="/2009/08/totd-97-glassfish-plugin-with-eclipse-3-5/">TOTD #97</a> showed how to install GlassFish Tools Bundle for Eclipse 1.1. Basically there are two options &#8211; either install Eclipse 3.4.2 with WTP and pre-bundled/configured with GlassFish v2/v3, MySQL JDBC driver and other features. Or if you are using Eclipse 3.5, then you can install the plug-in separately and get most of the functionality.</p>
<p><a href="/2009/08/totd-98-create-a-metro-jax-ws-web-service-using-glassfish-tools-bundle-for-eclipse/">TOTD #98</a> showed how to create a simple <a href="http://metro.dev.java.net">Metro</a>/<a href="http://jax-ws.dev.java.net">JAX-WS</a> compliant Web service using that bundle and deploy on <a href="http://glassfish.org">GlassFish</a>. </p>
<p>This <strong>T</strong>ip <strong>O</strong>f <strong>T</strong>he <strong>D</strong>ay (TOTD) shows how to create a simple Java EE 6 application that reads data from a MySQL database using JPA 2.0 and Servlet 3.0 and display the results. A more formal support of Java EE 6/Servlet 3.0 is coming but in the meanwhile the approach mentioned below will work.</p>
<p>Lets get started!</p>
<ol>
<li>
Configure database connection &#8211; The key point to notice here is that the <a href="http://www.mysql.com/products/connector/">MySQL Connector/J driver</a> is already built into the tool so there is no need to configure it explicitly.</p>
<ol>
<li>From &quot;Window&quot;, &quot;Show Perspective&quot;, change to the database perspective as shown below:
<p><img height="431" border="1" style="margin: 5px" width="360" alt="" src="/wp-content/uploads/2009/08/gftbe11-hellojpa-choose-db-perspective1.png" /></li>
<li>In the &quot;Data Source Explorer&quot;, right-click and click on &quot;Database Connections&quot; and select &quot;New &#8230;&quot;:
<p><img height="204" border="1" style="margin: 5px" width="302" alt="" src="/wp-content/uploads/2009/08/gftbe11-hellojpa-new-db-connection1.png" /></li>
<li>Search for &quot;mysql&quot; and type the database name as &quot;sakila&quot;:
<p><img height="534" border="1" style="margin: 5px" width="523" alt="" src="/wp-content/uploads/2009/08/gftbe11-hellojpa-search-mysql1.png" /></p>
<p>This blog uses <a href="http://forge.mysql.com/wiki/SakilaSampleDB">MySQL sample database sakila</a>. So please <a href="http://downloads.mysql.com/docs/sakila-db.zip">download</a> and <a href="http://dev.mysql.com/doc/sakila/en/sakila.html#sakila-installation">install</a> the sample database before proceeding further.</li>
<li>Click on &quot;Next &gt;&quot; and specify the database configuration:
<p><img height="554" border="1" style="margin: 5px" width="522" alt="" src="/wp-content/uploads/2009/08/gftbe11-hellojpa-sakila-configuration1.png" /></p>
<p>Notice the &quot;Drivers&quot; indicate that the JDBC driver is pre-bundled so there is no extra configuration required. If you are using a stand-alone Eclipse bunde and installing the plugin separately, then you need to configure the MySQL JDBC driver explictily.</p>
<p>The URL indicates the application is connecting to the sakila database. Click on &quot;Test Connection&quot; to test connection with the database and see the output as:</p>
<p><img height="259" border="1" style="margin: 5px" width="520" alt="" src="/wp-content/uploads/2009/08/gftbe11-hellojpa-sakila-test-connection-output1.png" /></p>
<p>and click on &quot;Finish&quot; to complete. The expanded database in the explorer looks like:</p>
<p><img height="707" border="1" style="margin: 5px" width="330" alt="" src="/wp-content/uploads/2009/08/gftbe11-hellojpa-sakila-explorer-view1.png" /></p>
<p>The expanded view shows all the tables in the database.</li>
</ol>
</li>
<li>
Create the Web project &amp; configure JPA</p>
<ol>
<li>Switch to JavaEE perspective by clicking &quot;Window&quot;, &quot;Choose Perspective&quot;, &quot;Other &#8230;&quot; and choosing &quot;Java EE&quot;.</li>
<li>Create a new dynamic web project with the following settings:
<p><img height="549" border="1" style="margin: 5px" width="584" alt="" src="/wp-content/uploads/2009/08/gftbe11-hellojpa-project-creation1.png" /></p>
<p>Only the project name needs to be specified and everything else is default. Notice the target runtime indicates that this is a Java EE 6 application. Click on &quot;Finish&quot;.</li>
<li>Right-click on the project, search for &quot;facets&quot; and enable &quot;Java Persistence&quot; as shown below:
<p><img height="498" border="1" style="margin: 5px" width="646" alt="" src="/wp-content/uploads/2009/08/gftbe11-hellojpa-persistence-facet1.png" /></li>
<li>Click on &quot;Further configuration available &#8230;&quot; and modify the facet as shown below:
<p><img height="541" border="1" style="margin: 5px" width="518" alt="" src="/wp-content/uploads/2009/08/gftbe11-hellojpa-jpa-configuration1.png" /></p>
<p>Make sure to disable &quot;orm.xml&quot; since we are generating a standard Java EE 6 web application. Choose &quot;sakila&quot; as the database. Click on &quot;OK&quot; and again on &quot;OK&quot; to complete the dialog.</li>
</ol>
</li>
<li>
Generate the JPA entities</p>
<ol>
<li>Right-click on the project, select &quot;JPA Tools&quot;, &quot;Generate Entities&quot; as shown:
<p><img height="161" border="1" style="margin: 5px" width="456" alt="" src="/wp-content/uploads/2009/08/gftbe11-hellojpa-generate-entities1.png" /></li>
<li>Choose the schema &quot;sakila&quot;:
<p><img height="206" border="1" style="margin: 5px" width="354" alt="" src="/wp-content/uploads/2009/08/gftbe11-hellojpa-generate-entities-db-connection1.png" /></p>
<p>and click on &quot;Next &gt;&quot;. If no values are shown in the schema drop-down, then click on &quot;Reconnect &#8230;&quot;.</li>
<li>Specify a package name for the generated entities as &quot;model&quot; and select &quot;film&quot; and &quot;language&quot; table:
<p><img height="614" border="1" style="margin: 5px" width="629" alt="" src="/wp-content/uploads/2009/08/gftbe11-hellojpa-generate-entities-from-table1.png" /></p>
<p>and click on &quot;Finish&quot;. The &quot;film&quot; and &quot;language&quot; table are related so it would be nice if all the related tables can be identified and picked accordingly.</p>
<p>Anyway this generates &quot;model.Film&quot; and &quot;model.Language&quot; classes and &quot;persistence.xml&quot; as shown below:</p>
<p><img height="348" border="1" style="margin: 5px" width="242" alt="" src="/wp-content/uploads/2009/08/gftbe11-hellojpa-entities-generated1.png" /></p>
<p>Also notice that &quot;web.xml&quot; and &quot;sun-web.xml&quot; have been explicitly removed since they are not required by a Java EE 6 application.</li>
<li>&quot;model.Film&quot; class needs to modified slightly because one of the columns is mapped to &quot;Object&quot; which is not a Serializable obect. So change the type of &quot;specialFeatures&quot; from Object to String and also change the corresponding getters/setters accordingly. The error message clearly conveyed during the initial deployment and so could be fixed. But it would be nice to generate the classes that will work out-of-the-box.</li>
</ol>
</li>
<li>
Create a Servlet client to retrieve/display data from the database</p>
<ol>
<li>Right-click on the project, select &quot;New&quot;, &quot;Class&quot; and specify the values as:
<p><img height="575" border="1" style="margin: 5px" width="524" alt="" src="/wp-content/uploads/2009/08/gftbe11-hellojpa-servlet-client1.png" /></p>
<p>and click on &quot;Finish&quot;. This class will be our Servlet client.</li>
<li>
Change the class such that it looks like:<br /> 
<pre>
@WebServlet(urlPatterns="/ServletClient")
public class ServletClient extends HttpServlet {
  @PersistenceUnit
  EntityManagerFactory factory;

  protected void doGet(HttpServletRequest req, HttpServletResponse resp)
         throws ServletException, IOException {
    ServletOutputStream out = resp.getOutputStream();
    List list = factory.createEntityManager().createQuery("select f from Film f where f.title like 'GL%';").getResultList();
    out.println("&lt;html&gt;&lt;table&gt;");
    for (Object film : list) {
      out.print("&lt;tr&gt;&lt;td&gt;" + ((Film)film).getTitle() + "&lt;/tr&gt;&lt;/td&gt;");
    }
    out.println("&lt;/table&gt;&lt;/html&gt;");
  }
}
</pre>
<p>and the imports as:<br /> 
<pre>
import java.io.IOException;
import java.util.List;

import javax.persistence.EntityManagerFactory;
import javax.persistence.PersistenceUnit;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import model.Film;
</pre>
<p>Basically, this is a Servlet 3.0 specification compliant Servlet that uses @WebServlet annotation. It uses @PersistenceUnit to inject the generated JPA Persistence Unit which is then used to query the database. The database query return all the movies whose title start with &quot;GL&quot; and the response is displayed in an HTML formatted table.            </li>
<li>Right-click on the project and select &quot;Run As&quot;, &quot;Run on Server&quot; and select <a href="http://download.java.net/glassfish/v3/promoted/">GlassFish v3 latest promoted build</a> (this blog used <a href="http://download.java.net/glassfish/v3/promoted/glassfish-v3-preview-b61.zip">build 61</a>) as:
<p><img height="515" border="1" style="margin: 5px" width="506" alt="" src="/wp-content/uploads/2009/08/gftbe11-hellojpa-run-on-server1.png" /></p>
<p> and click on &quot;Finish&quot;. The output at &quot;http://localhost:8080/HelloJPA/ServletClient&quot; looks like:</p>
<p><img height="186" border="1" style="margin: 5px" width="393" alt="" src="/wp-content/uploads/2009/08/gftbe11-hellojpa-output-final.png" /></li>
</ol>
</li>
</ol>
<p>Simple, easy and clean!</p>
<p>How are you using Eclipse and GlassFish &#8211; the consolidated bundle or standalone Eclipse + GlassFish plugin ?</p>
<p>Download <a href="http://download.java.net/glassfish/eclipse/">GlassFish Tools Bundle for Eclipse</a> now.</p>
<p><small>Technorati: <a href="http://technorati.com/tags/glassfish">glassfish</a> <a href="http://technorati.com/tags/eclipse">eclipse</a> <a href="http://technorati.com/tags/mysql">mysql</a> <a href="http://technorati.com/tags/jpa">jpa</a> <a href="http://technorati.com/tags/database">database</a></small></p></p>


<p>Related posts:<ol><li><a href='/2009/08/totd-98-create-a-metro-jax-ws-web-service-using-glassfish-tools-bundle-for-eclipse/' rel='bookmark' title='Permanent Link: TOTD #98: Create a Metro JAX-WS Web service using GlassFish Tools Bundle for Eclipse'>TOTD #98: Create a Metro JAX-WS Web service using GlassFish Tools Bundle for Eclipse</a></li><li><a href='/2009/04/lotd-20-how-to-create-a-jpa-application-using-glassfish-tools-bundle-for-eclipse/' rel='bookmark' title='Permanent Link: LOTD #20: How to create a JPA application using GlassFish Tools Bundle for Eclipse ?'>LOTD #20: How to create a JPA application using GlassFish Tools Bundle for Eclipse ?</a></li><li><a href='/2009/08/totd-94-a-simple-java-server-faces-2-0-jpa-2-0-application-getting-started-with-java-ee-6-using-netbeans-6-8-m1-glassfish-v3/' rel='bookmark' title='Permanent Link: TOTD #94: A simple Java Server Faces 2.0 + JPA 2.0 application &#8211; Getting Started with Java EE 6 using NetBeans 6.8 M1 &#038; GlassFish v3'>TOTD #94: A simple Java Server Faces 2.0 + JPA 2.0 application &#8211; Getting Started with Java EE 6 using NetBeans 6.8 M1 &#038; GlassFish v3</a></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.arungupta.me/2009/08/totd-99-creating-a-java-ee-6-application-using-mysql-jpa-2-0-and-servlet-3-0-with-glassfish-tools-bundle-for-eclipse/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>svn.dev.java.net is down!</title>
		<link>http://blog.arungupta.me/2009/08/svn-dev-java-net-is-down-2/</link>
		<comments>http://blog.arungupta.me/2009/08/svn-dev-java-net-is-down-2/#comments</comments>
		<pubDate>Sat, 29 Aug 2009 00:28:06 +0000</pubDate>
		<dc:creator>arungupta</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.arungupta.me/2009/08/svn-dev-java-net-is-down-2/</guid>
		<description><![CDATA[svn.dev.java.net is down &#8230; what&#8217;s new!
Here is how it looks like &#8230;

Do &#34;+1&#34; every time and any time in the comments you see java.net is not behaving for you and let&#8217;s see how quickly the comments fill up!
Technorati: java.net


Related posts:svn.dev.java.net is down!TOTD #95: EJB 3.1 + Java Server Faces 2.0 + JPA 2.0 web application [...]


Related posts:<ol><li><a href='/2009/08/svn-dev-java-net-is-down/' rel='bookmark' title='Permanent Link: svn.dev.java.net is down!'>svn.dev.java.net is down!</a></li><li><a href='/2009/08/totd-95-ejb-3-1-java-server-faces-2-0-jpa-2-0-web-application-getting-started-with-java-ee-6-using-netbeans-6-8-m1-glassfish-v3/' rel='bookmark' title='Permanent Link: TOTD #95: EJB 3.1 + Java Server Faces 2.0 + JPA 2.0 web application &#8211; Getting Started with Java EE 6 using NetBeans 6.8 M1 &#038; GlassFish v3'>TOTD #95: EJB 3.1 + Java Server Faces 2.0 + JPA 2.0 web application &#8211; Getting Started with Java EE 6 using NetBeans 6.8 M1 &#038; GlassFish v3</a></li><li><a href='/2008/01/developer-com-2008-awards-announced-netbeans-glassfish-and-java-se-6-score-well/' rel='bookmark' title='Permanent Link: Developer.com 2008 Awards Announced &#8211; NetBeans, GlassFish and Java SE 6 score well'>Developer.com 2008 Awards Announced &#8211; NetBeans, GlassFish and Java SE 6 score well</a></li></ol>]]></description>
			<content:encoded><![CDATA[<p>svn.dev.java.net is down &#8230; what&#8217;s new!</p>
<p>Here is how it looks like &#8230;</p>
<p><img height="302" border="1" style="margin: 5px" width="560" alt="" src="/wp-content/uploads/2009/08/svn.dev.java.net-down.png" /></p>
<p>Do &quot;+1&quot; every time and any time in the comments you see java.net is not behaving for you and let&#8217;s see how quickly the comments fill up!</p>
<p><small>Technorati: <a href="http://technorati.com/tags/java.net">java.net</a></small></p>


<p>Related posts:<ol><li><a href='/2009/08/svn-dev-java-net-is-down/' rel='bookmark' title='Permanent Link: svn.dev.java.net is down!'>svn.dev.java.net is down!</a></li><li><a href='/2009/08/totd-95-ejb-3-1-java-server-faces-2-0-jpa-2-0-web-application-getting-started-with-java-ee-6-using-netbeans-6-8-m1-glassfish-v3/' rel='bookmark' title='Permanent Link: TOTD #95: EJB 3.1 + Java Server Faces 2.0 + JPA 2.0 web application &#8211; Getting Started with Java EE 6 using NetBeans 6.8 M1 &#038; GlassFish v3'>TOTD #95: EJB 3.1 + Java Server Faces 2.0 + JPA 2.0 web application &#8211; Getting Started with Java EE 6 using NetBeans 6.8 M1 &#038; GlassFish v3</a></li><li><a href='/2008/01/developer-com-2008-awards-announced-netbeans-glassfish-and-java-se-6-score-well/' rel='bookmark' title='Permanent Link: Developer.com 2008 Awards Announced &#8211; NetBeans, GlassFish and Java SE 6 score well'>Developer.com 2008 Awards Announced &#8211; NetBeans, GlassFish and Java SE 6 score well</a></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.arungupta.me/2009/08/svn-dev-java-net-is-down-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>svn.dev.java.net is down!</title>
		<link>http://blog.arungupta.me/2009/08/svn-dev-java-net-is-down/</link>
		<comments>http://blog.arungupta.me/2009/08/svn-dev-java-net-is-down/#comments</comments>
		<pubDate>Sat, 29 Aug 2009 00:28:06 +0000</pubDate>
		<dc:creator>arungupta</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.arungupta.me/2009/08/svn-dev-java-net-is-down/</guid>
		<description><![CDATA[svn.dev.java.net is down &#8230; what&#8217;s new!
Here is how it looks like &#8230;

Do &#34;+1&#34; every time and any time in the comments you see java.net is not behaving for you and let&#8217;s see how quickly the comments fill up!
Technorati: java.net


Related posts:svn.dev.java.net is down!TOTD #95: EJB 3.1 + Java Server Faces 2.0 + JPA 2.0 web application [...]


Related posts:<ol><li><a href='/2009/08/svn-dev-java-net-is-down-2/' rel='bookmark' title='Permanent Link: svn.dev.java.net is down!'>svn.dev.java.net is down!</a></li><li><a href='/2009/08/totd-95-ejb-3-1-java-server-faces-2-0-jpa-2-0-web-application-getting-started-with-java-ee-6-using-netbeans-6-8-m1-glassfish-v3/' rel='bookmark' title='Permanent Link: TOTD #95: EJB 3.1 + Java Server Faces 2.0 + JPA 2.0 web application &#8211; Getting Started with Java EE 6 using NetBeans 6.8 M1 &#038; GlassFish v3'>TOTD #95: EJB 3.1 + Java Server Faces 2.0 + JPA 2.0 web application &#8211; Getting Started with Java EE 6 using NetBeans 6.8 M1 &#038; GlassFish v3</a></li><li><a href='/2008/01/developer-com-2008-awards-announced-netbeans-glassfish-and-java-se-6-score-well/' rel='bookmark' title='Permanent Link: Developer.com 2008 Awards Announced &#8211; NetBeans, GlassFish and Java SE 6 score well'>Developer.com 2008 Awards Announced &#8211; NetBeans, GlassFish and Java SE 6 score well</a></li></ol>]]></description>
			<content:encoded><![CDATA[<p>svn.dev.java.net is down &#8230; what&#8217;s new!</p>
<p>Here is how it looks like &#8230;</p>
<p><img height="302" border="1" style="margin: 5px" width="560" alt="" src="/wp-content/uploads/2009/08/svn.dev.java.net-down.png" /></p>
<p>Do &quot;+1&quot; every time and any time in the comments you see java.net is not behaving for you and let&#8217;s see how quickly the comments fill up!</p>
<p><small>Technorati: <a href="http://technorati.com/tags/java.net">java.net</a></small></p>


<p>Related posts:<ol><li><a href='/2009/08/svn-dev-java-net-is-down-2/' rel='bookmark' title='Permanent Link: svn.dev.java.net is down!'>svn.dev.java.net is down!</a></li><li><a href='/2009/08/totd-95-ejb-3-1-java-server-faces-2-0-jpa-2-0-web-application-getting-started-with-java-ee-6-using-netbeans-6-8-m1-glassfish-v3/' rel='bookmark' title='Permanent Link: TOTD #95: EJB 3.1 + Java Server Faces 2.0 + JPA 2.0 web application &#8211; Getting Started with Java EE 6 using NetBeans 6.8 M1 &#038; GlassFish v3'>TOTD #95: EJB 3.1 + Java Server Faces 2.0 + JPA 2.0 web application &#8211; Getting Started with Java EE 6 using NetBeans 6.8 M1 &#038; GlassFish v3</a></li><li><a href='/2008/01/developer-com-2008-awards-announced-netbeans-glassfish-and-java-se-6-score-well/' rel='bookmark' title='Permanent Link: Developer.com 2008 Awards Announced &#8211; NetBeans, GlassFish and Java SE 6 score well'>Developer.com 2008 Awards Announced &#8211; NetBeans, GlassFish and Java SE 6 score well</a></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.arungupta.me/2009/08/svn-dev-java-net-is-down/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>FREE GlassFish Webinar: &#8220;Java EE 6 Overview&#8221; &#8211; Aug 26, 2009, 10am PT</title>
		<link>http://blog.arungupta.me/2009/08/free-glassfish-webinar-java-ee-6-overview-aug-26-2009-10am-pt/</link>
		<comments>http://blog.arungupta.me/2009/08/free-glassfish-webinar-java-ee-6-overview-aug-26-2009-10am-pt/#comments</comments>
		<pubDate>Wed, 26 Aug 2009 06:00:45 +0000</pubDate>
		<dc:creator>arungupta</dc:creator>
				<category><![CDATA[glassfish]]></category>
		<category><![CDATA[javaee]]></category>
		<category><![CDATA[webinar]]></category>

		<guid isPermaLink="false">http://blog.arungupta.me/?p=5092</guid>
		<description><![CDATA[Java EE 6 is developed as JSR 316 under the Java Community Process. It breaks the &#8220;one size fits all&#8221; approach with Profiles and improves on the Java EE 5 developer productivity features. Several existing specifications are getting an extreme makeover such as Java Server Faces 2.0 and Servlet 3.0. GlassFish v3 is the Reference [...]


Related posts:<ol><li><a href='/2009/01/free-glassfish-webinar-for-students-at-osum/' rel='bookmark' title='Permanent Link: Free GlassFish Webinar for Students at OSUM'>Free GlassFish Webinar for Students at OSUM</a></li><li><a href='/2009/03/developing-glassfish-and-mysql-backed-applications-with-netbeans-and-jruby-on-rails-free-webinar-on-mar-26/' rel='bookmark' title='Permanent Link: Developing GlassFish- and MySQL-Backed Applications with Netbeans and JRuby-on-Rails &#8211; Free Webinar on Mar 26'>Developing GlassFish- and MySQL-Backed Applications with Netbeans and JRuby-on-Rails &#8211; Free Webinar on Mar 26</a></li><li><a href='/2009/01/developing-glassfish-and-mysql-backed-applications-with-netbeans-and-jruby-on-rails-free-webinar-on-jan-27/' rel='bookmark' title='Permanent Link: Developing GlassFish- and MySQL-Backed Applications with Netbeans and JRuby-on-Rails &#8211; Free Webinar on Jan 27'>Developing GlassFish- and MySQL-Backed Applications with Netbeans and JRuby-on-Rails &#8211; Free Webinar on Jan 27</a></li></ol>]]></description>
			<content:encoded><![CDATA[<p>Java EE 6 is developed as <a href="http://jcp.org/en/jsr/detail?id=316">JSR 316</a> under the Java Community Process. It breaks the &#8220;one size fits all&#8221; approach with Profiles and improves on the Java EE 5 developer productivity features. Several existing specifications are getting an extreme makeover such as Java Server Faces 2.0 and Servlet 3.0. GlassFish v3 is the Reference Implementation of Java EE 6.</p>
<p>So you&#8217;d like to get an overview of Java EE 6 and start developing with GlassFish v3. Please register for a <a href="https://dct.sun.com/dct/forms/reg_us_1808_880_0.jsp">free webinar</a> with coordinates:</p>
<p><b>Date</b>: Aug 26, 2009<br />
<b>Time</b>: 10am PT</p>
<p>Register <a href="https://dct.sun.com/dct/forms/reg_us_1808_880_0.jsp">here</a>.</p>
<p>Yep, it&#8217;s starting in a few hours so make sure to sign up and be ready with your questions. Several specification leads will be available to field your questions.</p>
<p><small>Technorati: <a href="http://technorati.com/tags/glassfish">glassfish</a> <a href="http://technorati.com/tags/javaee">javaee</a> <a href="http://technorati.com/tags/webinar">webinar</a></small></p>


<p>Related posts:<ol><li><a href='/2009/01/free-glassfish-webinar-for-students-at-osum/' rel='bookmark' title='Permanent Link: Free GlassFish Webinar for Students at OSUM'>Free GlassFish Webinar for Students at OSUM</a></li><li><a href='/2009/03/developing-glassfish-and-mysql-backed-applications-with-netbeans-and-jruby-on-rails-free-webinar-on-mar-26/' rel='bookmark' title='Permanent Link: Developing GlassFish- and MySQL-Backed Applications with Netbeans and JRuby-on-Rails &#8211; Free Webinar on Mar 26'>Developing GlassFish- and MySQL-Backed Applications with Netbeans and JRuby-on-Rails &#8211; Free Webinar on Mar 26</a></li><li><a href='/2009/01/developing-glassfish-and-mysql-backed-applications-with-netbeans-and-jruby-on-rails-free-webinar-on-jan-27/' rel='bookmark' title='Permanent Link: Developing GlassFish- and MySQL-Backed Applications with Netbeans and JRuby-on-Rails &#8211; Free Webinar on Jan 27'>Developing GlassFish- and MySQL-Backed Applications with Netbeans and JRuby-on-Rails &#8211; Free Webinar on Jan 27</a></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.arungupta.me/2009/08/free-glassfish-webinar-java-ee-6-overview-aug-26-2009-10am-pt/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>TOTD #98: Create a Metro JAX-WS Web service using GlassFish Tools Bundle for Eclipse</title>
		<link>http://blog.arungupta.me/2009/08/totd-98-create-a-metro-jax-ws-web-service-using-glassfish-tools-bundle-for-eclipse/</link>
		<comments>http://blog.arungupta.me/2009/08/totd-98-create-a-metro-jax-ws-web-service-using-glassfish-tools-bundle-for-eclipse/#comments</comments>
		<pubDate>Tue, 25 Aug 2009 06:05:30 +0000</pubDate>
		<dc:creator>arungupta</dc:creator>
				<category><![CDATA[eclipse]]></category>
		<category><![CDATA[totd]]></category>
		<category><![CDATA[webservices]]></category>
		<category><![CDATA[galileo]]></category>
		<category><![CDATA[glassfish]]></category>
		<category><![CDATA[jax-ws]]></category>
		<category><![CDATA[metro]]></category>

		<guid isPermaLink="false">http://blog.arungupta.me/?p=5014</guid>
		<description><![CDATA[Now that you&#8217;ve installed GlassFish Tools Bundle for Eclipse 1.1, lets use this bundle to create a simple Metro/JAX-WS compliant Web service and deploy on GlassFish. These steps will work with either Eclipse 3.4.2 or 3.5 with WTP Java EE support.

Lets create a simple &#8220;Dynamic Web Project&#8221; as shown below:


Name the project &#8220;HelloMetro&#8221; and take [...]


Related posts:<ol><li><a href='/2007/01/creating-and-invoking-a-web-service-using-glassfish-in-netbeans-intellij-and-eclipse-part-1/' rel='bookmark' title='Permanent Link: Creating and Invoking a Web service using GlassFish in NetBeans, IntelliJ, and Eclipse &#8211; Part 1'>Creating and Invoking a Web service using GlassFish in NetBeans, IntelliJ, and Eclipse &#8211; Part 1</a></li><li><a href='/2007/11/totd-19-how-to-add-metro-quality-of-service-to-contract-first-endpoint/' rel='bookmark' title='Permanent Link: TOTD #19: How to Add Metro Quality-of-Service to Contract-First Endpoint ?'>TOTD #19: How to Add Metro Quality-of-Service to Contract-First Endpoint ?</a></li><li><a href='/2007/02/creating-and-invoking-a-web-service-using-glassfish-in-netbeans-intellij-and-eclipse-part-3/' rel='bookmark' title='Permanent Link: Creating and Invoking a Web service using GlassFish in NetBeans, IntelliJ, and Eclipse &#8211; Part 3'>Creating and Invoking a Web service using GlassFish in NetBeans, IntelliJ, and Eclipse &#8211; Part 3</a></li></ol>]]></description>
			<content:encoded><![CDATA[<p>Now that you&#8217;ve installed <a href="/2009/08/totd-97-glassfish-plugin-with-eclipse-3-5/">GlassFish Tools Bundle for Eclipse 1.1</a>, lets use this bundle to create a simple <a href="http://metro.dev.java.net">Metro</a>/<a href="http://jax-ws.dev.java.net">JAX-WS</a> compliant Web service and deploy on <a  href="http://glassfish.org">GlassFish</a>. These steps will work with either Eclipse 3.4.2 or 3.5 with WTP Java EE support.</p>
<ol>
<li>Lets create a simple &#8220;Dynamic Web Project&#8221; as shown below:
<p><img style="border: 1px solid ; width: 556px; height: 368px;" alt="" src="/wp-content/uploads/2009/08/gftbe11-hellometro-create-dynamic-web-project.png">
</li>
<li>Name the project &#8220;HelloMetro&#8221; and take all other defaults:
<p><img style="border: 1px solid ; width: 591px; height: 553px;" alt="" src="/wp-content/uploads/2009/08/gftbe11-hellometro-project-name.png"></p>
<p>Click on &#8220;Finish&#8221; to complete the project creation.</li>
<li>Metro allows to create a Web service from a POJO class. So let&#8217;s add a POJO to the project by right-clicking on the project and selecting &#8220;New&#8221;, &#8220;Class&#8221; as shown below:
<p><img style="border: 1px solid ; width: 572px; height: 294px;" alt="" src="/wp-content/uploads/2009/08/gftbe11-hellometro-add-new-class.png">&nbsp;&nbsp;</p>
<p>Specify the package name as &#8220;server&#8221;, class name as &#8220;HelloService&#8221; and click on &#8220;Finish&#8221;.</li>
<li>Add a simple method to the newly generated class as:
<p><code>
<pre>
public String sayHello(String name) {
      return "Hello " + name + "!!";
}
</pre>
<p></code>
</li>
<li>Expand the project, go to &#8220;HelloService.java&#8221; in &#8220;server&#8221; package, right-click, select &#8220;Web Services&#8221;, &#8220;Create Web service&#8221;.</li>
<li>Click on &#8220;Web service runtime: Apache Axis&#8221; and select &#8220;Metro (JAX-WS) Runtime&#8221; as the Web service runtime as shown below:
<p><img style="border: 1px solid ; width: 603px; height: 546px;" alt="" src="/wp-content/uploads/2009/08/gftbe11-hellometro-metro-runtime.png"></li>
<li>Move the slider on the left to top. This will enable testing of the deployed Web service. The completed configuration looks like:
<p><img style="border: 1px solid ; width: 559px; height: 318px;" alt="" src="/wp-content/uploads/2009/08/gftbe11-hellometro-runtime-config.png"></p>
<p>and click on &#8220;Next &gt;&#8221;.</li>
<li>Select the checkbox &#8220;Copy Metro library jars to the project&#8221; to resolve the references correctly as shown below:
<p><img style="border: 1px solid ; width: 394px; height: 160px;" alt="" src="/wp-content/uploads/2009/08/gftbe11-hellometro-metro-jars.png"></p>
<p>and click on &#8220;Next &gt;&#8221;. This bundles the application and deploys to GlassFish and provides an option to test the deployed Web service as shown below:</p>
<p><img style="border: 1px solid ; width: 696px; height: 151px;" alt="" src="/wp-content/uploads/2009/08/gftbe11-hellometro-launch-button.png"></p>
<p>Clicking on the &#8220;Launch&#8221; button shows the following output in the browser:</p>
<p><a href="/wp-content/uploads/2009/08/gftbe11-hellometro-browser-output-default.png"><img style="border: 2px solid ; width: 700px; height: 415px;" alt="" src="/wp-content/uploads/2009/08/gftbe11-hellometro-browser-output-default.png"></a></p>
<p>The WSDL is hosted at &#8220;http://localhost:8083/HelloMetro/HelloServiceService?wsdl&#8221;.</li>
<li>Click on &#8220;sayHello&#8221; method, click on &#8220;Add&#8221; and enter the value as &#8220;Duke&#8221; as shown below:
<p><img style="border: 1px solid ; width: 424px; height: 371px;" alt="" src="/wp-content/uploads/2009/08/gftbe11-hellometro-add-parameter-value.png"></p>
<p>Click on &#8220;Go&#8221; and the response is shown as:</p>
<p><img style="border: 1px solid ; width: 275px; height: 329px;" alt="" src="/wp-content/uploads/2009/08/gftbe11-hellometro-browser-response.png"></p>
<p>Clicking on &#8220;Source&#8221; in the response window shows the SOAP request/response messages as shown below:</p>
<p><img style="border: 1px solid ; width: 411px; height: 607px;" alt="" src="/wp-content/uploads/2009/08/gftbe11-hellometro-browser-response-soap.png"></li>
<li>Alternatively, you can click on &#8220;Finish&#8221; to complete the dialog. Then click on &#8220;Run&#8221; menu item, &#8220;Launch the Web Services Explorer&#8221; to see a screen as:
<p><img style="border: 1px solid ; width: 439px; height: 290px;" alt="" src="/wp-content/uploads/2009/08/gftbe11-hellometro-launch-wse.png"></p>
<p>Enter the URL of the WSDL in &#8220;WSDL URL&#8221; box as &#8220;http://localhost:8083/HelloMetro/HelloServiceService?wsdl&#8221; and click on &#8220;Go&#8221;. Now you are seeing the similar screen to test the Web service within the integrated browser as shown below:</p>
<p><img style="border: 1px solid ; width: 572px; height: 376px;" alt="" src="/wp-content/uploads/2009/08/gftbe11-hellometro-launch-wse-within-ide.png">
</li>
</ol>
<p>A future blog will cover how to write a database-enabled application using the bundled <a href="http://www.eclipse.org/webtools/dali/main.php">Dali JPA Tools</a> and MySQL pre-registered JDBC driver.</p>
<p>Please send your questions and comments to <a href="mailto:users@glassfishplugins.dev.java.net">users@glassfishplugins.dev.java.net</a>.<br />Please leave suggestions on other TOTD that you&#8217;d like to see. A complete archive of all the tips is available <a href="/?tag=totd">here</a>.</p>
<p><small>Technorati: <a href="http://technorati.com/tags/totd">totd</a> <a href="http://technorati.com/tags/glassfish">glassfish</a> <a href="http://technorati.com/tags/eclipse">eclipse</a> <a href="http://technorati.com/tags/galileo">galileo</a> <a href="http://technorati.com/tags/webservices">webservices</a> <a href="http://technorati.com/tags/metro">metro</a> </small><a href="http://technorati.com/tags/jax-ws"><small>jax-ws</a></small></p>


<p>Related posts:<ol><li><a href='/2007/01/creating-and-invoking-a-web-service-using-glassfish-in-netbeans-intellij-and-eclipse-part-1/' rel='bookmark' title='Permanent Link: Creating and Invoking a Web service using GlassFish in NetBeans, IntelliJ, and Eclipse &#8211; Part 1'>Creating and Invoking a Web service using GlassFish in NetBeans, IntelliJ, and Eclipse &#8211; Part 1</a></li><li><a href='/2007/11/totd-19-how-to-add-metro-quality-of-service-to-contract-first-endpoint/' rel='bookmark' title='Permanent Link: TOTD #19: How to Add Metro Quality-of-Service to Contract-First Endpoint ?'>TOTD #19: How to Add Metro Quality-of-Service to Contract-First Endpoint ?</a></li><li><a href='/2007/02/creating-and-invoking-a-web-service-using-glassfish-in-netbeans-intellij-and-eclipse-part-3/' rel='bookmark' title='Permanent Link: Creating and Invoking a Web service using GlassFish in NetBeans, IntelliJ, and Eclipse &#8211; Part 3'>Creating and Invoking a Web service using GlassFish in NetBeans, IntelliJ, and Eclipse &#8211; Part 3</a></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.arungupta.me/2009/08/totd-98-create-a-metro-jax-ws-web-service-using-glassfish-tools-bundle-for-eclipse/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>TOTD #97: GlassFish Plugin with Eclipse 3.5</title>
		<link>http://blog.arungupta.me/2009/08/totd-97-glassfish-plugin-with-eclipse-3-5/</link>
		<comments>http://blog.arungupta.me/2009/08/totd-97-glassfish-plugin-with-eclipse-3-5/#comments</comments>
		<pubDate>Fri, 21 Aug 2009 20:20:07 +0000</pubDate>
		<dc:creator>arungupta</dc:creator>
				<category><![CDATA[eclipse]]></category>
		<category><![CDATA[totd]]></category>
		<category><![CDATA[galileo]]></category>
		<category><![CDATA[glassfish]]></category>

		<guid isPermaLink="false">http://blog.arungupta.me/?p=3363</guid>
		<description><![CDATA[A new version of GlassFish Tools Bundle for Eclipse (ver 1.1) was recently released. The build contains

Eclipse 3.4.2 IDE with WTP Java EE support
GlassFish v2.1 pre-registered and configured
GlassFish v3 Prelude pre-registered and configured
JavaDB sample database pre-registered and configured
GlassFish Plugin (1.0.29)
MySQL JDBC driver registered to the IDE
Maven m2 plugins
JAX-WS Metro plugin
GlassFish documentation
And optionally, a JDK 1.6.

The [...]


Related posts:<ol><li><a href='/2009/01/totd-66-glassfish-eclipse-plugin-1-0-16-install-v3-prelude-from-the-ide/' rel='bookmark' title='Permanent Link: TOTD #66: GlassFish Eclipse Plugin 1.0.16 &#8211; Install v3 Prelude from the IDE'>TOTD #66: GlassFish Eclipse Plugin 1.0.16 &#8211; Install v3 Prelude from the IDE</a></li><li><a href='/2009/08/totd-98-create-a-metro-jax-ws-web-service-using-glassfish-tools-bundle-for-eclipse/' rel='bookmark' title='Permanent Link: TOTD #98: Create a Metro JAX-WS Web service using GlassFish Tools Bundle for Eclipse'>TOTD #98: Create a Metro JAX-WS Web service using GlassFish Tools Bundle for Eclipse</a></li><li><a href='/2009/05/totd-83-eclipse-tools-bundle-for-glassfish-1-0-now-available/' rel='bookmark' title='Permanent Link: TOTD #83: Eclipse Tools Bundle for GlassFish 1.0 &#8211; Now Available!'>TOTD #83: Eclipse Tools Bundle for GlassFish 1.0 &#8211; Now Available!</a></li></ol>]]></description>
			<content:encoded><![CDATA[<p>A new version of GlassFish Tools Bundle for Eclipse (ver 1.1) was <a href="https://glassfishplugins.dev.java.net/servlets/ReadMsg?list=users&amp;msgNo=277">recently released</a>. The build contains</p>
<ul>
<li>Eclipse 3.4.2 IDE with WTP Java EE support</li>
<li>GlassFish v2.1 pre-registered and configured</li>
<li>GlassFish v3 Prelude pre-registered and configured</li>
<li>JavaDB sample database pre-registered and configured</li>
<li>GlassFish Plugin (1.0.29)</li>
<li>MySQL JDBC driver registered to the IDE</li>
<li>Maven m2 plugins</li>
<li>JAX-WS Metro plugin</li>
<li>GlassFish documentation</li>
<li>And optionally, a JDK 1.6.</li>
</ul>
<p>The functionality is also available in GlassFish Plugin that can be  installed on Eclipse 3.5. However because of the <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=280365">Eclipse  bug #280365</a>, the plugin cannot be installed directly using Server Adapters. The alternative is to install explicitly using the  Update Site. The instructions to do the same are given below:</p>
<ol>
<li>In &#8220;Help&#8221;, &#8220;Install New Software&#8221;, click on &#8220;Available Software Sites&#8221;:<img style="border: 1px solid; width: 501px; height: 237px;" src="/wp-content/uploads/2009/08/eclipse-3.5-available-software-sites.png" alt="" /></li>
<li>Search for &#8220;ajax&#8221; to see the output as:<img style="border: 1px solid; width: 700px; height: 227px;" src="/wp-content/uploads/2009/08/eclipse-3.5-available-software-sites-ajax-disabled.png" alt="" /></li>
<li>Click on &#8220;Enabled&#8221; button to enable the site and see the change as below:<img style="border: 1px solid; width: 700px; height: 224px;" src="/wp-content/uploads/2009/08/eclipse-3.5-available-software-sites-ajax-enabled.png" alt="" />
<p>click on &#8220;OK&#8221;.</li>
<li>Expand the drop-down list box and chose the recently added &#8220;update site&#8221; as shown below:<img style="border: 1px solid; width: 678px; height: 201px;" src="/wp-content/uploads/2009/08/eclipse-3.5-available-software-sites-add.png" alt="" />
<p>and it shows all the software available from that site as:</p>
<p><img style="border: 1px solid; width: 563px; height: 461px;" src="/wp-content/uploads/2009/08/eclipse-3.5-update-site-glassfish.png" alt="" /></li>
<li>Take the defaults, click on &#8220;Next&#8221; and it shows the GlassFish plugin version number as shown below:<img style="border: 1px solid; width: 572px; height: 172px;" src="/wp-content/uploads/2009/08/eclipse-3.5-glassfish-plugin-1.0.31.png" alt="" /></li>
<li>Click on &#8220;Next&#8221;, accept the license by clicking on  &#8220;I accept &#8230;&#8221; and click on &#8220;Finish&#8221; to start the  installation.<img style="border: 1px solid; width: 560px; height: 371px;" src="/wp-content/uploads/2009/08/eclipse-3.5-glassfish-1.0.31-install.png" alt="" />
<p>The IDE restarts after the installation is complete.</li>
<li>Now a new server can be added using &#8220;Servers&#8221; tab and it shows GlassFish as an option as shown below:<img style="border: 1px solid; width: 521px; height: 349px;" src="/wp-content/uploads/2009/08/eclipse-3.5-glassfish-1.0.31-server.png" alt="" /></li>
</ol>
<p>The <a href="http://blogs.sun.com/arungupta/entry/screencast_28_simple_web_application">screencast  #28</a> shows how to create a simple web application using <a href="http://glassfish.org">GlassFish v3</a>. Future blogs will show how to leverage the new functionality of JAX-WS Web  services plugin and JPA Dali Tooling with GlassFish.</p>
<p>Please leave suggestions on other TOTD that  you&#8217;d like to see.  A complete archive of all the tips is available <a href="/?tag=totd">here</a>.</p>
<p><small>Technorati: <a href="http://technorati.com/tags/totd">totd </a><a href="http://technorati.com/tags/glassfish">glassfish</a> <a href="http://technorati.com/tags/eclipse">eclipse</a> <a href="http://technorati.com/tags/galileo">galileo</a></small></p>


<p>Related posts:<ol><li><a href='/2009/01/totd-66-glassfish-eclipse-plugin-1-0-16-install-v3-prelude-from-the-ide/' rel='bookmark' title='Permanent Link: TOTD #66: GlassFish Eclipse Plugin 1.0.16 &#8211; Install v3 Prelude from the IDE'>TOTD #66: GlassFish Eclipse Plugin 1.0.16 &#8211; Install v3 Prelude from the IDE</a></li><li><a href='/2009/08/totd-98-create-a-metro-jax-ws-web-service-using-glassfish-tools-bundle-for-eclipse/' rel='bookmark' title='Permanent Link: TOTD #98: Create a Metro JAX-WS Web service using GlassFish Tools Bundle for Eclipse'>TOTD #98: Create a Metro JAX-WS Web service using GlassFish Tools Bundle for Eclipse</a></li><li><a href='/2009/05/totd-83-eclipse-tools-bundle-for-glassfish-1-0-now-available/' rel='bookmark' title='Permanent Link: TOTD #83: Eclipse Tools Bundle for GlassFish 1.0 &#8211; Now Available!'>TOTD #83: Eclipse Tools Bundle for GlassFish 1.0 &#8211; Now Available!</a></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.arungupta.me/2009/08/totd-97-glassfish-plugin-with-eclipse-3-5/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>TOTD #96: GlassFish v3 REST Interface to Monitoring and Management &#8211; JSON, XML, and HTML representations</title>
		<link>http://blog.arungupta.me/2009/08/totd-96-glassfish-v3-rest-interface-to-monitoring-and-management-json-xml-and-html-representations/</link>
		<comments>http://blog.arungupta.me/2009/08/totd-96-glassfish-v3-rest-interface-to-monitoring-and-management-json-xml-and-html-representations/#comments</comments>
		<pubDate>Thu, 20 Aug 2009 06:00:00 +0000</pubDate>
		<dc:creator>arungupta</dc:creator>
				<category><![CDATA[admin]]></category>
		<category><![CDATA[totd]]></category>
		<category><![CDATA[glassfish]]></category>
		<category><![CDATA[jersey]]></category>
		<category><![CDATA[management]]></category>
		<category><![CDATA[monitoring]]></category>
		<category><![CDATA[rest]]></category>
		<category><![CDATA[v3]]></category>

		<guid isPermaLink="false">http://blog.arungupta.me/?p=3364</guid>
		<description><![CDATA[GlassFish Monitoring allows you to monitor the state of various runtime components of the application server. This information is used to identify performance bottlenecks and tuning the system for optimal performance, to aid capacity planning, to predict failures, to do root cause analysis in case of failures and sometimes to just ensure that everything is [...]


Related posts:<ol><li><a href='/2007/10/totd-10-consuming-json-and-xml-representations-generated-by-a-jersey-endpoint-in-a-jmaki-table-widget/' rel='bookmark' title='Permanent Link: TOTD #10: Consuming JSON and XML representations generated by a Jersey endpoint in a jMaki Table widget'>TOTD #10: Consuming JSON and XML representations generated by a Jersey endpoint in a jMaki Table widget</a></li><li><a href='/2009/08/totd-91-retrieve-json-libraries-using-maven-dependency-json-lib/' rel='bookmark' title='Permanent Link: TOTD #91: Retrieve JSON libraries using Maven dependency: json-lib'>TOTD #91: Retrieve JSON libraries using Maven dependency: json-lib</a></li><li><a href='/2008/11/totd-56-simple-restful-web-service-using-jersey-and-embeddable-glassfish-text-and-json-output/' rel='bookmark' title='Permanent Link: TOTD #56: Simple RESTful Web service using Jersey and Embeddable GlassFish &#8211; Text and JSON output'>TOTD #56: Simple RESTful Web service using Jersey and Embeddable GlassFish &#8211; Text and JSON output</a></li></ol>]]></description>
			<content:encoded><![CDATA[<p><a href="http://glassfish.org">GlassFish</a> Monitoring allows you to monitor the state of various runtime components of the application server. This information is used to identify performance bottlenecks and tuning the system for optimal performance, to aid capacity planning, to predict failures, to do root cause analysis in case of failures and sometimes to just ensure that everything is functioning as expected.</p>
<p>GlassFish Management allows you to manage the running Application Server instance such as query/create/delete resources (JDBC, JMS, etc), stop/restart the instance, rotate the log and other similar functions.</p>
<p>GlassFish v3 exposes Monitoring and Management data using a REST Interface. This <span style="font-weight: bold;">T</span>ip <span style="font-weight: bold;">O</span>f <span style="font-weight: bold;">T</span>he <span style="font-weight: bold;">D</span>ay (TOTD) shows how to play with this new functionality. <a href="http://blogs.sun.com/aquatic/">Rajeshwar&#8217;s blog</a> has lot of useful information on this topic.</p>
<p>Most of the functionality available in web-based Admin Console and CLI (asadmin) is now available using the REST interface. Both of these are pre-built tools that ships with the GlassFish bundle. The REST interface is a lower level API that enables toolkit developers and IT administrators to write their custom scripts/clients using language of their choice such as Java, JavaScript, Ruby or Groovy.</p>
<p>The default URL for the REST interface of monitoring is &#8220;http://localhost:4848/monitoring/domain&#8221; and for the management is &#8220;http://localhost:4848/management/domain&#8221;. Each URL provides an XML, JSON and HTML representation of the resources. If a web browser is used then a HTML representation is returned and displayed nicely in the browser. <a href="http://blogs.sun.com/aquatic/entry/glassfish_rest_interface">Rajeshwar&#8217;s blog</a> described a <a href="http://blogs.sun.com/aquatic/resource/javaclient.zip">Java client</a> written using <a href="http://blogs.sun.com/arungupta/entry/totd_57_jersey_client_api">Jersey Client APIs</a> that can be used to make all the GET/PUT/POST/DELETE requests. This blog will use something more basic, and extremely popular, to make all the RESTful invocations &#8211; <a href="http://curl.haxx.se/">cURL</a>.</p>
<p>At this time the monitoring resources are read-only (GET) and management can be done using GET/POST/DELETE methods. POST is used for creating and updating resources/objects and the updates can be partial.</p>
<p>Lets get started.</p>
<ol>
<li>Download the <a href="http://hudson.glassfish.org/job/gf-trunk-build-continuous/lastSuccessfulBuild/artifact/bundles/glassfish.zip">latest continuous build from the trunk</a> and unzip. This functionality is also available in the <a href="http://hudson.glassfish.org/job/gf-trunk-build-continuous/lastSuccessfulBuild/artifact/bundles/web.zip">Web profile bundle</a>. This blog is using build <a href="http://hudson.glassfish.org/job/gf-trunk-build-continuous/2023/">#2023</a>.</li>
<li>Start the application server as:<br />
<table style="text-align: left; background-color: #ccccff; width: 100%;" border="0" cellspacing="2" cellpadding="2">
<tbody>
<tr>
<td>~/tools/glassfish/v3/2023/glassfishv3 &gt;<span style="font-weight: bold;">./bin/asadmin start-domain &#8211;verbose</span></p>
<p>Aug 19, 2009 9:52:45 AM com.sun.enterprise.admin.launcher.GFLauncherLogger info<br />
INFO: JVM invocation command line:<br />
/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home/bin/java<br />
-cp</p>
<p>. . .</p>
<p>INFO: felix.fileinstall.dir            /Users/arungupta/tools/glassfish/v3/2023/glassfishv3/glassfish/domains/domain1/autodeploy-bundles<br />
Aug 19, 2009 9:53:05 AM<br />
INFO: felix.fileinstall.debug          1<br />
Aug 19, 2009 9:53:05 AM<br />
INFO: felix.fileinstall.bundles.new.start          true</td>
</tr>
</tbody>
</table>
</li>
<li>Monitoring information &#8211; Lets monitor this GlassFish instance using the REST interface.
<ol>
<li>Retrieve JSON information &#8211; As mentioned above, the monitoring resources are read-only and so the information can be accessed as:<br />
<table style="text-align: left; background-color: #ccccff; width: 100%;" border="0" cellspacing="2" cellpadding="2">
<tbody>
<tr>
<td>~/tools/glassfish/v3/2023/glassfishv3 &gt;<span style="font-weight: bold;">curl -H &#8220;Accept: application/json&#8221; http://localhost:4848/monitoring/domain -v</span><br />
* About to connect() to localhost port 4848 (#0)<br />
*   Trying ::1&#8230; connected<br />
* Connected to localhost (::1) port 4848 (#0)<br />
&gt; GET /monitoring/domain HTTP/1.1<br />
&gt; User-Agent: curl/7.16.3 (powerpc-apple-darwin9.0) libcurl/7.16.3 OpenSSL/0.9.7l zlib/1.2.3<br />
&gt; Host: localhost:4848<br />
&gt; Accept: application/json<br />
&gt;<br />
&lt; HTTP/1.1 200 OK<br />
&lt; Content-Type: application/json<br />
&lt; Transfer-Encoding: chunked<br />
&lt; Date: Wed, 19 Aug 2009 17:40:29 GMT<br />
&lt;<br />
{Domain:{},&#8221;child-resources&#8221;:["http://localhost:4848/monitoring/domain/server"]}<br />
* Connection #0 to host localhost left intact<br />
* Closing connection #0</td>
</tr>
</tbody>
</table>
<p>The command explicitly asks for JSON representation of the resources. The outbound headers are prepended with &#8220;&gt;&#8221; and inbound headers with &#8220;&lt;&#8221;. And the JSON representation is shown in the last line as:</p>
<table style="text-align: left; background-color: #ccccff; width: 100%;" border="0" cellspacing="2" cellpadding="2">
<tbody>
<tr>
<td>{Domain:{},&#8221;child-resources&#8221;:["http://localhost:4848/monitoring/domain/server"]}</td>
</tr>
</tbody>
</table>
<p>The key element to remember here is &#8220;http://localhost:4848/monitoring/domain/server&#8221; which can be used to retrieve more monitoring information.</li>
<li>XML represetation: Lets change the command to ask for XML representation as:<br />
<table style="text-align: left; background-color: #ccccff; width: 100%;" border="0" cellspacing="2" cellpadding="2">
<tbody>
<tr>
<td>~/tools/glassfish/v3/2023/glassfishv3 &gt;<span style="font-weight: bold;">curl -H &#8220;Accept: application/xml&#8221; http://localhost:4848/monitoring/domain -v</span><br />
* About to connect() to localhost port 4848 (#0)<br />
*   Trying ::1&#8230; connected<br />
* Connected to localhost (::1) port 4848 (#0)<br />
&gt; GET /monitoring/domain HTTP/1.1<br />
&gt; User-Agent: curl/7.16.3 (powerpc-apple-darwin9.0) libcurl/7.16.3 OpenSSL/0.9.7l zlib/1.2.3<br />
&gt; Host: localhost:4848<br />
&gt; Accept: application/xml<br />
&gt;<br />
&lt; HTTP/1.1 200 OK<br />
&lt; Content-Type: application/xml<br />
&lt; Transfer-Encoding: chunked<br />
&lt; Date: Wed, 19 Aug 2009 17:43:51 GMT<br />
&lt;<br />
&lt;Domain&gt;<br />
&lt;child-resource&gt;http://localhost:4848/monitoring/domain/server&lt;/child-resource&gt;<br />
&lt;/Domain&gt;<br />
* Connection #0 to host localhost left intact<br />
* Closing connection #0</td>
</tr>
</tbody>
</table>
<p>The command changes the &#8220;Accept&#8221; header to &#8220;application/xml&#8221; and now the XML representation of the monitoring resources is returned as:</p>
<table style="text-align: left; background-color: #ccccff; width: 100%;" border="0" cellspacing="2" cellpadding="2">
<tbody>
<tr>
<td>&lt;Domain&gt;<br />
&lt;child-resource&gt;http://localhost:4848/monitoring/domain/server&lt;/child-resource&gt;<br />
&lt;/Domain&gt;</td>
</tr>
</tbody>
</table>
</li>
<li>HTML representation: The command can be altered to get the HTML representation as &#8220;<span style="font-weight: bold;">curl -H &#8220;Accept: text/html&#8221; http://localhost<br />
:4848/monitoring/domain -v</span>&#8220;. But HTML is more pleasant when rendered by a browser and so viewing the page &#8220;http://localhost:4848/monitoring/domain&#8221; in the browser is shown as:</p>
<p><img style="border: 1px solid; width: 603px; height: 273px;" src="/wp-content/uploads/2009/08/gfv3-2023-rest-monitoring-main.png" alt="" /></li>
<li>Get more information: As mentioned above, more information about this GlassFish instance can be accessed by GETing from &#8220;http://localhost:4848/monitoring/domain/server&#8221; and here is the result:<br />
<table style="text-align: left; background-color: #ccccff; width: 100%;" border="0" cellspacing="2" cellpadding="2">
<tbody>
<tr>
<td>&lt;/tools/glassfish/v3/2023/glassfishv3 &gt;<span style="font-weight: bold;">curl -H &#8220;Accept: application/json&#8221; http://localhost:4848/monitoring/domain/server -v</span><br />
* About to connect() to localhost port 4848 (#0)<br />
*   Trying ::1&#8230; connected<br />
* Connected to localhost (::1) port 4848 (#0)<br />
&gt; GET /monitoring/domain/server HTTP/1.1<br />
&gt; User-Agent: curl/7.16.3 (powerpc-apple-darwin9.0) libcurl/7.16.3 OpenSSL/0.9.7l zlib/1.2.3<br />
&gt; Host: localhost:4848<br />
&gt; Accept: application/json<br />
&gt;<br />
&lt; HTTP/1.1 200 OK<br />
&lt; Content-Type: application/json<br />
&lt; Transfer-Encoding: chunked<br />
&lt; Date: Wed, 19 Aug 2009 17:56:41 GMT<br />
&lt;<br />
{Server:{},&#8221;child-resources&#8221;:["http://localhost:4848/monitoring/domain/server/webintegration",<br />
"http://localhost:4848/monitoring/domain/server/transaction-service",<br />
"http://localhost:4848/monitoring/domain/server/network",<br />
"http://localhost:4848/monitoring/domain/server/jvm",<br />
"http://localhost:4848/monitoring/domain/server/web",<br />
"http://localhost:4848/monitoring/domain/server/realm",<br />
"http://localhost:4848/monitoring/domain/server/http-service"]}<br />
* Connection #0 to host localhost left intact<br />
* Closing connection #0</td>
</tr>
</tbody>
</table>
<p>An HTML rendering of this representation looks like:</p>
<p><img style="border: 1px solid; width: 655px; height: 378px;" src="/wp-content/uploads/2009/08/gfv3-2023-rest-monitoring-server.png" alt="" /></p>
<p>You can keep clicking on the links and more detailed information about that resource is displayed. This is just one HTML representation and is purposely kept light-weight. You can certainly grab the XML representation and apply an XSLT to generate your own HTML rendering.</p>
<p>The monitoring levels for different modules can be easily changed using the management REST interface as explained below.</li>
</ol>
</li>
<li>Management of the GlassFish instance
<ol>
<li>Lets see all the options supported by management REST interface as:<br />
<table style="text-align: left; background-color: #ccccff; width: 100%;" border="0" cellspacing="2" cellpadding="2">
<tbody>
<tr>
<td>~/tools/glassfish/v3/2023/glassfishv3 &gt;<span style="font-weight: bold;">curl -X OPTIONS http://localhost:4848/management/domain -v</span><br />
* About to connect() to localhost port 4848 (#0)<br />
*   Trying ::1&#8230; connected<br />
* Connected to localhost (::1) port 4848 (#0)<br />
&gt; OPTIONS /management/domain HTTP/1.1<br />
&gt; User-Agent: curl/7.16.3 (powerpc-apple-darwin9.0) libcurl/7.16.3 OpenSSL/0.9.7l zlib/1.2.3<br />
&gt; Host: localhost:4848<br />
&gt; Accept: */*<br />
&gt;<br />
&lt; HTTP/1.1 200 OK<br />
&lt; Content-Type: application/json<br />
&lt; Transfer-Encoding: chunked<br />
&lt; Date: Wed, 19 Aug 2009 18:07:14 GMT<br />
&lt;<br />
{<br />
&#8220;Method&#8221;:&#8221;GET&#8221;</p>
<p>&#8220;Method&#8221;:&#8221;PUT&#8221;<br />
}<br />
* Connection #0 to host localhost left intact<br />
* Closing connection #0</td>
</tr>
</tbody>
</table>
<p>Specifying &#8220;-X OPTIONS&#8221; switch displays the various HTTP methods supported by the REST interface. Even though the results show GET and PUT, but it really means GET and POST (<a href="https://glassfish.dev.java.net/issues/show_bug.cgi?id=9177">issue #9177</a>). Lets try &#8220;GET&#8221; first.</li>
<li>GET JSON information as:<br />
<table style="text-align: left; background-color: #ccccff; width: 100%;" border="0" cellspacing="2" cellpadding="2">
<tbody>
<tr>
<td>~/tools/glassfish/v3/2023/glassfishv3 &gt;<span style="font-weight: bold;">curl -H &#8220;Accept: application/json&#8221; http://localhost:4848/management/domain -v</span><br />
* About to connect() to localhost port 4848 (#0)<br />
*   Trying ::1&#8230; connected<br />
* Connected to localhost (::1) port 4848 (#0)<br />
&gt; GET /management/domain HTTP/1.1<br />
&gt; User-Agent: curl/7.16.3 (powerpc-apple-darwin9.0) libcurl/7.16.3 OpenSSL/0.9.7l zlib/1.2.3<br />
&gt; Host: localhost:4848<br />
&gt; Accept: application/json<br />
&gt;<br />
&lt; HTTP/1.1 200 OK<br />
&lt; Content-Type: application/json<br />
&lt; Transfer-Encoding: chunked<br />
&lt; Date: Wed, 19 Aug 2009 18:14:46 GMT<br />
&lt;<br />
{Domain:{&#8221;log-root&#8221; : &#8220;${com.sun.aas.instanceRoot}/logs&#8221;,&#8221;application-root&#8221; : &#8220;${com.sun.aas.instanceRoot}/applications&#8221;,&#8221;locale&#8221; : &#8220;&#8221;,&#8221;version&#8221; : &#8220;re-continuous&#8221;},&#8221;child-resources&#8221;:["http://localhost:4848/management/domain/configs",<br />
"http://localhost:4848/management/domain/resources","http://localhost:4848/management/domain/servers",<br />
"http://localhost:4848/management/domain/property","http://localhost:4848/management/domain/applications",<br />
"http://localhost:4848/management/domain/system-applications","http://localhost:4848/management/domain/stop",<br />
"http://localhost:4848/management/domain/restart","http://localhost:4848/management/domain/uptime",<br />
"http://localhost:4848/management/domain/version","http://localhost:4848/management/domain/rotate-log",<br />
"http://localhost:4848/management/domain/host-port"]}<br />
* Connection #0 to host localhost left intact<br />
* Closing connection #0</td>
</tr>
</tbody>
</table>
<p>As the result shows, there are several RESTful URLs available (in &#8220;child-resources&#8221; element) to manage this GlassFish instance. For example:</p>
<ol>
<li>Show the host/port of GlassFish instance as:<br />
<table style="text-align: left; background-color: #ccccff; width: 100%;" border="0" cellspacing="2" cellpadding="2">
<tbody>
<tr>
<td>curl -H &#8220;Accept: application/json&#8221; http://localhost:4848/management/domain/host-port -v</td>
</tr>
</tbody>
</table>
<p>will show the result as:</p>
<table style="text-align: left; background-color: #ccccff; width: 100%;" border="0" cellspacing="2" cellpadding="2">
<tbody>
<tr>
<td>{&#8221;GetHostAndPort&#8221;:{&#8221;value&#8221; : &#8220;dhcp-usca14-132-79.SFBay.Sun.COM:8080&#8243;}}</td>
</tr>
</tbody>
</table>
</li>
<li>Show that web-based Admin Console is pre-installed as system application using:<br />
<table style="text-align: left; background-color: #ccccff; width: 100%;" border="0" cellspacing="2" cellpadding="2">
<tbody>
<tr>
<td>curl -H &#8220;Accept: application/json&#8221; http://localhost:4848/management/domain/system-applications/application/__admingui -v</td>
</tr>
</tbody>
</table>
<p>will show the result as:</p>
<table style="text-align: left; background-color: #ccccff; width: 100%;" border="0" cellspacing="2" cellpadding="2">
<tbody>
<tr>
<td>{__admingui:{&#8221;libraries&#8221; : &#8220;&#8221;,&#8221;availability-enabled&#8221; : &#8220;false&#8221;,&#8221;enabled&#8221; : &#8220;true&#8221;,&#8221;context-root&#8221; : &#8220;&#8221;,&#8221;location&#8221; : &#8220;${com.sun.aas.installRootURI}/lib/install/applications/__admingui&#8221;,&#8221;description&#8221; : &#8220;&#8221;,&#8221;name&#8221; : &#8220;__admingui&#8221;,&#8221;directory-deployed&#8221; : &#8220;true&#8221;,&#8221;object-type&#8221; : &#8220;system-admin&#8221;},&#8221;child-resources&#8221;:["http://localhost:4848/management/domain/system-applications/application/__admingui/module"]}<!--<br /--> td&gt;</td>
</tr>
</tbody>
</table>
</li>
<li>Query the monitoring levels of different modules as:<br />
<table style="text-align: left; background-color: #ccccff; width: 100%;" border="0" cellspacing="2" cellpadding="2">
<tbody>
<tr>
<td>curl -H &#8220;Accept: application/json&#8221; http://localhost:4848/management/domain/configs/config/server-config/monitoring-service/module-monitoring-levels -v</td>
</tr>
</tbody>
</table>
<p>to see the result as:</p>
<table style="text-align: left; background-color: #ccccff; width: 100%;" border="0" cellspacing="2" cellpadding="2">
<tbody>
<tr>
<td>{ModuleMonitoringLevels:{&#8221;transaction-service&#8221; : &#8220;OFF&#8221;,&#8221;ejb-container&#8221; : &#8220;OFF&#8221;,&#8221;jdbc-connection-pool&#8221; : &#8220;OFF&#8221;,&#8221;orb&#8221; : &#8220;OFF&#8221;,&#8221;http-service&#8221; : &#8220;OFF&#8221;,&#8221;connector-connection-pool&#8221; : &#8220;OFF&#8221;,&#8221;jms-service&#8221; : &#8220;OFF&#8221;,&#8221;connector-service&#8221; : &#8220;OFF&#8221;,&#8221;jvm&#8221; : &#8220;OFF&#8221;,&#8221;thread-pool&#8221; : &#8220;OFF&#8221;,&#8221;web-container&#8221; : &#8220;OFF&#8221;},&#8221;child-resources&#8221;:[]}</td>
</tr>
</tbody>
</table>
<p>And then change the monitoring level of Web container as:</p>
<table style="text-align: left; background-color: #ccccff; width: 100%;" border="0" cellspacing="2" cellpadding="2">
<tbody>
<tr>
<td>~/tools/glassfish/v3/2023/glassfishv3 &gt;<span style="font-weight: bold;">curl -X POST -d &#8220;web-container=ON&#8221; -H &#8220;Accept: application/json&#8221; http://localhost:4848/management/domain/configs/config/server-config/monitoring-service/module-monitoring-levels -v</span><br />
* About to connect() to localhost port 4848 (#0)<br />
*   Trying ::1&#8230; connected<br />
* Connected to localhost (::1) port 4848 (#0)<br />
&gt; POST /management/domain/configs/config/server-config/monitoring-service/module-monitoring-levels HTTP/1.1<br />
&gt; User-Agent: curl/7.16.3 (powerpc-apple-darwin9.0) libcurl/7.16.3 OpenSSL/0.9.7l zlib/1.2.3<br />
&gt; Host: localhost:4848<br />
&gt; Accept: application/json<br />
&gt; Content-Length: 16<br />
&gt; Content-Type: application/x-www-form-urlencoded<br />
&gt;<br />
&lt; HTTP/1.1 200 OK<br />
&lt; Content-Type: application/json<br />
&lt; Transfer-Encoding: chunked<br />
&lt; Date: Wed, 19 Aug 2009 22:01:31 GMT<br />
&lt;<br />
* Connection #0 to host localhost left intact<br />
* Closing connection #0<br />
&#8220;http://localhost:4848/management/domain/configs/config/server-config/monitoring-service/module-monitoring-levels&#8221; updated successfully</td>
</tr>
</tbody>
</table>
<p>The last line shows that the monitoring level is successfull updated and can be verified again as:</p>
<table style="text-align: left; background-color: #ccccff; width: 100%;" border="0" cellspacing="2" cellpadding="2">
<tbody>
<tr>
<td>~/tools/glassfish/v3/2023/glassfishv3 &gt;<span style="font-weight: bold;">curl -H &#8220;Accept: application/json&#8221; http://localhost:4848/management/domain/configs/config/server-config/monitoring-service/module-monitoring-levels -v</span><br />
* About to connect() to localhost port 4848 (#0)<br />
*   Trying ::1&#8230; connected<br />
* Connected to localhost (::1) port 4848 (#0)<br />
&gt; GET /management/domain/configs/config/server-config/monitoring-service/module-monitoring-levels HTTP/1.1<br />
&gt; User-Agent: curl/7.16.3 (powerpc-apple-darwin9.0) libcurl/7.16.3 OpenSSL/0.9.7l zlib/1.2.3<br />
&gt; Host: localhost:4848<br />
&gt; Accept: application/json<br />
&gt;<br />
&lt; HTTP/1.1 200 OK<br />
&lt; Content-Type: application/json<br />
&lt; Transfer-Encoding: chunked<br />
&lt; Date: Wed, 19 Aug 2009 22:36:47 GMT<br />
&lt;<br />
* Connection #0 to host localhost left intact<br />
* Closing connection #0<br />
{ModuleMonitoringLevels:{&#8221;transaction-service&#8221; : &#8220;OFF&#8221;,&#8221;ejb-container&#8221; : &#8220;OFF&#8221;,&#8221;jdbc-connection-pool&#8221; : &#8220;OFF&#8221;,&#8221;orb&#8221; : &#8220;OFF&#8221;,&#8221;http-service&#8221; : &#8220;OFF&#8221;,&#8221;connector-connection-pool&#8221; : &#8220;OFF&#8221;,&#8221;jms-service&#8221; : &#8220;OFF&#8221;,&#8221;connector-service&#8221; : &#8220;OFF&#8221;,&#8221;jvm&#8221; : &#8220;OFF&#8221;,&#8221;thread-pool&#8221; : &#8220;OFF&#8221;,&#8221;web-container&#8221; : &#8220;ON&#8221;},&#8221;child-resources&#8221;:[]}</td>
</tr>
</tbody>
</table>
</li>
<li>Stop this GlassFish instance using:<br />
<table style="text-align: left; background-color: #ccccff; width: 100%;" border="0" cellspacing="2" cellpadding="2">
<tbody>
<tr>
<td>curl -H &#8220;Accept: application/json&#8221; http://localhost:4848/management/domain/stop -v</td>
</tr>
</tbody>
</table>
<p>Or restart the instance using:</p>
<table style="text-align: left; background-color: #ccccff; width: 100%;" border="0" cellspacing="2" cellpadding="2">
<tbody>
<tr>
<td>curl -H &#8220;Accept: application/json&#8221; http://localhost:4848/management/domain/restart -v</td>
</tr>
</tbody>
</table>
</li>
<li>Create a JDBC resource using an existing connection pool
<ol>
<li>Lets see all the resources that are available:<br />
<table style="text-align: left; background-color: #ccccff; width: 100%;" border="0" cellspacing="2" cellpadding="2">
<tbody>
<tr>
<td>curl -H &#8220;Accept: application/json&#8221; http://localhost:4848/management/domain/resources -v</td>
</tr>
</tbody>
</table>
<p>and the results are shown as:</p>
<table style="text-align: left; background-color: #ccccff; width: 100%;" border="0" cellspacing="2" cellpadding="2">
<tbody>
<tr>
<td>{Resources:{},&#8221;child-resources&#8221;:["http://localhost:4848/management/domain/resources/jdbc-connection-pool",<br />
"http://localhost:4848/management/domain/resources/jdbc-resource"]}</td>
</tr>
</tbody>
</table>
</li>
<li>View all the JDBC connection pools as:<br />
<table style="text-align: left; background-color: #ccccff; width: 100%;" border="0" cellspacing="2" cellpadding="2">
<tbody>
<tr>
<td>curl -H &#8220;Accept: application/json&#8221; http://localhost:4848/management/domain/resources/jdbc/connection-pool -v</td>
</tr>
</tbody>
</table>
<p>and the results are shown as:</p>
<table style="text-align: left; background-color: #ccccff; width: 100%;" border="0" cellspacing="2" cellpadding="2">
<tbody>
<tr>
<td>{JdbcConnectionPool:{},&#8221;child-resources&#8221;:["http://localhost:4848/management/domain/resources/jdbc-connection-pool/__TimerPool",<br />
"http://localhost:4848/management/domain/resources/jdbc-connection-pool/DerbyPool"]}</td>
</tr>
</tbody>
</table>
</li>
<li>See all the JDBC resources available as:<br />
<table style="text-align: left; background-color: #ccccff; width: 100%;" border="0" cellspacing="2" cellpadding="2">
<tbody>
<tr>
<td>curl &#8220;Accept: application/json&#8221; http://localhost:4848/management/domain/resources/jdbc-resource -v</td>
</tr>
</tbody>
</table>
<p>and the results are shown as:</p>
<table style="text-align: left; background-color: #ccccff; width: 100%;" border="0" cellspacing="2" cellpadding="2">
<tbody>
<tr>
<td>{JdbcResource:{},&#8221;child-resources&#8221;:["http://localhost:4848/management/domain/resources/jdbc-resource/jdbc/__TimerPool",<br />
"http://localhost:4848/management/domain/resources/jdbc-resource/jdbc/__default"]}</td>
</tr>
</tbody>
</table>
</li>
<li>See all the OPTIONS accepted for JDBC resource creation as:<br />
<table style="text-align: left; width: 100%;" border="0" cellspacing="2" cellpadding="2">
<tbody>
<tr>
<td>curl -X OPTIONS -H &#8220;Accept: application/json&#8221; http://localhost:4848/management/domain/resources/jdbc-resource -v</td>
</tr>
</tbody>
</table>
<p>with the result as:</p>
<table style="text-align: left; background-color: #ccccff; width: 100%;" border="0" cellspacing="2" cellpadding="2">
<tbody>
<tr>
<td>{<br />
&#8220;Method&#8221;:&#8221;POST&#8221;,<br />
&#8220;Message Parameters&#8221;:{<br />
&#8220;id&#8221;:{&#8221;Acceptable Values&#8221;:&#8221;",&#8221;Default Value&#8221;:&#8221;",&#8221;Type&#8221;:&#8221;class java.lang.String&#8221;,&#8221;Optional&#8221;:&#8221;false&#8221;},<br />
&#8220;enabled&#8221;:{&#8221;Acceptable Values&#8221;:&#8221;",&#8221;Default Value&#8221;:&#8221;true&#8221;,&#8221;Type&#8221;:&#8221;class java.lang.Boolean&#8221;,&#8221;Optional&#8221;:&#8221;true&#8221;},<br />
&#8220;description&#8221;:{&#8221;Acceptable Values&#8221;:&#8221;",&#8221;Default Value&#8221;:&#8221;",&#8221;Type&#8221;:&#8221;class java.lang.String&#8221;,&#8221;Optional&#8221;:&#8221;true&#8221;},<br />
&#8220;target&#8221;:{&#8221;Acceptable Values&#8221;:&#8221;",&#8221;Default Value&#8221;:&#8221;",&#8221;Type&#8221;:&#8221;class java.lang.String&#8221;,&#8221;Optional&#8221;:&#8221;true&#8221;},<br />
&#8220;property&#8221;:{&#8221;Acceptable Values&#8221;:&#8221;",&#8221;Default Value&#8221;:&#8221;",&#8221;Type&#8221;:&#8221;class java.util.Properties&#8221;,&#8221;Optional&#8221;:&#8221;true&#8221;},<br />
&#8220;connectionpoolid&#8221;:{&#8221;Acceptable Values&#8221;:&#8221;",&#8221;Default Value&#8221;:&#8221;",&#8221;Type&#8221;:&#8221;class java.lang.String&#8221;,&#8221;Optional&#8221;:&#8221;false&#8221;}<br />
}</p>
<p>&#8220;Method&#8221;:&#8221;GET&#8221;</td>
</tr>
</tbody>
</table>
</li>
<li>Finally, create the JDBC resource as:<br />
<table style="text-align: left; background-color: #ccccff; width: 100%;" border="0" cellspacing="2" cellpadding="2">
<tbody>
<tr>
<td>~/tools/glassfish/v3/2023/glassfishv3 &gt;<span style="font-weight: bold;">curl -d &#8220;id=jdbc/sample&amp;connectionpoolid=DerbyPool&#8221; http://localhost:4848/management/domain/resources/jdbc-resource -v</span><br />
* About to connect() to localhost port 4848 (#0)<br />
*   Trying ::1&#8230; connected<br />
* Connected to localhost (::1) port 4848 (#0)<br />
&gt; POST /management/domain/resources/jdbc-resource HTTP/1.1<br />
&gt; User-Agent: curl/7.16.3 (powerpc-apple-darwin9.0) libcurl/7.16.3 OpenSSL/0.9.7l zlib/1.2.3<br />
&gt; Host: localhost:4848<br />
&gt; Accept: */*<br />
&gt; Content-Length: 42<br />
&gt; Content-Type: application/x-www-form-urlencoded<br />
&gt;<br />
&lt; HTTP/1.1 201 Created<br />
&lt; Content-Type: text/html<br />
&lt; Transfer-Encoding: chunked<br />
&lt; Date: Wed, 19 Aug 2009 20:45:51 GMT<br />
&lt;<br />
* Connection #0 to host localhost left intact<br />
* Closing connection #0<br />
&#8220;http://localhost:4848/management/domain/resources/jdbc-resource/jdbc/sample&#8221; created successfully.</td>
</tr>
</tbody>
</table>
<p>Note, this is a POST request. The JDBC resource name and JDBC connection pool id are passed as CLI parameters using &#8220;-d&#8221; switch. The last line shows that the JDBC resource was created successfully.</li>
<li>And finally query the JDBC Resources again as:<br />
<table style="text-align: left; background-color: #ccccff; width: 100%;" border="0" cellspacing="2" cellpadding="2">
<tbody>
<tr>
<td>curl -H &#8220;Accept: application/json&#8221; http://localhost:4848/management/domain/resources/jdbc-resource -v</td>
</tr>
</tbody>
</table>
<p>to see the updated result as:</p>
<table style="text-align: left; background-color: #ccccff; width: 100%;" border="0" cellspacing="2" cellpadding="2">
<tbody>
<tr>
<td>{JdbcResource:{},&#8221;child-resources&#8221;:["http://localhost:4848/management/domain/resources/jdbc-resource/jdbc/__TimerPool",<br />
"http://localhost:4848/management/domain/resources/jdbc-resource/jdbc/__default",<br />
"http://localhost:4848/management/domain/resources/jdbc-resource/jdbc/sample"]}</td>
</tr>
</tbody>
</table>
</li>
</ol>
</li>
<p>Similarly JDBC connection pools can be created.</ol>
</li>
<li>POST can be used to update the top-level attributes such as &#8220;log-root&#8221; and &#8220;application-root&#8221;. The name of these attributes are shown in the result of GET.</li>
<li>As earlier, XML representation of management resources can be obtained as:<br />
<table style="text-align: left; background-color: #ccccff; width: 100%;" border="0" cellspacing="2" cellpadding="2">
<tbody>
<tr>
<td>~/tools/glassfish/v3/2023/glassfishv3 &gt;<span style="font-weight: bold;">curl -H &#8220;Accept: application/xml&#8221; http://localhost:4848/management/domain -v</span><br />
* About to connect() to localhost port 4848 (#0)<br />
*   Trying ::1&#8230; connected<br />
* Connected to localhost (::1) port 4848 (#0)<br />
&gt; GET /management/domain HTTP/1.1<br />
&gt; User-Agent: curl/7.16.3 (powerpc-apple-darwin9.0) libcurl/7.16.3 OpenSSL/0.9.7l zlib/1.2.3<br />
&gt; Host: localhost:4848<br />
&gt; Accept: application/xml<br />
&gt;<br />
&lt; HTTP/1.1 200 OK<br />
&lt; Content-Type: application/xml<br />
&lt; Transfer-Encoding: chunked<br />
&lt; Date: Wed, 19 Aug 2009 18:17:07 GMT<br />
&lt;<br />
&lt;Domain log-root=&#8221;${com.sun.aas.instanceRoot}/logs&#8221; application-root=&#8221;${com.sun.aas.instanceRoot}/applications&#8221; locale=&#8221;" version=&#8221;re-continuous&#8221;&gt;<br />
&lt;child-resource&gt;http://localhost:4848/management/domain/configs&lt;/child-resource&gt;<br />
&lt;child-resource&gt;http://localhost:4848/management/domain/resources&lt;/child-resource&gt;<br />
&lt;child-resource&gt;http://localhost:4848/management/domain/servers&lt;/child-resource&gt;<br />
&lt;child-resource&gt;http://localhost:4848/management/domain/property&lt;/child-resource&gt;<br />
&lt;child-resource&gt;http://localhost:4848/management/domain/applications&lt;/child-resource&gt;<br />
&lt;child-resource&gt;http://localhost:4848/management/domain/system-applications&lt;/child-resource&gt;<br />
&lt;child-resource&gt;http://localhost:4848/management/domain/stop&lt;/child-resource&gt;<br />
&lt;child-resource&gt;http://localhost:4848/management/domain/restart&lt;/child-resource&gt;<br />
&lt;child-resource&gt;http://localhost:4848/management/domain/uptime&lt;/child-resource&gt;<br />
&lt;child-resource&gt;http://localhost:4848/management/domain/version&lt;/child-resource&gt;<br />
&lt;child-resource&gt;http://localhost:4848/management/domain/rotate-log&lt;/child-resource&gt;<br />
&lt;child-resource&gt;http://localhost:4848/management/domain/host-port&lt;/child-resource&gt;<br />
* Connection #0 to host localhost left intact<br />
* Closing connection #0</td>
</tr>
</tbody>
</table>
<p>Just changing the &#8220;Accept&#8221; header to &#8220;application/xml&#8221; did the trick.</li>
<li>And an HTML representation can be obtained by viewing the URL &#8220;http://localhost:4848/management/domain&#8221; in the browser with result as:<img style="border: 1px solid; width: 641px; height: 628px;" src="/wp-content/uploads/2009/08/gfv3-2023-rest-management-server.png" alt="" /></li>
</ol>
</li>
</ol>
<p>Just like GlassFish v3, the REST interface is extensible as well. So if a new container is plugged in that generates data (possibly through probes) captured in the runtime tree, that is automatically exposed in the RESTful interface.</p>
<p>Now for the Mac users, <a href="http://www.newmediacampaigns.com/page/webkit-team-admits-accept-header-error">Safari prefers XML over HTML</a>. Basically a resource, that can be served using both XML and HTML representation (as our Management and Monitoring interface), is served as XML by Safari and HTML by Firefox. So use Firefox on Mac if you want HTML rendering.</p>
<p>How will you use GlassFish RE<br />
ST interface ?</p>
<p>Do your application server provide that level of administration capability ?</p>
<p>Please leave suggestions on other TOTD that you&#8217;d like to see. A complete archive of all the tips is available <a href="/?tag=totd">here</a>.</p>
<p><small>Technorati: <a href="http://technorati.com/tags/totd">totd</a> <a href="http://technorati.com/tags/glassfish">glassfish</a> <a href="http://technorati.com/tags/v3">v3</a> <a href="http://technorati.com/tags/rest">rest</a> <a href="http://technorati.com/tags/management">management</a> <a href="http://technorati.com/tags/monitoring">monitoring</a> <a href="http://technorati.com/tags/jersey">jersey</a></small></p>


<p>Related posts:<ol><li><a href='/2007/10/totd-10-consuming-json-and-xml-representations-generated-by-a-jersey-endpoint-in-a-jmaki-table-widget/' rel='bookmark' title='Permanent Link: TOTD #10: Consuming JSON and XML representations generated by a Jersey endpoint in a jMaki Table widget'>TOTD #10: Consuming JSON and XML representations generated by a Jersey endpoint in a jMaki Table widget</a></li><li><a href='/2009/08/totd-91-retrieve-json-libraries-using-maven-dependency-json-lib/' rel='bookmark' title='Permanent Link: TOTD #91: Retrieve JSON libraries using Maven dependency: json-lib'>TOTD #91: Retrieve JSON libraries using Maven dependency: json-lib</a></li><li><a href='/2008/11/totd-56-simple-restful-web-service-using-jersey-and-embeddable-glassfish-text-and-json-output/' rel='bookmark' title='Permanent Link: TOTD #56: Simple RESTful Web service using Jersey and Embeddable GlassFish &#8211; Text and JSON output'>TOTD #56: Simple RESTful Web service using Jersey and Embeddable GlassFish &#8211; Text and JSON output</a></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.arungupta.me/2009/08/totd-96-glassfish-v3-rest-interface-to-monitoring-and-management-json-xml-and-html-representations/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>LOTD #22: How to inject JPA resources ? &#8211; PersistenceUnit vs PersistenceContext</title>
		<link>http://blog.arungupta.me/2009/08/lotd-22-how-to-inject-jpa-resources-persistenceunit-vs-persistencecontext/</link>
		<comments>http://blog.arungupta.me/2009/08/lotd-22-how-to-inject-jpa-resources-persistenceunit-vs-persistencecontext/#comments</comments>
		<pubDate>Tue, 18 Aug 2009 10:00:00 +0000</pubDate>
		<dc:creator>arungupta</dc:creator>
				<category><![CDATA[glassfish]]></category>
		<category><![CDATA[lotd]]></category>
		<category><![CDATA[javaee]]></category>
		<category><![CDATA[jpa]]></category>
		<category><![CDATA[persistence]]></category>

		<guid isPermaLink="false">http://blog.arungupta.me/?p=3365</guid>
		<description><![CDATA[ Java Persistence API defines a standard object/relational mapping using POJOs. In JPA, a persistence unit is described using &#8220;persistence.xml&#8221;, bundled with the web application, injected into your web application and then POJOs are used to access all the information from the underlying persistence mechanism such as a database.
 JPA can injected into your application [...]


Related posts:<ol><li><a href='/2008/08/lotd-3-rails-2-2-going-multi-threaded/' rel='bookmark' title='Permanent Link: LOTD #3: Rails 2.2 going multi-threaded'>LOTD #3: Rails 2.2 going multi-threaded</a></li><li><a href='/2008/11/lotd-13-warbling-with-rmagick-on-glassfish/' rel='bookmark' title='Permanent Link: LOTD #13: Warbling with RMagick on GlassFish'>LOTD #13: Warbling with RMagick on GlassFish</a></li><li><a href='/2008/08/lotd-6-rails-deployment-on-glassfish-in-4-steps-and-15-minutes/' rel='bookmark' title='Permanent Link: LOTD #6: Rails Deployment on GlassFish in 4 steps and 15 minutes'>LOTD #6: Rails Deployment on GlassFish in 4 steps and 15 minutes</a></li></ol>]]></description>
			<content:encoded><![CDATA[<p> Java Persistence API defines a standard object/relational mapping using POJOs. In JPA, a <span style="font-style: italic;">persistence unit</span> is described using &#8220;persistence.xml&#8221;, bundled with the web application, injected into your web application and then POJOs are used to access all the information from the underlying persistence mechanism such as a database.</p>
<p> JPA can injected into your application couple of different ways as shown below:</p>
<table  style="text-align: left; background-color: rgb(204, 204, 255); width: 100%;"  cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td>@PersistenceUnit<br /> EntityManagerFactory emf;</td>
</tr>
</tbody>
</table>
<p> and</p>
<table  style="text-align: left; background-color: rgb(204, 204, 255); width: 100%;"  cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td>@PersistenceContext<br /> EntityManager manager; </td>
</tr>
</tbody>
</table>
<p> Which one is preferred, why, and pros/cons are very clearly explained in (slightly old but very relevant) <a  href="http://weblogs.java.net/blog/ss141213/archive/2005/12/dont_use_persis_1.html">this blog</a>. It also discusses a JNDI approach.</p>
<p> In case you are interested in the summary:<br /> 
<ul>
<li>Use &#8220;@PersistenceUnit EntityManagerFactory&#8221; for Servlets because of thread safety</li>
<li>Use &#8220;@PersistenceContext EntityManager&#8221; in EJBs for simpler/cleaner code</li>
</ul>
<p> Read other <a href="http://blogs.sun.com/arungupta/tags/jpa">JPA related entries</a>.<br /> All previous entries in this series are archived at <a  href="http://blogs.sun.com/arungupta/tag/lotd">LOTD</a>. </p>
<p> <small>Technorati: <a href="http://technorati.com/tag/lotd">lotd</a> <a href="http://technorati.com/tag/glassfish">glassfish</a> <a href="http://technorati.com/tags/jpa">jpa</a> <a  href="http://technorati.com/tags/javaee">javaee</a> <a  href="http://technorati.com/tags/persistence">persistence</a></small></p>


<p>Related posts:<ol><li><a href='/2008/08/lotd-3-rails-2-2-going-multi-threaded/' rel='bookmark' title='Permanent Link: LOTD #3: Rails 2.2 going multi-threaded'>LOTD #3: Rails 2.2 going multi-threaded</a></li><li><a href='/2008/11/lotd-13-warbling-with-rmagick-on-glassfish/' rel='bookmark' title='Permanent Link: LOTD #13: Warbling with RMagick on GlassFish'>LOTD #13: Warbling with RMagick on GlassFish</a></li><li><a href='/2008/08/lotd-6-rails-deployment-on-glassfish-in-4-steps-and-15-minutes/' rel='bookmark' title='Permanent Link: LOTD #6: Rails Deployment on GlassFish in 4 steps and 15 minutes'>LOTD #6: Rails Deployment on GlassFish in 4 steps and 15 minutes</a></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.arungupta.me/2009/08/lotd-22-how-to-inject-jpa-resources-persistenceunit-vs-persistencecontext/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>TOTD #95: EJB 3.1 + Java Server Faces 2.0 + JPA 2.0 web application &#8211; Getting Started with Java EE 6 using NetBeans 6.8 M1 &amp; GlassFish v3</title>
		<link>http://blog.arungupta.me/2009/08/totd-95-ejb-3-1-java-server-faces-2-0-jpa-2-0-web-application-getting-started-with-java-ee-6-using-netbeans-6-8-m1-glassfish-v3/</link>
		<comments>http://blog.arungupta.me/2009/08/totd-95-ejb-3-1-java-server-faces-2-0-jpa-2-0-web-application-getting-started-with-java-ee-6-using-netbeans-6-8-m1-glassfish-v3/#comments</comments>
		<pubDate>Mon, 17 Aug 2009 10:00:00 +0000</pubDate>
		<dc:creator>arungupta</dc:creator>
				<category><![CDATA[javaserverfaces]]></category>
		<category><![CDATA[netbeans]]></category>
		<category><![CDATA[totd]]></category>

		<guid isPermaLink="false">http://blog.arungupta.me/?p=3366</guid>
		<description><![CDATA[TOTD #93 showed how to get started with Java EE 6 using NetBeans 6.8 M1 and GlassFish v3 by building a simple Servlet 3.0 + JPA 2.0 web application. TOTD #94 built upon it by using Java Server Faces 2 instead of Servlet 3.0 for displaying the results. However we are still using a POJO [...]


Related posts:<ol><li><a href='/2009/08/totd-94-a-simple-java-server-faces-2-0-jpa-2-0-application-getting-started-with-java-ee-6-using-netbeans-6-8-m1-glassfish-v3/' rel='bookmark' title='Permanent Link: TOTD #94: A simple Java Server Faces 2.0 + JPA 2.0 application &#8211; Getting Started with Java EE 6 using NetBeans 6.8 M1 &#038; GlassFish v3'>TOTD #94: A simple Java Server Faces 2.0 + JPA 2.0 application &#8211; Getting Started with Java EE 6 using NetBeans 6.8 M1 &#038; GlassFish v3</a></li><li><a href='/2009/05/totd-82-getting-started-with-servlet-3-0-and-ejb-3-1-in-java-ee-6-using-netbeans-6-7/' rel='bookmark' title='Permanent Link: TOTD #82: Getting Started with Servlet 3.0 and EJB 3.1 in Java EE 6 using NetBeans 6.7'>TOTD #82: Getting Started with Servlet 3.0 and EJB 3.1 in Java EE 6 using NetBeans 6.7</a></li><li><a href='/2008/10/totd-49-converting-a-jsf-1-2-application-to-jsf-2-0-managedbean/' rel='bookmark' title='Permanent Link: TOTD #49: Converting a JSF 1.2 application to JSF 2.0 &#8211; @ManagedBean'>TOTD #49: Converting a JSF 1.2 application to JSF 2.0 &#8211; @ManagedBean</a></li></ol>]]></description>
			<content:encoded><![CDATA[<p><a href="http://blogs.sun.com/arungupta/entry/totd_93_getting_started_with">TOTD #93</a> showed how to get started with <a href="http://jcp.org/en/jsr/detail?id=316">Java EE 6</a> using <a href="http://www.netbeans.org/servlets/NewsItemView?newsItemID=1413">NetBeans 6.8 M1</a> and <a href="http://glassfish.org">GlassFish v3</a> by building a simple Servlet 3.0 + JPA 2.0 web application. <a href="http://blogs.sun.com/arungupta/entry/totd_94_a_simple_java">TOTD #94</a> built upon it by using Java Server Faces 2 instead of Servlet 3.0 for displaying the results. However we are still using a POJO for all the database interactions. This works fine if we are only reading values from the database but that&#8217;s not how a typical web application behaves. The web application would typically perform all CRUD operations. More typically they like to perform one or more CRUD operations within the context of a transaction. And how do you do transactions in the context of a web application ? Java EE 6 comes to your rescue.</p>
<p>The <a href="http://jcp.org/en/jsr/detail?id=318">EJB 3.1 specification</a> (another new specification in Java EE 6) allow POJO classes to be annotated with @EJB and bundled within WEB-INF/classes of a WAR file. And so you get all transactional capabilities in your web application very easily.</p>
<p>This <span style="font-weight: bold;">T</span>ip <span style="font-weight: bold;">O</span>f <span style="font-weight: bold;">T</span>he <span style="font-weight: bold;">D</span>ay (TOTD) shows how to enhance the application created in TOTD #94 and use EJB 3.1 instead of the JSF <span style="font-style: italic;">managed bean</span> for performing the business logic. There are two ways to achieve this pattern as described below.</p>
<p>Lets call this TOTD #95.1</p>
<ol>
<li>The easiest way to back a JSF page with an EJB is to convert the managed bean into an EJB by adding @javax.ejb.Stateless annotation. So change the  &#8220;StateList&#8221; class from TOTD #94 as shown below:<br />
<table style="text-align: left; background-color: #ccccff; width: 100%;" border="0" cellspacing="2" cellpadding="2">
<tbody>
<tr>
<td><span style="font-weight: bold;">@javax.ejb.Stateless</span><br />
@ManagedBean<br />
public class StateList {<br />
@PersistenceUnit<br />
EntityManagerFactory emf;</p>
<p>public List&lt;States&gt; getStates() {<br />
return emf.createEntityManager().createNamedQuery(&#8221;States.findAll&#8221;).getResultList();<br />
}<br />
}</td>
</tr>
</tbody>
</table>
<p>The change is highlighted in bold, and that&#8217;s it!</li>
</ol>
<p>Because of &#8220;Deploy-on-save&#8221; feature in NetBeans and GlassFish v3, the application is autodeployed. Otherwise right-click on the project and select Run (default shortcut &#8220;F6&#8243;). As earlier, the results can be seen at &#8220;http://localhost:8080/HelloEclipseLink/forwardToJSF.jsp&#8221; or &#8220;http://localhost:8080/HelloEclipseLink/faces/template-client.xhtml&#8221; and looks like:</p>
<p><img style="border: 1px solid; width: 465px; height: 605px;" src="/wp-content/uploads/2009/08/nb68m1-jee6-ejb-1st-output.png" alt="" /></p>
<p>The big difference this time is that the business logic is executed by an EJB in a fully transactional manner. Even though the logic in this case is a single read-only operation to the database, but you get the idea <img src='/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Alternatively, you can use the delegate pattern in the <span style="font-style: italic;">managed bean</span> as described below. Lets call this #95.2.</p>
<ol>
<li>Right-click on the project, select &#8220;New&#8221;, &#8220;Session Bean &#8230;&#8221; and create a stateless session bean by selecting the options as shown below:<span style="text-decoration: underline;"><img style="border: 1px solid; width: 371px; height: 378px;" src="/wp-content/uploads/2009/08/nb68m1-jee6-ejb-create.png" alt="" /></span>
<p>This creates a stateless session with the name &#8220;StateBeanBean&#8221; (<a href="http://www.netbeans.org/issues/show_bug.cgi?id=170392">bug #170392</a> for redundant &#8220;Bean&#8221; in the name).</li>
<li>Simplify your managed bean by refactoring all the business logic to the EJB as shown below:<br />
<table style="text-align: left; background-color: #ccccff; width: 100%;" border="0" cellspacing="2" cellpadding="2">
<tbody>
<tr>
<td>@Stateless<br />
public class StateBeanBean {<br />
@PersistenceUnit<br />
EntityManagerFactory emf;</p>
<p>public List&lt;States&gt; getStates() {<br />
return emf.createEntityManager().createNamedQuery(&#8221;States.findAll&#8221;).getResultList();<br />
}<br />
}</td>
</tr>
</tbody>
</table>
<p>and</p>
<table style="text-align: left; background-color: #ccccff; width: 100%;" border="0" cellspacing="2" cellpadding="2">
<tbody>
<tr>
<td>@ManagedBean<br />
public class StateList {<br />
@EJB StateBeanBean bean;</p>
<p>public List&lt;States&gt; getStates() {<br />
return bean.getStates();<br />
}<br />
}<br />
<span style="font-weight: bold;"> </span></td>
</tr>
</tbody>
</table>
<p>In fact the EJB code can be further simplified to:</p>
<table style="text-align: left; background-color: #ccccff; width: 100%;" border="0" cellspacing="2" cellpadding="2">
<tbody>
<tr>
<td>@Stateless<br />
public class StateBeanBean {<br />
<span style="font-weight: bold;">@PersistenceContext</span><br style="font-weight: bold;" /> <span style="font-weight: bold;"> EntityManager em;</span></p>
<p>public List&lt;States&gt; getStates() {<br />
return <span style="font-weight: bold;">em.</span>createNamedQuery(&#8221;States.findAll&#8221;).getResultList();<br />
}<br />
}<br />
<span style="font-weight: bold;"> </span></td>
</tr>
</tbody>
</table>
<p>The changes are highlighted in bold.</li>
</ol>
<p>If the application is already running then <span style="font-style: italic;">Deploy-on-Save</span> would have automatically deployed the entire application. Otherwise right-click on the project and select Run (default shortcut &#8220;F6&#8243;). Again, the results can be seen at &#8220;http://localhost:8080/HelloEclipseLink/forwardToJSF.jsp&#8221; or &#8220;http://localhost:8080/HelloEclipseLink/faces/template-client.xhtml&#8221; and are displayed as shown in the screenshot above.</p>
<p>The updated directory structure looks like:</p>
<p><img style="border: 1px solid; width: 267px; height: 400px;" src="/wp-content/uploads/2009/08/nb68m1-jee6-ejb-dir-structure.png" alt="" /></p>
<p>The important point to note is that our EJB is bundled in the WAR file and no additional deployment descriptors were added or existing ones modified to achieve that. Now, that&#8217;s really clean <img src='/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>The next blog in this series will show how managed beans can be replaced with WebBeans, err JCDI.</p>
<p>Also refer to other <a href="http://blogs.sun.com/arungupta/tags/javaee6">Java EE 6 blog entries</a>.</p>
<p>Please leave suggestions on other TOTD that you&#8217;d like to see. A complete archive of all the tips is available <a href="/?tag=totd">here</a>.</p>
<p><small>Technorati: <a href="http://technorati.com/tags/totd">totd</a> <a href="http://technorati.com/tags/glassfish">glassfish</a> <a href="http://technorati.com/tags/v3">v3</a> <a href="http://technorati.com/tags/mysql">mysql</a> <a href="http://technorati.com/tags/javaee6">javaee6</a> <a href="http://technorati.com/tags/javaserverfaces">javaserverfaces</a> <a href="http://technorati.com/tags/jpa2">jpa2</a> <a href="http://technorati.com/tags/ejb">ejb</a><!--<br /--> <a href="http://technorati.com/tags/netbeans">netbeans</a></small></p>


<p>Related posts:<ol><li><a href='/2009/08/totd-94-a-simple-java-server-faces-2-0-jpa-2-0-application-getting-started-with-java-ee-6-using-netbeans-6-8-m1-glassfish-v3/' rel='bookmark' title='Permanent Link: TOTD #94: A simple Java Server Faces 2.0 + JPA 2.0 application &#8211; Getting Started with Java EE 6 using NetBeans 6.8 M1 &#038; GlassFish v3'>TOTD #94: A simple Java Server Faces 2.0 + JPA 2.0 application &#8211; Getting Started with Java EE 6 using NetBeans 6.8 M1 &#038; GlassFish v3</a></li><li><a href='/2009/05/totd-82-getting-started-with-servlet-3-0-and-ejb-3-1-in-java-ee-6-using-netbeans-6-7/' rel='bookmark' title='Permanent Link: TOTD #82: Getting Started with Servlet 3.0 and EJB 3.1 in Java EE 6 using NetBeans 6.7'>TOTD #82: Getting Started with Servlet 3.0 and EJB 3.1 in Java EE 6 using NetBeans 6.7</a></li><li><a href='/2008/10/totd-49-converting-a-jsf-1-2-application-to-jsf-2-0-managedbean/' rel='bookmark' title='Permanent Link: TOTD #49: Converting a JSF 1.2 application to JSF 2.0 &#8211; @ManagedBean'>TOTD #49: Converting a JSF 1.2 application to JSF 2.0 &#8211; @ManagedBean</a></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.arungupta.me/2009/08/totd-95-ejb-3-1-java-server-faces-2-0-jpa-2-0-web-application-getting-started-with-java-ee-6-using-netbeans-6-8-m1-glassfish-v3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>TOTD #94: A simple Java Server Faces 2.0 + JPA 2.0 application &#8211; Getting Started with Java EE 6 using NetBeans 6.8 M1 &amp; GlassFish v3</title>
		<link>http://blog.arungupta.me/2009/08/totd-94-a-simple-java-server-faces-2-0-jpa-2-0-application-getting-started-with-java-ee-6-using-netbeans-6-8-m1-glassfish-v3/</link>
		<comments>http://blog.arungupta.me/2009/08/totd-94-a-simple-java-server-faces-2-0-jpa-2-0-application-getting-started-with-java-ee-6-using-netbeans-6-8-m1-glassfish-v3/#comments</comments>
		<pubDate>Fri, 14 Aug 2009 10:00:00 +0000</pubDate>
		<dc:creator>arungupta</dc:creator>
				<category><![CDATA[javaserverfaces]]></category>
		<category><![CDATA[netbeans]]></category>
		<category><![CDATA[totd]]></category>

		<guid isPermaLink="false">http://blog.arungupta.me/?p=3367</guid>
		<description><![CDATA[TOTD #93 showed how to get started with Java EE 6 using NetBeans 6.8 M1 and GlassFish v3 by building a simple Servlet 3.0 + JPA 2.0 web application. JPA 2.0 + Eclipselink was used for the database connectivity and Servlet 3.0 was used for displaying the results to the user. The sample demonstrated how [...]


Related posts:<ol><li><a href='/2009/08/totd-95-ejb-3-1-java-server-faces-2-0-jpa-2-0-web-application-getting-started-with-java-ee-6-using-netbeans-6-8-m1-glassfish-v3/' rel='bookmark' title='Permanent Link: TOTD #95: EJB 3.1 + Java Server Faces 2.0 + JPA 2.0 web application &#8211; Getting Started with Java EE 6 using NetBeans 6.8 M1 &#038; GlassFish v3'>TOTD #95: EJB 3.1 + Java Server Faces 2.0 + JPA 2.0 web application &#8211; Getting Started with Java EE 6 using NetBeans 6.8 M1 &#038; GlassFish v3</a></li><li><a href='/2009/08/totd-93-getting-started-with-java-ee-6-using-netbeans-6-8-m1-glassfish-v3-a-simple-servlet-3-0-jpa-2-0-app/' rel='bookmark' title='Permanent Link: TOTD #93: Getting Started with Java EE 6 using NetBeans 6.8 M1 &#038; GlassFish v3 &#8211; A simple Servlet 3.0 + JPA 2.0 app'>TOTD #93: Getting Started with Java EE 6 using NetBeans 6.8 M1 &#038; GlassFish v3 &#8211; A simple Servlet 3.0 + JPA 2.0 app</a></li><li><a href='/2008/10/totd-49-converting-a-jsf-1-2-application-to-jsf-2-0-managedbean/' rel='bookmark' title='Permanent Link: TOTD #49: Converting a JSF 1.2 application to JSF 2.0 &#8211; @ManagedBean'>TOTD #49: Converting a JSF 1.2 application to JSF 2.0 &#8211; @ManagedBean</a></li></ol>]]></description>
			<content:encoded><![CDATA[<p><a href="http://blogs.sun.com/arungupta/entry/totd_93_getting_started_with">TOTD #93</a> showed how to get started with <a href="http://jcp.org/en/jsr/detail?id=316">Java EE 6</a> using <a href="http://www.netbeans.org/servlets/NewsItemView?newsItemID=1413">NetBeans 6.8 M1</a> and <a href="http://glassfish.org">GlassFish v3</a> by building a simple Servlet 3.0 + JPA 2.0 web application. JPA 2.0 + Eclipselink was used for the database connectivity and Servlet 3.0 was used for displaying the results to the user. The sample demonstrated how the two technologies can be mixed to create a simple web application. But Servlets are meant for server-side processing rather than displaying the results to end user. <a href="http://jcp.org/en/jsr/detail?id=314">JavaServer Faces 2</a> (another new specification in Java EE 6) is designed to fulfill that purpose.</p>
<p>This <span style="font-weight: bold;">T</span>ip <span style="font-weight: bold;">O</span>f <span style="font-weight: bold;">T</span>he <span style="font-weight: bold;">D</span>ay (TOTD) shows how to enhance the application created in TOTD #93 and use JSF 2 for displaying the results.</p>
<ol>
<li>Right-click on the project, select &#8220;Properties&#8221;, select &#8220;Frameworks&#8221;, click on &#8220;Add &#8230;&#8221; as shown below:
<p><a href="/wp-content/uploads/2009/08/nb68m1-jee6-jsf2-add-framework.png"><img style="border: 2px solid; width: 700px; height: 382px;" src="/wp-content/uploads/2009/08/nb68m1-jee6-jsf2-add-framework.png" alt="" /></a></p>
<p>Select &#8220;JavaServer Faces&#8221; and click on &#8220;OK&#8221;. The following configuration screen is shown:</p>
<p><a href="/wp-content/uploads/2009/08/nb68m1-jee6-jsf2-framework-added.png"><img style="border: 2px solid; width: 636px; height: 539px;" src="/wp-content/uploads/2009/08/nb68m1-jee6-jsf2-framework-added.png" alt="" /></a></p>
<p>Click on &#8220;OK&#8221; to complete the dialog. This generates a whole bunch of files (7 to be accurate) in your project. Most of these files are leftover from previous version of NetBeans and will be cleaned up. For example, &#8220;faces-config.xml&#8221; is now optional and &#8220;forwardToJSF.jsp&#8221; is redundant.</li>
<li>Anyway, lets add a POJO class that will be our <span style="font-style: italic;">managed bean</span>. Right-click on &#8220;server&#8221; package and select &#8220;New&#8221;, &#8220;Java Class &#8230;&#8221;, give the name as &#8220;StateList&#8221;. Change the class such that it looks like:<br />
<table style="text-align: left; background-color: #ccccff; width: 100%;" border="0" cellspacing="2" cellpadding="2">
<tbody>
<tr>
<td>package server;</p>
<p>import java.util.List;<br />
import javax.faces.bean.ManagedBean;<br />
import javax.persistence.EntityManagerFactory;<br />
import javax.persistence.PersistenceUnit;<br />
import states.States;</p>
<p>/**<br />
* @author arungupta<br />
*/<br />
@ManagedBean<br />
public class StateList {<br />
@PersistenceUnit<br />
EntityManagerFactory emf;</p>
<p>public List&lt;States&gt; getStates() {<br />
return emf.createEntityManager().createNamedQuery(&#8221;States.findAll&#8221;).getResultList();<br />
}<br />
}</td>
</tr>
</tbody>
</table>
<p>Here are the main characterisitcs of this class:</p>
<ol>
<li>This is a POJO class with @ManagedBean annotation. This annotation makes this class a <span style="font-style: italic;">managed bean</span> that can be used in the JSF pages. As no other annotations or parameters are specified, this is a request-scoped managed bean with the name &#8220;stateList&#8221; and lazily initialized. More details about this annotation are available in the <a href="https://javaserverfaces.dev.java.net/nonav/docs/2.0/managed-bean-javadocs/index.html">javadocs</a>.</li>
<li>The persistence unit created in <a href="http://blogs.sun.com/arungupta/entry/totd_93_getting_started_with">TOTD #93</a> is injected using @PersistenceUnit annotation.</li>
<li>The POJO has one getter method that queries the database and return the list of all the states.</li>
</ol>
</li>
<li>In the generated file &#8220;template-client.xhtml&#8221;, change the &#8220;head&#8221; template to:<br />
<table style="text-align: left; background-color: #ccccff; width: 100%;" border="0" cellspacing="2" cellpadding="2">
<tbody>
<tr>
<td>Show States<br />
<span style="font-weight: bold;"> </span></td>
</tr>
</tbody>
</table>
<p>and &#8220;body&#8221; template to:</p>
<table style="text-align: left; background-color: #ccccff; width: 100%;" border="0" cellspacing="2" cellpadding="2">
<tbody>
<tr>
<td>&lt;h:dataTable var=&#8221;state&#8221; value=&#8221;#{stateList.states}&#8221; border=&#8221;1&#8243;&gt;<br />
&lt;h:column&gt;&lt;h:outputText value=&#8221;#{state.abbrev}&#8221;/&gt;&lt;/h:column&gt;<br />
&lt;h:column&gt;&lt;h:outputText value=&#8221;#{state.name}&#8221;/&gt;&lt;/h:column&gt;<br />
&lt;/h:dataTable&gt;<br />
<span style="font-weight: bold;"> </span></td>
</tr>
</tbody>
</table>
</li>
<p>This uses the standard JSF &#8220;dataTable&#8221;, &#8220;column&#8221;, and &#8220;outputText&#8221; tags and uses the <span style="font-style: italic;">value expression</span> to fetch the values from the <span style="font-style: italic;">managed bean</span>.</ol>
<p>If the application is already running from <a href="http://blogs.sun.com/arungupta/entry/totd_93_getting_started_with">TOTD #93</a>, then <span style="font-style: italic;">Deploy-on-Save</span> would have automatically deployed the entire application. Otherwise right-click on the project and select Run (default shortcut &#8220;F6&#8243;). The results can be seen at &#8220;http://localhost:8080/HelloEclipseLink/forwardToJSF.jsp&#8221; or &#8220;http://localhost:8080/HelloEclipseLink/faces/template-client.xhtml&#8221; and looks like:</p>
<p><img style="border: 1px solid; width: 531px; height: 539px;" src="/wp-content/uploads/2009/08/nb68m1-jee6-jsf2-output.png" alt="" /></p>
<p>The updated directory structure looks like:</p>
<p><img style="border: 1px solid; width: 300px; height: 383px;" src="/wp-content/uploads/2009/08/nb68m1-jee6-jsf2-dir-structure.png" alt="" /></p>
<p>There were multiple files added by the JSF framework support in NetBeans. But as I said earlier, they will be cleaned up before the final release.</p>
<p>Also refer to other <a href="http://blogs.sun.com/arungupta/tags/javaee6">Java EE 6 blog entries</a>.</p>
<p>Please leave suggestions on other TOTD that you&#8217;d like to see. A complete archive of all the tips is available <a href="/?tag=totd">here</a>.</p>
<p><small>Technorati: <a href="http://technorati.com/tags/totd">totd</a> <a href="http://technorati.com/tags/glassfish">glassfish</a> <a href="http://technorati.com/tags/v3">v3</a> <a href="http://technorati.com/tags/mysql">mysql</a> <a href="http://technorati.com/tags/javaee6">javaee6</a> <a href="http://technorati.com/tags/javaserverfaces">javaserverfaces</a> <a href="http://technorati.com/tags/jpa2">jpa2</a> <a href="http://technorati.com/tags/netbeans">netbeans</a></small></p>


<p>Related posts:<ol><li><a href='/2009/08/totd-95-ejb-3-1-java-server-faces-2-0-jpa-2-0-web-application-getting-started-with-java-ee-6-using-netbeans-6-8-m1-glassfish-v3/' rel='bookmark' title='Permanent Link: TOTD #95: EJB 3.1 + Java Server Faces 2.0 + JPA 2.0 web application &#8211; Getting Started with Java EE 6 using NetBeans 6.8 M1 &#038; GlassFish v3'>TOTD #95: EJB 3.1 + Java Server Faces 2.0 + JPA 2.0 web application &#8211; Getting Started with Java EE 6 using NetBeans 6.8 M1 &#038; GlassFish v3</a></li><li><a href='/2009/08/totd-93-getting-started-with-java-ee-6-using-netbeans-6-8-m1-glassfish-v3-a-simple-servlet-3-0-jpa-2-0-app/' rel='bookmark' title='Permanent Link: TOTD #93: Getting Started with Java EE 6 using NetBeans 6.8 M1 &#038; GlassFish v3 &#8211; A simple Servlet 3.0 + JPA 2.0 app'>TOTD #93: Getting Started with Java EE 6 using NetBeans 6.8 M1 &#038; GlassFish v3 &#8211; A simple Servlet 3.0 + JPA 2.0 app</a></li><li><a href='/2008/10/totd-49-converting-a-jsf-1-2-application-to-jsf-2-0-managedbean/' rel='bookmark' title='Permanent Link: TOTD #49: Converting a JSF 1.2 application to JSF 2.0 &#8211; @ManagedBean'>TOTD #49: Converting a JSF 1.2 application to JSF 2.0 &#8211; @ManagedBean</a></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.arungupta.me/2009/08/totd-94-a-simple-java-server-faces-2-0-jpa-2-0-application-getting-started-with-java-ee-6-using-netbeans-6-8-m1-glassfish-v3/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
