I wish to use the interface only option of the RestEasy framework as it is much cleaner and should work.
But I’m having problems with passing parameters within POST request.
I found this example in the documentation:
@PUT
@Path("basic")
@Consumes("text/plain")
void putBasic(String body);
And to invoke:
import org.jboss.resteasy.client.ProxyFactory;
// ...
// this initialization only needs to be done once per VM
RegisterBuiltin.register(ResteasyProviderFactory.getInstance());
SimpleClient client = ProxyFactory.create(SimpleClient.class, "http://localhost:8081");
client.putBasic("hello world");
I’ve tried the following:
@POST
@Consumes(MediaType.TEXT_PLAIN)
@Path("http://localhost:8080/app/resource")
String postBasic(String body);
And invoked:
RegisterBuiltin.register(ResteasyProviderFactory.getInstance());
RepoClient client = ProxyFactory.create(RepoClient.class, "");
client.postBasic("hi");
When printing the parameters Map (and debugging it) on the doPost method of the called servelet, the parameters were empty. I really can’t see the difference between my approach and the documented one (which is from here: Resteasy interface example).
So to sum up, only using the Interface declaration and proxy implementation how can I send POST parameters?
Solution: It’s as expected…just needed to declare the consumes accordingly with the received parameter and it works…the problem was calling the POST method of a servlet within another servlet.
In your POST example, the
@Pathcannot include an absolute URL. Try to put just/appor/app/resource, depending on your configuration.