how to send JSON to a REST web service -
i wrote simple web service in mailrest class path:
@path("/service")
the post method want test is:
@post @path("/sendtest/") @consumes(mediatype.application_json) @produces(mediatype.text_plain) public string test(jsonobject json) { string input = (string) json.get("input"); string output = "the input sent is:" + input; system.err.println(output); return "hello"; }
my mailrestclient class is:
static final string rest_uri = "http://localhost:9999/mail"; static final string mail = "service/sendtest"; public static void main(string[] args) { mail mail = new mail(); mail.setfrom("testfrom"); mail.setto("testto"); byte[] attachment = new byte[] {}; string attachmentbase64encoded = datatypeconverter.printbase64binary(attachment); gson g = new gson(); string json = g.tojson(mail); ????? }
i understand best method calling
i saw examples apache httpclient , jersey, i'm unable make them work.
Comments
Post a Comment