【发布时间】:2012-05-03 10:04:49
【问题描述】:
我正在尝试使用 RESTEasy 客户端映射“旧版”REST 服务器。
这个ws的url映射如下:
端点始终是 server.php,调用的函数是使用查询参数映射的。
@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);
我这样称呼它
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);
}
让我们忽略一个事实,即“get_courses”方法是使用 POST 映射的,并且令牌是使用 QueryParameter 在这篇文章中传递的,是否可以避免在每个方法上传递函数和响应格式?我想使用注释来映射它。
我尝试使用
直接写入@Path/server.php?function=core_course_get_courses
但显然这不是正确的方法(另外,因为它被转义了,所以它不起作用)
【问题讨论】: