<?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>Andy Gibson &#187; Glassfish</title>
	<atom:link href="http://www.andygibson.net/blog/tag/glassfish/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.andygibson.net/blog</link>
	<description>Open Source Projects &#38; Technical Writings</description>
	<lastBuildDate>Thu, 02 Feb 2012 14:33:32 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language></language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Simple RESTful services in Glassfish Pt 2</title>
		<link>http://www.andygibson.net/blog/tutorial/simple-restful-services-in-glassfish-pt-2/</link>
		<comments>http://www.andygibson.net/blog/tutorial/simple-restful-services-in-glassfish-pt-2/#comments</comments>
		<pubDate>Mon, 21 Mar 2011 12:39:13 +0000</pubDate>
		<dc:creator>Andy Gibson</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[CDI]]></category>
		<category><![CDATA[Glassfish]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Java EE]]></category>
		<category><![CDATA[JEE]]></category>
		<category><![CDATA[Journeyman]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[Web Services]]></category>

		<guid isPermaLink="false">http://www.andygibson.net/blog/?p=1765</guid>
		<description><![CDATA[In part 2 of this article, we are going to create a data driven web service that will return JSON and XML to the client, and then use jQuery to add a new item to the database and display it in our page. In part 1, we looked at creating simple web services and now [...]]]></description>
			<content:encoded><![CDATA[<p>In part 2 of this article, we are going to create a data driven web service that will return JSON and XML to the client, and then use jQuery to add a new item to the database and display it in our page.<br />
<span id="more-1765"></span><br />
In part 1, we looked at creating simple web services and now we&#8217;re going to look at making something more practical and interesting. We&#8217;ll start from where we left off with the source code as it was at the end of the part 1 which you can download from here (<a href="http://www.andygibson.net/blog/wp-content/uploads/2011/02/restwebdemo_pt1.zip">restwebdemo_pt1</a>) if you want to follow along. If not, the final source can be downloaded from here (<a href='http://www.andygibson.net/blog/wp-content/uploads/2011/03/restwebdemo_pt2.zip'>restwebdemo_pt2</a>).</p>
<ol>
<li>First off, we&#8217;re going to change the entity manager that is available for injection to be request scoped. To do this, open up <code>DataRepositoryProducer.java</code> and change the <code>@ConversationScoped</code> annotation on the <code>getEntityManager()</code> method to be <code>@RequestScoped</code>.  The reason for this is documented here in <a href="http://www.andygibson.net/blog/article/a-little-less-conversation/">A Little Less Conversation</a>.</li>
<li>Next we are going to create a simple dao for Course objects, and the only reason to do this is to demonstrate the integration of CDI and the ability to layer your code. Create a new class called <code>CourseDao</code> with the following code.
<pre class="brush: java;">
package org.fluttercode.restwebdemo.bean;

@Stateless
@LocalBean
public class CourseDao {

	@Inject @DataRepository
	private EntityManager entityManager;

	public void save(Course course) {
		entityManager.persist(course);
	}

	public Course update(Course course) {
		return entityManager.merge(course);
	}

	public Course find(Long id) {
		return entityManager.find(Course.class, id);
	}
}
</pre>
<p>This just injects an entityManager and uses it to locate, save and update Course objects.
</li>
<li>Now create a new <code>CourseService</code> bean that will handle the web services. To start with we want to make it a stateless EJB and inject the course Dao. We are going start by re-implementing the method to return the course name for the given id.
<pre class="brush: java;">
	@Path(&quot;courseName/{id}&quot;)
	@GET
	public String getCourseName(@PathParam(&quot;id&quot;) Long id) {
		Course course = courseDao.find(id);
		if (course == null) {
			return &quot;Course not found&quot;;
		} else {
			return course.getTitle();
		}
	}
</pre>
</ol>
<p>To see this method in action, deploy the application and go to <a href="http://localhost:8080/restwebdemo/rest/course/courseName/126">http://localhost:8080/restwebdemo/rest/course/courseName/126</a>. Now we know everything is working and hooked up together, we can look at adding some new functionality. </p>
<p>Let&#8217;s start by returning a course with a given id from the service. This is fairly simple given what we already know. The only thing to determine now is what format to return the object as and to convert it to that type. Luckily, Java EE already provides JAXB which can take an object graph and convert it to XML for us as long as we annotate the classes with the annotations to let the JAXB implementation know how to convert it. The same annotations can be used by the body writer that handles JSON.</p>
<p>First we&#8217;ll annotate the <code>Course</code> class and make a couple of changes that we need to. Next we&#8217;ll create methods to return a <code>Cource</code> object from the service in XML or JSON format.</p>
<ol>
<li>Open the <code>Course</code> class and add the following annotations to the class. </p>
<pre class="brush: java;">
@Entity
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class Course extends BaseEntity {
   ...
   ...
}
</pre>
<p>This tells the JAXB processor that this class can be serialized and to access the values using fields in the class. This also means that any other annotations we want to add to control the serialization needs to be applied to the fields.
</li>
<p>This is a simple example, so we don&#8217;t want to serialize the <code>teacher</code> or <code>enrolled</code> properties which we can do by marking them with the <code>@XmlTransient</code> attributes. Also, remove the <code>@NotNull</code> annotation from the <code>teacher</code> attribute as we will need it blank later. The following code shows the fields with both the JAXB and JPA annotations. JAXB (like JPA) uses default conventions for fields that don&#8217;t have annotations : </p>
<pre class="brush: java;">
	@Column(length = 32, nullable = false)
	@Size(max = 32)
	@NotEmpty(message = &quot;title is required&quot;)
	private String title;

	@Column(length = 8, nullable = false)
	@Size(max = 8  )
	@NotEmpty(message = &quot;code is required&quot;)
	private String code;

	@ManyToOne(fetch = FetchType.LAZY)
	@XmlTransient
	private Teacher teacher;

	@ManyToMany(mappedBy = &quot;enrolled&quot;)
	@XmlTransient
	private List&lt;Student&gt; students = new ArrayList&lt;Student&gt;();
</pre>
<p>We are just using a simple JAXB model for the sake of the example which is why we aren&#8217;t including the <code>Teacher</code> and <code>Student</code> classes.
</li>
<li>Now in our <code>CourseService</code> class we will create methods to return the course entity and we will create one for JSON and one for XML.
<pre class="brush: java;">
	@Path(&quot;find/{id}/xml&quot;)
	@GET
	@Produces(MediaType.APPLICATION_XML)
	public Course getCourseAsXml(@PathParam(&quot;id&quot;) Long id) {
		return courseDao.find(id);
	}

	@Path(&quot;find/{id}/json&quot;)
	@GET
	@Produces(MediaType.APPLICATION_JSON)
	public Course getCourseAsJson(@PathParam(&quot;id&quot;) Long id) {
		return courseDao.find(id);
	}
</pre>
</li>
<p><small>(note : At this point, I had to switch to using Hibernate as the JPA provider since JAXB didn&#8217;t like the interface EclipseLink used for proxying the properties. You can do this using the Glassfish update tool).</small><br />
If you redeploy the application and browse to <a href="http://localhost:8080/restwebdemo/rest/course/find/1/json">http://localhost:8080/restwebdemo/rest/course/find/1/json</a> you should be prompted to save a file, or it will display the text, but the content should be something like : </p>
<pre class="brush: plain;">
{&quot;createdOn&quot;:&quot;2010-08-27T16:36:57.015-04:00&quot;,
  &quot;id&quot;:&quot;1&quot;,
  &quot;modifiedOn&quot;:&quot;2010-08-27T16:36:57.015-04:00&quot;,
  &quot;title&quot;:&quot;Computing for Beginners&quot;,
   &quot;code&quot;:&quot;CS101&quot;}
</pre>
<p>or if you go to <a href="http://localhost:8080/restwebdemo/rest/course/find/1/xml">http://localhost:8080/restwebdemo/rest/course/find/1/xml</a> you will get an XML version :</p>
<pre class="brush: xml;">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;yes&quot;?&gt;
&lt;course&gt;
	&lt;createdOn&gt;2010-08-27T16:36:57.015-04:00&lt;/createdOn&gt;
	&lt;id&gt;1&lt;/id&gt;
	&lt;modifiedOn&gt;2010-08-27T16:36:57.015-04:00&lt;/modifiedOn&gt;
	&lt;title&gt;Computing for Beginners&lt;/title&gt;
	&lt;code&gt;CS101&lt;/code&gt;
&lt;/course&gt;
</pre>
<p>Now we can grab objects from our web service, we should look at creating objects from the service. We add a new method that takes the title and code values, creates a new <code>Course</code> with those values and saves it using the <code>courseDao</code>.</p>
<pre class="brush: java;">
	@Path(&quot;create&quot;)
	@PUT
	@Produces(MediaType.APPLICATION_JSON)
	public Course createCourse(@FormParam(&quot;title&quot;) String title,@FormParam(&quot;code&quot;) String code) {
		Course course = new Course();
		course.setTitle(title);
		course.setCode(code);
		courseDao.save(course);
		return course;
	}
</pre>
<p>Here I&#8217;ve used the <code>FormParam</code> annotations to plug form values into the method call. You&#8217;ll notice that using REST conventions, the method to create a course uses the PUT type of request. Now let&#8217;s create a page to enter a title and code and create the course. Notice that our method returns the created course so we can return the course back to the user. This is probably not ideal, but suits for the purposes of demonstration. Now lets create a new HTML page to allow for data entry and calling the web service to create the Course.</p>
<pre class="brush: xml;">
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Insert title here&lt;/title&gt;
&lt;script type=&quot;text/javascript&quot;
	src=&quot;http://localhost:8080/restwebdemo/jquery-1.4.min.js&quot;&gt;
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;div id=&quot;message&quot;
	style=&quot;display: none; background: #d0d0f0; padding: 12px&quot;&gt;Message Div&lt;/div&gt;
&lt;form action=&quot;rest/course/create&quot; method=&quot;POST&quot;&gt;

    &lt;fieldset&gt;
    	&lt;legend&gt;Create Course&lt;/legend&gt;
    	&lt;p&gt;
	        Title&lt;br /&gt;
    	    &lt;input id=&quot;title&quot; /&gt;&lt;br /&gt;
    	&lt;/p&gt;
    	&lt;p&gt;
        	Code&lt;br /&gt;
        	&lt;input id=&quot;code&quot; /&gt;&lt;br /&gt;
    	&lt;/p&gt;
    	&lt;input type=&quot;submit&quot; id=&quot;submit&quot; /&gt;
	&lt;/fieldset&gt;
&lt;/form&gt;
&lt;/body&gt;

&lt;script type=&quot;text/javascript&quot;&gt;

//jquery pieces
$(document).ready(function() {

    //change the submit button behaviouus.
    $('#submit').click(function () {
		var title = $(&quot;input#title&quot;).val();
		var code = $(&quot;input#code&quot;).val();

		params = &quot;title=&quot;+title+&quot;&amp;code=&quot;+code;
		//alert(&quot;posting form : &quot;+data);
        $.ajax({
               type: &quot;PUT&quot;,
               url: &quot;rest/course/create&quot;,
               data: params,
               success: function(result) {
        		   showMessage(&quot;Created Course &quot;+result.title+&quot; with id &quot;+result.id+&quot; on &quot;+result.createdOn);
               }
        });
		return false;
    });
});

function showMessage(msg) {
	  $('#message').html(msg);
	  $('#message').fadeIn('fast');
	   $('#message').delay(3000).fadeOut('slow');
}
&lt;/script&gt;
&lt;/html&gt;
</pre>
<p>This looks a lot code, but not really. We import jquery to help us post our form, and we create our form with the two fields. We use JQuery to add an event handler so when you click submit, it packages up the form, calls our web service with a PUT type of request and grabs the returned object as a JSON object, and displays a message using the values from the new instance obtained from the server. To verify that your course has been created, go to the <a href="http://localhost:8080/restwebdemo/home.jsf">front page</a> and you should see it listed.</p>
<p>That about wraps it up for this post, the source code can be downloaded from (<a href='http://www.andygibson.net/blog/wp-content/uploads/2011/03/restwebdemo_pt2.zip'>restwebdemo_pt2</a>), just unzip it, use <code>mvn clean package</code> and deploy the war to glassfish and use the URLs mentioned in the article.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.andygibson.net/blog/tutorial/simple-restful-services-in-glassfish-pt-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Simple RESTful web services with Glassfish</title>
		<link>http://www.andygibson.net/blog/article/simple-restful-web-services-with-glassfish/</link>
		<comments>http://www.andygibson.net/blog/article/simple-restful-web-services-with-glassfish/#comments</comments>
		<pubDate>Thu, 03 Feb 2011 13:44:52 +0000</pubDate>
		<dc:creator>Andy Gibson</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Glassfish]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[Web Services]]></category>

		<guid isPermaLink="false">http://www.andygibson.net/blog/?p=1723</guid>
		<description><![CDATA[Here&#8217;s a quick guide to creating a RESTful web service with Glassfish using JAX-RS. First create a new maven project called restwebdemo using the jee6-sandbox-archetype so we have a model and some data to work with. To get this working with Glassfish, open the persistence.xml file and change the jta-data-source name to jdbc/__default. Also, make [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a quick guide to creating a RESTful web service with Glassfish using JAX-RS.<br />
<span id="more-1723"></span><br />
First create a new maven project called <code>restwebdemo</code> using the jee6-sandbox-archetype so we have a model and some data to work with. To get this working with Glassfish, open the <code>persistence.xml</code> file and change the <code>jta-data-source</code> name to <code>jdbc/__default</code>. Also, make sure that the javaDB is up and running by going to <code>$glassfish_dir/bin</code> and typing <code>asadmin start-database</code>. Verify that the application is working correctly by going to <a href="http://localhost:8080/restwebdemo/">http://localhost:8080/restwebdemo/</a> and you should get a list of courses.</p>
<p>Before we start getting to the interesting stuff, we have one more boring piece of configuration to perform specific to web services. We need to add the jersey servlet container to our <code>web.xml</code> file:</p>
<pre class="brush: xml;">
&lt;servlet&gt;
	&lt;servlet-name&gt;Jersey Web Application&lt;/servlet-name&gt;
	&lt;servlet-class&gt;com.sun.jersey.spi.container.servlet.ServletContainer&lt;/servlet-class&gt;
	&lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
&lt;/servlet&gt;
&lt;servlet-mapping&gt;
	&lt;servlet-name&gt;Jersey Web Application&lt;/servlet-name&gt;
	&lt;url-pattern&gt;/rest/*&lt;/url-pattern&gt;
&lt;/servlet-mapping&gt;
</pre>
<p>This also tells Jersey to handle urls starting with <code>/rest</code> and pass it along to our web service methods.</p>
<p>Now we can dive right in an create a new server bean that will respond to requests for web services. For now we&#8217;ll just return a simple message from a POJO.</p>
<pre class="brush: java;">
@Path(&quot;sample&quot;)
public class SimpleService {

	@Path(&quot;greet&quot;)
	@GET
	public String doGreet() {
		return &quot;Hello Stranger, the time is &quot;+ new Date();
	}
}
</pre>
<p>The path annotation on the class indicates that this is a root resource class and the path value given specifies the base URI for all the web service methods contained in the class.<br />
On the <code>doGreet</code> method we have <code>@Path</code> which is used to specify the path template this method should match. The <code>@GET</code> annotation is used to differentiate between a sub-resource method that handles the actual web service request and a sub-resource locator method that returns an object that will instead be used to handle the request. In this case, the method has the <code>@GET</code> annotation which means this method handles the request and returns the result.<br />
If you navigate to <a href="http://localhost:8080/restwebdemo/rest/sample/greet/">http://localhost:8080/restwebdemo/rest/sample/greet/</a> you should see a welcome message with the current date and time.</p>
<p>Now we&#8217;ll look at adding parameterized web services that extracts parameters from the request URL and uses them to form the output. Add the following method to the web service class :</p>
<pre class="brush: java;">
@Path(&quot;sayHello/{name}&quot;)
@GET
public String doSayHello(@PathParam(&quot;name&quot;) String name) {
	return &quot;Hello there &quot;+name;
}
</pre>
<p>Again we have the path annotation to indicate what URLs this method will match, and this time we have have <code>{name}</code> added to the URL. This lets us extract a part of the url and give it a name. This name is used in the <code>@PathParam</code> annotation in the method signature to assign the URL fragment to the name parameter . To test our new method, redeploy the application and go to the URL  <a href="http://localhost:8080/restwebdemo/rest/sample/sayHello/Andy">http://localhost:8080/restwebdemo/rest/sample/sayHello/Andy</a> to get the response  <code>Hello there Andy</code></p>
<p>We can also use request parameters to provide values to the method by using the <code>@QueryParam</code> annotation. We&#8217;ll create another method that is similar but uses a query parameter instead.</p>
<pre class="brush: java;">
@Path(&quot;sayHello&quot;)
@GET
public String doSayHelloWithRequestParam(@QueryParam(&quot;name&quot;) String name) {
	return &quot;Hi there &quot;+name;
}
</pre>
<p>This time, the URL to use is <a href="http://localhost:8080/restwebdemo/rest/sample/sayHello?name=Andy">http://localhost:8080/restwebdemo/rest/sample/sayHello?name=Andy</a> to get the same message.</p>
<p>To make things more interesting, lets add a new page that lets us enter a name in a form and submit it to the web service.  Add a new page called <code>form.html</code> with the following content : </p>
<pre class="brush: xml;">
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Insert title here&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;form action=&quot;rest/sample/sayHello&quot; method=&quot;GET&quot;&gt;
Name &lt;input id=&quot;name&quot; name=&quot;name&quot;/&gt; &lt;input type=&quot;submit&quot; /&gt;
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>Go to this page at <a href="http://localhost:8080/restwebdemo/form.html">http://localhost:8080/restwebdemo/form.html</a>, enter your name and click submit and you should be greeted by name in the next page.</p>
<p>Notice that we had to set the form method to <code>GET</code> because our web service is only set up to respond to GET requests. If we change the form method to POST we can get the following error message : </p>
<pre class="brush: plain;">
HTTP Status 405 - Method Not Allowed
type Status report
message Method Not Allowed
description The specified HTTP method is not allowed for the requested resource (Method Not Allowed).</pre>
<p>Remember, with REST, those actual verbs have meaning and adds meaning to the request so it is strict on how it matches the method to be called.</p>
<p>To solve this problem, we can add a new method to handle form POSTs like so :</p>
<pre class="brush: java;">
@Path(&quot;sayHello&quot;)
@POST
public String doSayHelloWithFormParam(@FormParam(&quot;name&quot;) String name) {
	return &quot;Hi there &quot; + name;
}
</pre>
<p>Here we changed the <code>@GET</code> to a <code>@POST</code> to allow the different verb and changed the annotation on the <code>name</code> method parameter to <code>@FormParam</code>. The path remains the same because we can have service methods that match the same path, but for different request verbs. We can even have the same verb and path as long as the content type returned is different. The content type is used to specify the type of output the is returned from the method. It is set by adding a <code>@javax.ws.rs.Produces</code> (not to be confused with the CDI <code>Produces</code> annotation).  The annotation takes a string parameter that indicates the type of media returned from the method. Common media types are defined as constants in the <code>MediaType</code> class so you can use :</p>
<pre class="brush: java;">
@Path(&quot;sayHello&quot;)
@POST
@Produces(MediaType.APPLICATION_XML)
public String doSayHelloWithFormParam(@FormParam(&quot;name&quot;) String name) {
	return &quot;&lt;message&gt;Hi there &quot; + name+&quot;&lt;/message&gt;&quot;;
}
</pre>
<p>If you run your form again, and post it, you will get an xml response as follows : </p>
<pre class="brush: xml;">
&lt;message&gt;Hi there Andy&lt;/message&gt;
</pre>
<p>Depending on your browser, if you return just the text, you will get an error because the plain text isn&#8217;t valid XML and the browser expects XML because that is the response type set on the response from the web service.</p>
<p>To finish up, we are going to do something a little more interesting, we will create a web service to return the name of a course from the database using the sandbox data built into the archetype. For various reasons, we will take the most direct route to getting data access which is to make the web service bean a stateless bean and inject a persistence context using the <code>@PersistenceContext</code> annotation.</p>
<ol>
<li>Add the <code>@Stateless</code> annotation to the <code>SimpleService</code> class and an entity manager field annotated with <code>@PersistenceContext</code> along with the getters and setters.</li>
<li>Add a new method to return the course name for the given course id parameter. We will return it as text for the time being :
<pre class="brush: java;">
@Path(&quot;courseName/{id}&quot;)
@GET
public String getCourseNameFromId(@PathParam(&quot;id&quot;) Long id) {
	Course c = entityManager.find(Course.class, id);
	if (c == null) {
		return &quot;Not Found, try the index &lt;a href='/restwebdemo/'&gt;page&lt;/a&gt; and come back&quot;;
	} else {
		return c.getTitle();
	}
}
</pre>
<p>Note that the automatic type conversion takes place and the value is converted to a <code>Long</code> automatically. If the course is not found, we suggest the user goes to the main page of the demo. We aren&#8217;t just being overly helpful, the test data is generated when you request one of the application pages for the first time. In the current persistence context, when you redeploy, the database is dropped and rebuilt so it will be empty. You need to go to the front page to automatically create the data and then go back to  your page to view the course. An example URL is <a href="http://localhost:8080/restwebdemo/rest/sample/courseName/124">http://localhost:8080/restwebdemo/rest/sample/courseName/124</a>.
</li>
<p>Of course you could grab the course object and build your own XML or JSON response to send back to the client, or use a third party library like Jackson to build the JSON response. However, as we&#8217;ll see next time, Java EE 6 has all these goodies built in for us, and with a few annotations, we&#8217;ll be slinging objects back and forth in no time at all.</p>
<p>You can download the source code for the project from <a href='http://www.andygibson.net/blog/wp-content/uploads/2011/02/restwebdemo_pt1.zip'>here</a>. Simply unzip, build with maven (<code>mvn clean package</code>) and deploy to Glassfish.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.andygibson.net/blog/article/simple-restful-web-services-with-glassfish/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Updating Weld in Glassfish V3</title>
		<link>http://www.andygibson.net/blog/quickbyte/updating-weld-in-glassfish-v3/</link>
		<comments>http://www.andygibson.net/blog/quickbyte/updating-weld-in-glassfish-v3/#comments</comments>
		<pubDate>Tue, 27 Jul 2010 14:08:40 +0000</pubDate>
		<dc:creator>Andy Gibson</dc:creator>
				<category><![CDATA[QuickBytes]]></category>
		<category><![CDATA[CDI]]></category>
		<category><![CDATA[Glassfish]]></category>
		<category><![CDATA[Weld]]></category>

		<guid isPermaLink="false">http://www.andygibson.net/blog/?p=1146</guid>
		<description><![CDATA[(updated : This post refers to Glassfish installations prior to version 3.0.1 which was recently released and includes Weld version 3.0.1. Given the new version, this manual update is not necessary and should not be performed if you have an updated installation of Glassfish 3.0.1+) Even some of the recent versions of Glassfish include a [...]]]></description>
			<content:encoded><![CDATA[<p>(<b>updated</b> : This post refers to Glassfish installations prior to version 3.0.1 which was recently released and includes Weld version 3.0.1. Given the new version, this manual update is not necessary and should not be performed if you have an updated installation of Glassfish 3.0.1+)</p>
<p>Even some of the recent versions of Glassfish include a version of Weld, the reference implementation for CDI (JSR 299), that has some major issues. Since Glassfish uses OSGI, upgrading isn&#8217;t as easy as just replacing the jar with a new one. This tutorial shows you how to upgrade Glassfish to Weld 1.0.1.Final as well as including a pre-built distribution of the two files that need re-deploying.</p>
<p>One of the ways to get around the faulty version of Weld currently in Glassfish is to moving up to Glassfish 3.0.1 nightly builds (<b>update</b> : 3.0.1 has been released and should be used) . A less bleeding edge solution would be to upgrade the version of Weld that is deployed on your current version of Glassfish by updating the <code>weld-integration</code> and <code>weld-osgi-bundle</code> jar files. However, one must be careful of the integration jar version as one of the major interfaces changed after the initial release of Weld introducing incompatibilities.</p>
<p>Updating the OSGI bundle is easy since it can be built from the Weld source code. Just download and compile it and locate the osgi-bundle.jar file.</p>
<p>We also need to grab a new version of the <code>weld-integration.jar</code> file.  There are all sorts of <a href="http://download.java.net/maven/glassfish/org/glassfish/web/weld-integration/">versions</a> of this file, but the one I found working for Weld 1.0.1.final was <a href="http://download.java.net/maven/glassfish/org/glassfish/web/weld-integration/3.0.1-b11/">version 3.0.1-b11/</a>. </p>
<p>I&#8217;ve already built the osgi-bundle and grabbed the integration jar and verified that they work so I&#8217;ve renamed and zipped them so you can just <a href='http://www.andygibson.net/blog/wp-content/uploads/2010/07/Weld-glassfish.zip'>download</a> and unzip them into the <code>modules</code> directory of your Glassfish v3 installation.</p>
<p>This is also a necessary step to get the <a href="http://www.andygibson.net/projects/knappsack">Knappsack Java EE 6 demo project</a> working under Glassfish. You can find more details on the <a href="http://www.andygibson.net/blog/projects/knappsack/deploying-knappsack-projects">server compatability page</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.andygibson.net/blog/quickbyte/updating-weld-in-glassfish-v3/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Java EE 6 Is Here</title>
		<link>http://www.andygibson.net/blog/news/java-ee-6-is-here/</link>
		<comments>http://www.andygibson.net/blog/news/java-ee-6-is-here/#comments</comments>
		<pubDate>Fri, 11 Dec 2009 00:13:19 +0000</pubDate>
		<dc:creator>Andy Gibson</dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[CDI]]></category>
		<category><![CDATA[EJB]]></category>
		<category><![CDATA[Glassfish]]></category>
		<category><![CDATA[JEE]]></category>
		<category><![CDATA[JPA]]></category>
		<category><![CDATA[JSF]]></category>
		<category><![CDATA[Netbeans]]></category>

		<guid isPermaLink="false">http://www.andygibson.net/blog/?p=689</guid>
		<description><![CDATA[Like Christmas come early, Sun announced the release of JEE 6. This release sees continued improvement in the JEE stack with the inclusion of JSR 299, Java Contexts and Dependency Injection (CDI), and EJB 3.1 as well as JSF 2.0, and JPA 2.0. JSF especially has seen changes as a result of practical user feedback [...]]]></description>
			<content:encoded><![CDATA[<p>Like Christmas come early, Sun <a href="http://www.sun.com/aboutsun/pr/2009-12/sunflash.20091210.1.xml">announced</a> the release of JEE 6. This release sees continued improvement in the JEE stack with the inclusion of JSR 299, Java Contexts and Dependency Injection (CDI), and EJB 3.1 as well as JSF 2.0, and JPA 2.0. JSF especially has seen changes as a result of practical user feedback and community add-ons such as Seam and JSF Ajax frameworks which have contributed back to the JCP.</p>
<p>Glassfish v3 which implements the full JEE 6 stack has also been released, with JBoss&#8217; Weld as the CDI implementation. Netbeans 6.8 has also been released with full JEE 6 project support including maven support for enterprise applications. Also of note is the hot deploy function of Glassfish which can deploy your app while maintaining session information.</p>
<p>Personally, I&#8217;m pleased. JEE 6 has really improved things for the java standards, and CDI has filled some gaps that previously required different additional pieces to completely fill. The ghosts of EJB 2.1 should now be permanently laid to rest, but should serve as a stark reminder. Having good frameworks to build standards based solutions is always good for the community.</p>
<p>I&#8217;ll try and get some tutorials on developing with CDI and JSF 2.0 with Netbeans and Glassfish out soon.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.andygibson.net/blog/news/java-ee-6-is-here/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

