1

I need to put allow origin in my Jersery Project. m getting error:- access-control-allow-origin-issue-in-angular-2 Where should I need to put.

@GET
@Produces("application/json")
public Response getLipid() {
    LipidDAO dao = new LipidDAO();
    List lipid = dao.getLipid();
    String json = new Gson().toJson(lipid);
    return Response.ok().entity(json.toString()).build();
}
Lumpy Wizard
  • 143
  • 1
  • 5
mehul
  • 109
  • 3
  • 12

1 Answers1

0

You can tack it on as a header after the Response.ok()

return Response.ok()
    .entity(json.toString())
    .header("Access-Control-Allow-Origin", "*")
    .header("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT")
    .build();

Or do it in an implementation of ContainerResponseFilter and register that filter to your application.

Probably don't want to leave it as * unless you want user's browsers from other sites accessing your API though.

Lumpy Wizard
  • 143
  • 1
  • 5
  • I have Tried it but its not working for me..Anything i have to add (cross allow origin) in angular 2 header part ? – mehul Jun 07 '17 at 19:52