java - BadRequestException in JAX-RS endpoint -
i have following endpoint declared in jax-rs application:
@webservice public interface alertweb { @post @path("/add") @produces(mediatype.application_json) @consumes(mediatype.application_form_urlencoded) public stringresponse addalert(string name, int amount, string timespan, string repo, string action); }
i'm using following curl
command call endpoint:
curl -x post -h "cache-control: no-cache" -h "content-type: application/x-www-form-urlencoded" -d "name=yellow&amount=2×pan=day&repo=a&action=%7baction%3a'greendivaction'%2c+message%3a'simple+message'%2c+args%3a+%5b'arg1'%2c'arg2'%5d%7d" http://localhost:8080/adminservice/alert/add
but keep getting following error when make request:
javax.ws.rs.badrequestexception: java.lang.numberformatexception: input string: ""
note line breaks in curl syntax added readability.
what doing wrong?
you need add @formparam
method parameters if want them injected such
@post @path("/add") @produces(mediatype.application_json) @consumes(mediatype.application_form_urlencoded) public response addalert( @formparam("name") string name, @formparam("amount") int amount, @formparam("timespan") string timespan, @formparam("repo") string repo, @formparam("action") string action) { }
Comments
Post a Comment