This is my custom class:
@XmlRootElement
class Request{
private String name;
private String age;
public Request(){
}
public Request(String name, String age) {
this.name = name;
this.age = age;
}
public String getName() {
return this.name;
}
}
This is my service:
@PATH("/webapp/")
class RestService{
@POST
@Produces(MediaType.APPLICATION_XML)
@PATH("getNameFromRequest")
public String getNameFromRequest(@FormPara Request request) {
System.out.println(request.getName()) //Here request.getName() is null !!!
return request.getName();
}
}
This is how I programmatically make the restful call using a client service created by JAXRSClientFactory
RestService service = JAXRSClientFactory.create("http://test:8080", RestService.class);
service.getNameFromRequest(new Request("Rachel","23"))
However, it seems that "Rachel" is not passed into the request at all.
If I use Web-browser to request against this, the name will be set:
http://test:8080/webapp?name=Rachel
Could someone please help me why I cannot programmatically make the restful call?