Openbravo 休息网络服务 [英] Openbravo rest web services

查看:53
本文介绍了Openbravo 休息网络服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在启动一个项目,该项目包含通过 Restful WS 层(可能是 json)与 OpenBravo 集成.这种集成在开始时很简单,因为只包含一个将执行 GET、PUT、POST 和 DELETE 操作.

I'm starting a project that consists in OpenBravo integration via the Restful WS Layer (may be json) That kind of integration is simple in the beggining because just consists in a rest web service client which will perform the GET, PUT, POST and DELETE actions.

我的问题是关于如何管理 json 对象,以及 OpenBravo 是否带来了某种方式来转换数据访问对象中的 json 对象,以便更容易处理.

My question is about how to manage the json objects and if OpenBravo brings some way to convert json objects in data access objects, in order to easier handling.

我见过 OpenBravo DAL(数据访问层),有没有办法将其余部分和 dal 混合起来处理 OB 对象?

I have seen OpenBravo DAL (Data Access Layer), Is there a way to mix the rest and dal to crud the OB Objects?

此致,

推荐答案

这是一个可能对您有所帮助的示例...首先让我们看一下这段代码

Here is an example which might help you... First Let us look at this code snippet

 public class SimpleRestClass extends BaseWebServiceServlet {
   private static final long serialVersionUID = 1L;

   @Override
   public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException,ServletException {
     String Name = request.getParameter("Name");
     String Email = request.getParameter("Email");

     List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
     Map<String, Object> map = new HashMap<String, Object>();

     map.put("Name", Name);
     map.put("Email", Email);
     // map.put("Path", request.getPathInfo().toString());

     list.add(map);
     final String json = new DataToJsonConverter().convertToJsonObjects(list).toString();

     // write to the response
    response.setContentType("application/json");
    response.setCharacterEncoding("utf-8");
    final Writer w = response.getWriter();
    w.write(json);
    w.close();

  }

}

在上面的代码中

final String json = new DataToJsonConverter().convertToJsonObjects(list).toString();

就是你要找的.convertToJsonObjects() 方法的签名是

is what you are looking for. The signature of convertToJsonObjects() method is

List<JSONObject> convertToJsonObjects(List<Map<String, Object>> data)

openbravo 中 REST Json WS 需要注意的重要类是

The important class in openbravo for REST Json WS to notice is

import org.openbravo.service.json.DataToJsonConverter

这个类有更多与 Json 相关的方法.希望这对您有所帮助.

This class has many more Json related methods. Hope this will help you.

如果您有任何问题,请随时提出.

If you have any questions then please feel free to ask.

这篇关于Openbravo 休息网络服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆