Wednesday, August 10, 2011

Using JAXRS and CDI

The following helped me out a lot when setting up jaxrs over existing managed beans.

http://download.oracle.com/javaee/6/tutorial/doc/gkncy.html

Essentially the managed bean is now stateless ejb with jaxrs annotation:

@Stateless
@Named
@Path(value = "/cabins")

the method is also annotated:

@GET
@Produces(MediaType.APPLICATION_JSON)
@Path(value = "/list")

The entity is annotated so it can be marshalled:

@XmlRootElement
public class Cabin extends AbstractEntity {

And a JaxApplication loader class was added:

package com.examples.service;

import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;

@ApplicationPath("/rest")
public class JaxApplicationPath extends Application {
}

With these things in place I can reuse the CabinSearchBean from the web page site as a bean for jaxrs (json or xml) and access via Android.



No comments:

Post a Comment