【问题标题】:RESTEasy mapping a "legacy" Moodle REST serviceRESTEasy 映射“遗留”Moodle REST 服务
【发布时间】:2012-05-03 10:04:49
【问题描述】:

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

这个ws的url映射如下:

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

端点始终是 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

但显然这不是正确的方法(另外,因为它被转义了,所以它不起作用)

【问题讨论】:

    标签: rest resteasy moodle


    【解决方案1】:

    也许直接在您的方法中使用 HttpServletRequest 并“手动”解析请求参数会更好。我的意思是:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-11-08
      • 2010-11-23
      • 1970-01-01
      • 2011-05-22
      • 2010-12-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多