This question is asked here but still, I could not able to find my answer in those and I believe I have done all my research,
a. Things what I have done so far:
I have tried .share Link for the Same
I have tried to check whether it's a preflight request and found this in my network tab:
there is 2 OPTION call and 2 GET call is going . So, we can be sure that its not PREFLIGHT request.
Now comming towards my coding part:
Component
------------
constructor(
private _notificationService: NotificationService) {
this.getNotification();
}
getNotification() {
this._notificationService.getNotifications().subscribe(notifications => {
this.notificationList = notifications;
});
}
Service:
-------------
constructor(private http: Http,private config: Configuration) { }
getNotifications() {
const headers = new Headers({
'c-t-tenant': 'TENANT NAME',
'c-t-apitoken': 'TOKEN-NAME',
'Content-Type': 'application/json',
});
return this.http.get(this.config.notificationApiUrl, { headers: headers })
.map((res: Response) => res.json());
}
I am very much sure that this api is not getting called from somewhere else. If somebody stucked in this kind of situation please help me here.
My backend is in Spring Boot and i have implemented CORS filter also:
package com.bosch.cb.dashboard.auth;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Component;
@Component
public class SimpleCORSFilter implements Filter {
public SimpleCORSFilter() {
System.out.println("SimpleCORSFilter init");
}
@Override
public void init(FilterConfig filterConfig) throws ServletException {
}
@Override
public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain)
throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest) req;
HttpServletResponse response = (HttpServletResponse) resp;
response.setHeader("Access-Control-Allow-Origin", "*");
response.setHeader("Access-Control-Allow-Credentials", "true");
response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE");
response.setHeader("Access-Control-Max-Age", "3600");
response.setHeader("Access-Control-Allow-Headers", "Access-Control-Allow-Headers, Pragma, Origin,Accept, b-h-apitoken ,X-Requested-With, Content-Type, Access-Control-Request-Method, Access-Control-Request-Headers, Authorization");
chain.doFilter(request, response);
}
@Override
public void destroy() {
}
}