I wrote a simple web service in a MailREST class with this path:
@Path("/service")
the post method I want to 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 you 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 would like to understand which is the best method for calling it
I saw some examples with Apache HttpClient and Jersey, but I'm unable to make them work.