Hi!
Is it even possible to invoke square method and get "good" result?
In this setup: no there isn't. That is because there is no standard MessageBodyWriter defined for a Double.
n2 param is not annotated, so what value it will have if somehow it will be invoked? Is there way to send request for such resource (with not annotated params)?
It is possible when using Strings only. n2 doesn't have to be annotated if the parameter is sent as an entity.
Try this working example:
Code: Select all
Client cl = Client.create();
WebResource webResource = cl.resource("http://localhost:8080/SimpleRS/j/div/10");
String response = webResource.entity("2").get(String.class);
System.out.println(response.toString());
and the method:
Code: Select all
@ApplicationPath("j")
@Path("div")
@Stateless
public class DivisionResource extends Application {
@POST
@Path("{num}")
public String divString(@PathParam("num") String n1, String n2){
return "" + (new Integer(n1)/new Integer(n2));
}
}
Result is:
5
Note that parameter n2 is sent as the body of the post request (entity("2")), and parameter n1 ("10") is sent as part of the URL.
Regards,
Frits