ejemplo de código rápida:
1) Añadir el javax.ws.rs dependencia en su pom (si se utiliza Maven) o descargarlo.
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>jsr311-api</artifactId>
<version>1.1.1</version>
</dependency>
2) Cree una clase vacía para definir la ruta de su servicio; por ejemplo para audición a application/service/rest
sería
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;
@ApplicationPath("/service/rest")
public class WebConfig extends Application {
}
3) Crear el controlador de la API. Por ejemplo si necesitamos estas llamadas: application/service/rest/resource/{id}
un código simple sería:
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
@Path("resource/{id}")
public class ApiController {
/**
* Call: <code>/service/rest/resource/23</code>
* @return HTTP Response
*/
@GET
public Response getResource(@PathParam("id") String anId) {
Resource myResource = whatever.get(anId);
return Response.status(Status.OK).entity(myResource).build();
}
4) Si queremos especificar una respuesta JSON asegurarse de que tiene los captadores para el recurso y el tipo:
@GET
@Produces("application/json")
public Response getResource(@PathParam("id") String anId) {
// the same
}
Si he entendido bien, trate de [esta] enlace (http://blogs.oracle.com/enterprisetechtips/entry/consuming_restful_web_services_with) –