I'm trying to create a restful service in my Java Application. So far i got a POJO, a Entitymanagement Class, a "Wrapper" and a Class to access the Data via Rest. I'm using a wildfly 10 and didn't add any dependencies (except for the hibernate).
POJO
import java.sql.Date;
import java.util.List;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.OneToOne;;
@Entity
public class Event {
private static final long serialVersionUID = 2L;
@Id
@GeneratedValue
private int id;
private Date eventDate;
private double price;
@ManyToMany(fetch = FetchType.LAZY)
private List<Visitor> visitors;
@OneToOne
private Organisation orga;
private String name;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public Organisation getOrga() {
return orga;
}
public void setOrga(Organisation orga) {
this.orga = orga;
}
public Date getEventDate() {
return eventDate;
}
public void setEventDate(Date eventDate) {
this.eventDate = eventDate;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public List<Visitor> getVisitors() {
return visitors;
}
public void setVisitors(List<Visitor> visitors) {
this.visitors = visitors;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
Entity Management
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;
import lele.core.entities.Event;
import lele.core.entities.Organisation;
@Stateless
public class Loader {
@PersistenceContext
private EntityManager em;
public List<Event> getAllEvents()
{
TypedQuery<Event> query = em.createQuery("select e from Event e", Event.class);
return query.getResultList();
}
Wrapper
import java.util.List;
import javax.xml.bind.annotation.XmlRootElement;
import lele.core.entities.Event;
@XmlRootElement(name="events")
public class EventWrapper {
private List<Event> list;
public EventWrapper() {
}
public List<Event> getList() {
return list;
}
public void setList(List<Event> list) {
this.list = list;
}
}
API- Class
@Path("/appmgr")
@Consumes({ "application/json" })
@Produces({ "application/json" })
public class Appmgr {
@EJB
private Loader ld;
@EJB
private Saver sv;
@GET
@Path("events")
@Produces("application/json")
public Response getEvents() {
EventWrapper wrapper = new EventWrapper();
wrapper.setList(ld.getAllEvents());
return Response.status(200).entity(wrapper).build();
}
Am I missing something? Any help would be apreciated since it's my first time working on a Restful service.
Maybe it's a configuration Error...?
Edit: