I can’t find my GET method path in Webservice Rest

Asked

Viewed 137 times

0

@Path("webservice")
public class WebService {

    private CriancaDAO criancaDAO = new CriancaDAO();

    @GET
    @Path("getCriancaTodasCriancas/{idCrianca}")
    @Produces(MediaType.APPLICATION_JSON)
    public List<Crianca> getCriancaTodasCriancas() {

        return criancaDAO.getCriancaTodasCriancas();

    }

    @GET
    @Path("/getCriancaPorId/{idCrianca}")
    @Produces(MediaType.APPLICATION_JSON)

    public Crianca getCriancaPorId(@PathParam("idCrianca") int idCrianca) {

        return criancaDAO.getCriancaPorId(idCrianca);

    }

    @GET
    @Path("/salvarCrianca/{name}/{sexo}/{dataNasc}/{parentesco}/{etinia}/{corCabelo}/{corOlhos}/{rua}/{bairro}")
    @Produces(MediaType.APPLICATION_JSON)

    public String salvarCrianca(@PathParam("name") String name, @PathParam("sexo") boolean sexo, @PathParam("dataNasc") Date dataNasc, @PathParam("parentesco") String parentesco,
            @PathParam("etinia") String etinia, @PathParam("corCabelo") String corCabelo, @PathParam("corOlhos") String corOlhos, @PathParam("rua") String rua, @PathParam("bairro") String bairro) {

        Crianca crianca = new Crianca();
        crianca.setName(name);
        crianca.setSexo(sexo);
        crianca.setDataNasc(dataNasc);
        crianca.setParentesco(parentesco);
        crianca.setEtinia(etinia);
        crianca.setCorCabelo(corCabelo);
        crianca.setCorOlhos(corOlhos);
        crianca.setRua(rua);
        crianca.setBairro(bairro);

        if (criancaDAO.salvarCrianca(crianca)) {

            return "(\"Crianca Salva!\")";

        } else {

            return "(\"Crianca não Salva!\")";

        }
    }

    @GET
    @Path("/salvarCrianca/{idCrianca}/{name}/{sexo}/{dataNasc}/{parentesco}/{etinia}/{corCabelo}/{corOlhos}/{rua}/{bairro}")
    @Produces(MediaType.APPLICATION_JSON)

    public String AtualizaCrianca(@PathParam("idCrianca") int idcrianca, @PathParam("name") String name, @PathParam("sexo") boolean sexo, @PathParam("dataNasc") Date dataNasc, @PathParam("parentesco") String parentesco,
            @PathParam("etinia") String etinia, @PathParam("corCabelo") String corCabelo, @PathParam("corOlhos") String corOlhos, @PathParam("rua") String rua, @PathParam("bairro") String bairro) {

        Crianca crianca = new Crianca();

        crianca.setIdCrianca(idcrianca);
        crianca.setName(name);
        crianca.setSexo(sexo);
        crianca.setDataNasc(dataNasc);
        crianca.setParentesco(parentesco);
        crianca.setEtinia(etinia);
        crianca.setCorCabelo(corCabelo);
        crianca.setCorOlhos(corOlhos);
        crianca.setRua(rua);
        crianca.setBairro(bairro);

        if (criancaDAO.salvarCrianca(crianca)) {

            return "(\"Crianca Salva!\")";

        } else {

            return "(\"Crianca não Salva!\")";

        }

    }

}

When I put my server address:

http://localhost:8080/Webserviceandroid/webservice/salvarCrianca/

Only da not found.

Prj in netbeans and glassfish server.

  • 1

    Are you passing the parameters? By the way, why are you sending such complex information via GET? It would be better to use the verb POST.

  • Yes, I am and I did so because follows a tutorial and the little I know rs, I’m still attending college. Thank you

  • If you want a hint: change the tutorial =). You’ll end up learning wrong.

  • 1

    In the "@Path" annotation, "/" was missing, leave it at this: "@Path("/webservice")", also check what @jbueno commented, if you are not passing the parameters will not work.

  • Thanks for the answer, more even by passing the parameters and putting the @Path("/webservice") only from not found. Ex.:http://localhost:8080/Webserviceandroid/webservice/salvarcrianca/Marcelo/true/10-12-1991/pai/white/brown/brown/Walter/saofrancisco

1 answer

0

You also need to set up your web.xml. It would look like this:

<servlet-name>Jersey RESTful Application</servlet-name>
 <url-pattern>/rest/*</url-pattern>
</servlet-mapping>

Then you will be able to access the url like this:

http://localhost:8080/WebServiceAndroid/rest/webservice/salvarCrianca/

I hope I’ve helped ^^

Browser other questions tagged

You are not signed in. Login or sign up in order to post.