RESTEasy映射“遗留”Moodle REST服务

时间:2012-05-03 10:04:49

标签: rest resteasy moodle

我正在尝试使用RESTEasy客户端映射“传统”REST服务器。

这个ws的网址映射如下:

http://localhost/webservice/rest/server.php?wstoken=reallylongtokenhash&wsfunction=core_course_get_courses

端点始终是server.php,要使用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);

我以这种方式打电话

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);
}

让我们忽略一个事实,即使用POST映射“get_courses”方法,并且使用此帖子上的QueryParameter传递令牌,是否可以避免在每个方法上传递函数和响应格式?我想使用注释来映射它。

我尝试使用

直接写入@Path

/server.php?function=core_course_get_courses

但显然这不是正确的继续进行方式(此外,由于它已被转义,因此无效)

1 个答案:

答案 0 :(得分:0)

也许最好直接在你的方法中使用HttpServletRequest并解析请求参数&#34;手工&#34;。我的意思是:

@POST
@Path("/server.php")
@Produces("application/json")
List<Map<String, Object>> getCourses(@Context HttpServletRequest request){
   //parse request.getParameters()
}