I have a project maven - EAR, in the same i have a RESTful JAX-RS that work with jersey and it is consuming with JSON, when I try get list to RESTful since EJB, bring not nothing. However when add list in the same REST it works well.!
this is the RESTful with list in the same class!.
@Path("/courseMockRS")
@Consumes({"application/json"})
@Produces({"application/json"})
public class CourseMock_RS {
@GET
@Path("/all_courses")
public List<CourseMock> AllCourses() {
List<CourseMock> courses = getCoursesMock();
return courses;
}
public List<CourseMock> getCoursesMock() {
List<CourseMock> coursesMocks = new ArrayList<CourseMock>();
CourseMock mock = new CourseMock();
mock.setName("SOA Analist");
mock.setAuthor("SOA Education");
mock.setReleaseDate("16/07/2015");
coursesMocks.add(mock);
mock = new CourseMock();
mock.setName("SOA Architect");
mock.setAuthor("SOA ET");
mock.setReleaseDate("16/07/2015");
coursesMocks.add(mock);
mock = new CourseMock();
mock.setName("SOA Consultant");
mock.setAuthor("SOA ET");
mock.setReleaseDate("16/07/2015");
coursesMocks.add(mock);
return coursesMocks;
}
}
Thus it works well!
[{"name":"SOA Analist","author":"SOA Education","releaseDate":"16/07/2015"},
{"name":"SOA Architect","author":"SOA ET","releaseDate":"16/07/2015"},
{"name":"SOA Consultant","author":"SOA ET","releaseDate":"16/07/2015"}]
But when implement EJB not found!, However the application it is deployed and the Stateless resource is accepted.
This is the resources from EJB.
DTO
public class CourseMock {
private String name;
private String author;
private String releaseDate;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public String getReleaseDate() {
return releaseDate;
}
public void setReleaseDate(String releaseDate) {
this.releaseDate = releaseDate;
}
}
Facade
@Stateless
@LocalBean
public class CourseFacadeMock implements ICourseMockFacade{
private CourseMock mock;
@Override
public List<CourseMock> getCoursesMock() {
List <CourseMock> coursesMocks = new ArrayList<CourseMock>();
mock= new CourseMock();
mock.setName("Analista SOA");
mock.setAuthor("SOA Education");
mock.setReleaseDate("16/07/2015");
coursesMocks.add(mock);
mock= new CourseMock();
mock.setName("SOA Analist");
mock.setAuthor("SOA Education");
mock.setReleaseDate("16/07/2015");
coursesMocks.add(mock);
mock = new CourseMock();
mock.setName("SOA Architect");
mock.setAuthor("SOA ET");
mock.setReleaseDate("16/07/2015");
coursesMocks.add(mock);
mock = new CourseMock();
mock.setName("SOA Consultant");
mock.setAuthor("SOA ET");
mock.setReleaseDate("16/07/2015");
coursesMocks.add(mock);
return coursesMocks;
}
}
Interface Facade
@Local
public interface ICourseMockFacade {
public List<CourseMock> getCoursesMock();
}
And the RESTful
@Path("/courseMockRS")
@Consumes({"application/json"})
@Produces({"application/json"})
public class CourseMock_RS {
@EJB
ICourseMockFacade courseMockFacade;
@GET
@Path("/all_courses")
public List<CourseMock> AllCourses() {
List<CourseMock> courses = courseMockFacade.getCoursesMock();
return courses;
}
}
Thus fails.. The Exception is NUllPointerException. Help, please!.