title: Angular 4- Failed to load URL: Response for preflight is invalid (redirect)
body: <p>I know this question has been asked repeatedly. but none of them helped me.
  I am trying to POST data from angular 4 to REST API service. however after clicking submit button its giving error as Failed to load "URL": Response for preflight is invalid (redirect). 
  I know this is the CORS issue. we have added headers in web.xml as well. After that we are able to do GET request, but getting Preflight error for POST, PUT and DELETE. </p>
  
  <p>Following is my Component.ts method.I am calling saveDetails(form.value) on button submit click. emergencycontacts is my EMTServiceService(service)</p>
  
  <pre><code>saveDetails(user) {
    this.emergencycontacts.SaveEmpDetails([user])
      .subscribe(
        empData =&gt; {this.empDetails = empData;},
        error =&gt; console.log(error)
  );
  </code></pre>
  
  <p>EMTServiceService -</p>
  
  <pre><code>SaveEmpDetails(user):  Observable&lt;Employee&gt; {
    console.log(this.apiService.post('/Emt/saveEmtDetailsPost',  user)); 
    const some = this.apiService.post(
      '/Emt/saveEmtDetailsPost', user
    );
    console.log({some});
    return some.map( data =&gt; { return data.DATA; } );
  }
  </code></pre>
  
  <p>apiService is:</p>
  
  <pre><code>post(path: string, body: Object = {}): Observable&lt;any&gt; {
  
  let jsonPostValue = JSON.stringify(body);
  return this.http.post(
    `${environment.api_url}${path}`,
    jsonPostValue,
    { headers: this.setHeadersPost() }
  )
  .catch(this.formatErrors)
  .map((res: Response) =&gt; res.json());
  </code></pre>
  
  <p>}</p>
  
  <p>Rest service method:</p>
  
  <pre><code>@POST
     @Path("/saveEmtDetailsPost")
     @Consumes(MediaType.APPLICATION_JSON)
     @Produces(MediaType.APPLICATION_JSON)
     public String saveEmtDetails(EmtContacts EmtContactsBean) {       
          JSONArray jsonArray = new JSONArray();
          JSONObject jsonObject = new JSONObject();       
  
          String insertStmt = "INSERT INTO Emt_Contacts (EmpId,LocationID,DeptID,CreatedBy,CREATEDON,ModifiedBy,ModifiedOn,IsActive,Nortel,Mobile)"
                      + "VALUES (?,?,?,?,?,?,?,?,?,?)";
          System.out.println("insertStmt" + insertStmt);
          try {
                getJdbcTemplate().update(insertStmt, new Object[] {
  
                      EmtContactsBean.getEmpID(), EmtContactsBean.getLocationId(), EmtContactsBean.getDeptId(),                      
                            "ID5020","2017-01-01","ID5020","2017-01-01",
                            GlobalConstants.STATUS_ACTIVE,EmtContactsBean.getNortel(),EmtContactsBean.getMobile() });
  
                jsonObject = RespBuilder.buildSuccessResponse(GlobalConstants.KEY_CODE_SUCCESS,
                            GlobalConstants.STATUS_SUCCESS_MESSAGE);
          } catch (Exception e) {
                AppLoger.APPLOGGER.info("Exception is :" + e);
                jsonObject = RespBuilder.buildFailedResponse(GlobalConstants.KEY_MESSAGE_FAILURE, e.toString());
          }
          jsonArray.put(jsonObject);
          System.out.println(jsonArray);
          return jsonArray.toString();
    }
  </code></pre>
  
  <p>Thank you for your Help in advance</p>