I am trying to use the built-in Restful WebServices with JBoss AS 7. My web.xml is ..
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5"> </web-app>
My application class ...
package com.robert; import javax.ws.rs.ApplicationPath; import javax.ws.rs.core.Application; import java.util.HashSet; import java.util.Set; @ApplicationPath("/services") public class HelloWorld extends Application { private Set<Object> singletons = new HashSet<Object>(); public HelloWorld() { singletons.add(new Library()); } @Override public Set<Class<?>> getClasses() { Set<Class<?>> classes = new HashSet<Class<?>>(); classes.add(Library.class); return classes;
}
and my class
import javax.ws.rs.*; @Path("/library") public class Library { @GET @Path("/books") public String getBooks() { return "this is all your books"; } @GET @Path("/book/{isbn}") public String getBook(@PathParam("isbn") String id) { // search my database and get a string representation and return it return "Its a good book; I read it"; } @PUT @Path("/book/{isbn}") public void addBook(@PathParam("isbn") String id, @QueryParam("name") String name) { System.out.println("Adding book "+name); } @DELETE @Path("/book/{id}") public void removeBook(@PathParam("id") String id ){ System.out.println("Removing book "+id); }
}
However, when I start JBoss AS7, the WebService never starts. I do not see it on the JBoss control page, and I do not see it in
http:
source share