Внутренняя ошибка сервера 500. Неожиданный символ JSON.parse в строке 1 столбца 1 данных JSON - PullRequest
0 голосов
/ 21 мая 2019

Я хочу отправить данные на мой REST-сервер, работающий на glassfish. Я все время получаю внутреннюю ошибку сервера 500, и я не знаю, что не так. Я искал в Интернете, но это не помогло мне. Мой фронтенд сделан с угловатыми, а бэкэнд работает на стеклянных рыбках. Я часами пытаюсь отладить эту ошибку, но ничего не получается. Надеюсь, кто-то знает, что здесь не так?

Frontend:

  public codeValue: string;

  codeList = [
    { id: 1, name: 'Mcdonalds' },
    { id: 2, name: 'Kentucky Fried Chicken' },
    { id: 3, name: 'Burger King' },
    { id: 4, name: 'Domino`s pizza' },
    { id: 5, name: 'New York Pizza' }
  ];


  @ViewChild('f') form: NgForm;
  restaurant = {
    id: null,
    name: ''
  };
   httpOptions = {
    headers: new HttpHeaders({
      'Content-Type':  'application/json',
      'Authorization': 'my-auth-token'
    })
  };


  constructor(private http: HttpClient) {
  }

  ngOnInit() {
  }

  public saveCode(e): void {
    let name = e.target.value;
    let list = this.codeList.filter(x => x.name === name)[0];



    this.restaurant.id =  list.id;
    this.restaurant.name = list.name;

console.log(list.id);
console.log(list.name);



    const httpOptions = {
      headers: new HttpHeaders({
        'Content-Type':  'application/json'
      })
    };

    const data = {
      id: list.id,
      name: list.name
    };


    this.http.post('http://localhost:8080/aquadine-jee/resources/restaurant',
      (data), httpOptions)


      .subscribe( // subscribe to observable http.post
        res => {
          console.log("response" + " " + res); // log results otherwise log error
        },
        err => {
          console.log('Error occured');
        }
      );
  }

Код сервера:

@GET
@Produces("application/json")
public Response all(){
    List<Restaurant> all = repositoryService.getAllRestaurants();
    return Response
            .status(200)
            .header("Access-Control-Allow-Origin", "*")
            .entity(all)
            .build();
}



    @POST
    @Consumes("application/json")
    public Response save(Restaurant restaurant){
        repositoryService.save(restaurant);
        return Response
                .status(201)
                .build();
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...