0

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.

Noomak
  • 371
  • 5
  • 19
  • Is it mandatory for you to call your webservice from a main class? there are browser plugins using which you can easily test your web services. Check this post for testing using Chrome extension called "Postman" : http://stackoverflow.com/questions/29364862/how-to-send-post-request-to-the-below-post-method-using-postman-rest-client/29365126#29365126 – Pramod Karandikar Apr 01 '15 at 12:53
  • no it's not, but except for the name 'test' , that is effectively the piece of code I need for the client, that must be java coded – Noomak Apr 01 '15 at 13:02

0 Answers0