java - REST Web 服务使用 ReSTLet 接受 POST - 最佳实践

标签 java web-services rest post restlet

我有我的资源和它们处理 POST 请求的典型重写方法。

public void acceptRepresentation(Representation rep) {

  if (MediaType.APPLICATION_XML.equals(rep.getMediaType())) {
      //Do stuff here
  }
  else {
      //complain!
  }
}

我想知道的是处理我的 XML 数据包的最佳实践。我看到很多使用 Form 的示例 - 但肯定有一种方法可以使用 Representation 对象本身或将其转换为一些有用的 XML 对象???

对于您应该如何解析资源中传入的 XML 的任何帮助,我们都非常感激。

最佳答案

这更像是我想要的回应。感谢Thierry Boileau答案:

You can use two kinds of "XML representations": DomRepresentation and SaxRepresentation. You can instantiate both of them with the posted representation. E.g.: DomRepresentation xmlRep = new DomRepresentation(rep);

The DomRepresentation gives you access to the Dom document. The SaxRepresentation allows you to parse the XML doc with your own contentHandler. See the javadocs here 1 and here 2.

  1. http://www.restlet.org/documentation/1.1/api/org/restlet/res​ource/DomRepresentat​ion.html

  2. http://www.restlet.o​rg/documentation/1.1​/api/org/restlet/res​ource/SaxRepresentat​ion.html

关于java - REST Web 服务使用 ReSTLet 接受 POST - 最佳实践,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/440989/

相关文章:

java - Spring Boot 不接受括号内的列表参数

java - 为什么 playframework 2.0.3 在 Controller 中显示无法识别的编译错误字符?

java - 我的 Vaadin 应用程序中所有布局的半透明横幅,à la Vaadin Charts 2 Demo 许可证?

C 程序-如何检查 Web 服务是否正在运行

java - 使用 Java Web 服务时如何访问 HttpServletRequest 对象

php - 将数据从一个页面发送到另一台服务器。语言不可知论

java - builder 模式和持久化

java - 识别同一包中的变量和方法时出现问题

api - 使用 vmware vCenter 7 Rest api 导出虚拟机的步骤是什么

javascript - Cesium KML 轮询数据