-1

I have the following method:

@Path("/criar_evento")
@GET
@Consumes({"application/json", "application/xml"})
@Produces({"application/json", "application/xml"})
public synchronized Evento addEvento(@QueryParam("nome") String nome, @QueryParam("data") String data, @QueryParam("tipo") String tipo) {
    Evento evento = new Evento(nome,data,tipo);
    System.out.println(nome + "\n" + data + "\n" + tipo);
    return evento;
}

When I try to run this terminal code:

curl http://localhost:8001/sd/evento/criar_evento?nome=teste&data=25082001&tipo=basket

I get the data and tipo as null values but not the name

Here is the output on the server:

teste
null
null

But if I try for example:

curl http://localhost:8001/sd/evento/criar_evento?data=25082001&tipo=basket&nome=teste

In the server I get:

null
25082001
null

Any ideas in how to fix this?

3
  • When I use the link in the browser all works just fine Commented Jan 16, 2022 at 23:49
  • Not an expert, but try without @Consumes. The GET method handles only key-value pairs in the URL, and @Consumes may be confusing the code (@Confuses?) Commented Jan 17, 2022 at 2:32
  • 1
    & may be being interpreted by your shell. Try enclsing your URL in ' characters. Commented Jan 17, 2022 at 2:49

1 Answer 1

-1

The problem is in the "@Consumes({"application/json", "application/xml"})" this means that the addEvent method is expecting an Input Json object and you are sending values separated by commas in the tests.

you should send a json object like this:

{
'name'='test',
'data'='25082001',
'type'='basketball'
}

and you should test through postman.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.