I made a java webservice with Jersey and Javax.ws.rs, and at my controller a made a method that returns a list of json objects. This is the method >
@Path("chamados")
public class ChamadoController {
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/")
public List<Chamado> listChamados(){
Chamado c1 = new Chamado();
c1.setId(50);
c1.setAssunto("assunto1");
c1.setMensagem("oi");
c1.setStatus(Status.NOVO);
Chamado c2 = new Chamado();
c2.setId(20);
c2.setAssunto("assunto2");
c2.setMensagem("oi2");
c2.setStatus(Status.FECHADO);
List<Chamado> list1 = new ArrayList<Chamado>();
list1.add(c1);
list1.add(c2);
return list1;
}
}
The output when I run the project with apache and access /rest/chamados/ is this >
[{"id":50,"assunto":"assunto1","mensagem":"oi","status":"NOVO"},
{"id":20,"assunto":"assunto2","mensagem":"oi2","status":"FECHADO"}]
My issue is when i try to print it at my angular4 project, i never done this before so im kinda lost, this how im tryng to print it >
export class AppComponent{
data: any = {};
constructor(private http: Http){
this.getData();
this.getImages();
}
getData(){
return this.http.get(this.apiURI).map((res: Response) => res.json())
}
getImages(){
this.getData().subscribe(data => {
console.log(data);
})
}
private apiURI = 'http://localhost:8080/aprendendo-java-backend/rest/chamados/';
}
This is the error I get when trying to console.log >
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost:8080/aprendendo-java-backend/rest/chamados/. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing).
Any tips on whats wrong or how should I be doing this?
Thanks in advance