Problem Description
I'm trying to map a "legacy" REST server using RESTEasy client.
The urls of this ws are mapped like this:
http://localhost/webservice/rest/server.php?wstoken=reallylongtokenhash&wsfunction=core_course_get_courses
The endpoint is always server.php, and the function to call is mapped using a queryparam.
@POST
@Path("/server.php")
@Produces("application/json")
List<Map<String, Object>> getCourses(
@QueryParam("wstoken") String token
, @QueryParam("wsfunction") String function
, @QueryParam("moodlewsrestformat") String format);
@POST
@Path("/server.php")
@Produces("application/json")
String createUser(
@QueryParam("wstoken") String token
, @QueryParam("wsfunction") String function
, @QueryParam("moodlewsrestformat") String format
, @Form User user);
which I call in this way
private static void getCourses() {
final MoodleRest client = ProxyFactory.create(MoodleRest.class, "http://localhost/webservice/rest/");
final List<Map<String, Object>> s = client.getCourses(token, "core_course_get_courses", "json");
System.out.println("s = " + s);
}
Let's ignore the fact that a "get_courses" method is mapped using a POST, and that the token are passed using the QueryParameter on this post, is it possible to avoid passing the function and the response format on every method? I would like to map it using the annotations.
I tried to write in directly into the @Path using
/server.php?function=core_course_get_courses
But obviously this is not the right way to proceed (plus, it doesn't work since it's escaped)
AI-Generated Solution
Powered by LMSouq AI · GPT-4.1-mini
Analyzing problem and generating solution…
Was this solution helpful?