I have a problem of API Restfull backend (jersey jpa) and frontend (angular 5) in my development because when I execute an update operation of my application, I have never encountered this problem before, so I'm not able to understand this. code here
title: LangueRest.java
package com.spro.rest;
import java.util.List;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import com.spro.dao.DaoFactory;
import com.spro.entity.Langue;
import com.spro.jpa.JpaLangueDao;
@Path("/langue")
public class LangueRest {
private JpaLangueDao langueDao;
public LangueRest() {
this.langueDao = DaoFactory.getInstance().getLangueDao();
}
@Path("/getall")
@GET
@Produces(MediaType.APPLICATION_JSON)
public List<Langue> getAll(){
return langueDao.findAll();
}
@Path("/{id}")
@GET
@Produces(MediaType.APPLICATION_JSON)
public Langue getById(@PathParam("id") long id){
return langueDao.findById(id).get(0);
}
@Path("/add")
@POST
@Consumes(MediaType.APPLICATION_JSON)
public void add(Langue langue) {
langueDao.add(langue);
}
@Path("/update")
@PUT
@Consumes(MediaType.APPLICATION_JSON)
public void update(Langue langue) {
langueDao.update(langue);
}
@Path("/delete")
@
@Consumes(MediaType.APPLICATION_JSON)
public void delete(Langue langue) {
langueDao.delete(langue);
}
}
langue.service.ts
import { Langue } from './langue';
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import {Observable} from 'rxjs';
import 'rxjs/add/operator/map';
const httpOptions = {
headers: new HttpHeaders({ 'Content-Type': 'application/json'})
};
@Injectable()
export class LangueService {
constructor(private http: HttpClient) {}
// lister toutes les Langues
getLangues() {
return this.http.get('http://localhost:8081/APIRest/resources/langue/getall');
}
// créer un enregistrement langue
createLangue(langue:Langue) {
return this.http.post('http://localhost:8081/APIRest/resources/langue/add', JSON.stringify(langue), httpOptions);
}
// modifier une langue
updateLangue(langue:Langue) {
alert("sssssss "+ httpOptions);
return this.http.put('http://localhost:8081/APIRest/resources/langue/update' + langue.langueId, JSON.stringify(langue), httpOptions);
}
// supprimer une langue
deleteLangue(langue:Langue) {
return this.http.delete('http://localhost:8081/APIRest/resources/langue/delete/'+ langue.langueId);
}
}
the error is:
PUT http://localhost:8081/APIRest/resources/langue/update3092 405 (Non Allowed Method)