Connect to JBoss AS RESTful web services

Good. So now we will replace the static XML file with some data produced by a RESTful web service.
Here's a simple Web service which produces a collection of items:

package sample;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;

@Path("rest")

public class SampleREST {
 
 @GET
 @Path("itemArray")
 @Produces({"application/xml"})
 public Item[]  getItem() {
 Item item[] = new Item[6];
 item[0] = new Item("a1","computer",2500,45);
 item[1] = new Item("b1","monitor",500,25);
 item[2] = new Item("c1","chair",1500,15);
 item[3] = new Item("d1","keyboard",50,45);
 item[4] = new Item("e1","mouse",25,45);
 item[5] = new Item("f1","phone",250,70);
 

 return item;
 }  

}

This is the Item object class:

package sample;

import java.io.Serializable;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement
public class Item implements Serializable {

 @XmlElement
 String name;
 @XmlElement
 int price;
 @XmlElement
 int quantity;
 @XmlElement
 String id;

 public Item(String id, String name, int price, int quantity) {
 this.id = id;
 this.quantity = quantity;
 this.name = name;
 this.price = price;
 }

 public Item() {

 }
}

Ok. Now the only thing you need to change is the setDataURL method in ItemDS


setDataURL("http://localhost:8080/WebApp/rest/itemArray");  

It's time to export your war to JBoss AS. use the Eclipse Export functionality to export as archive file (f.e. example.war):


gwt google web toolkit jboss tutorial

Be careful to export only the selected directory of the war file, otherwise the Export Utility will not create a compliant war file.

If everything works correctly by pointing to your html page, you should see data displayed just like we did for static files: http://localhost:8080/example/Example.html

 

Enjoy Google Web Toolkit and JBoss !

0
0
0
s2smodern