Some Name
Some Name

Reputation: 571

JAX-RS 405 Method not allowed

My GET functions for JAX-RS work perfectly. I am now working on my POST methods, but this keeps giving me 405 errors. My resource points towards my DAO.

Is there something faulty in my code?

REsource

@POST
@Path("/insert")
public void insertIngredient(@QueryParam("Q1") int hoeveelheid, @QueryParam("Q2") String datum,@QueryParam("Q3") String ingredientnaam , @QueryParam("Q4") String gebruikersnaam) {
    IngredientService service = ServiceProvider.getIngredientService();
    service.insertIngredient(hoeveelheid, datum, ingredientnaam, gebruikersnaam);
}

DAO

public void insertIngredient(int hoeveelheid, String datum, String ingredientnaam, String gebruikersnaam) {
    try (Connection con = super.getConnection()) {
        Statement stmt = con.createStatement();
        ResultSet nextId = stmt.executeQuery("SELECT MAX(dagboek_id) FROM dagboek");
        int maxId = nextId.getInt("dagboek_id") + 1;

        stmt.executeQuery("insert into dagboek(dagboek_id, hoeveelheid, datum, fk_ingredientnaam, fk_gebruikersnaam) values('"+maxId+"','" + hoeveelheid + "','" + datum + "','" + ingredientnaam + "','" + gebruikersnaam + "')");

    } catch (SQLException sqle) {
        sqle.printStackTrace();
    }
}

Upvotes: 2

Views: 5638

Answers (1)

Jeff Wang
Jeff Wang

Reputation: 1867

an HTTP 405 method not allowed means that you got the correct endpoint, but did not get a correct http method. It has nothing to do with your implementation of the endpoint. Common poential issues to check are:

  1. Are you sure you're making the request as a POST?
  2. Did you configure your server to allow POSTs to that particular endpoint?
  3. Do you have a method overwriting filter somewhere?

Upvotes: 2

Related Questions