简体   繁体   English

Openbravo休息网络服务

[英]Openbravo rest web services

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. 我正在通过Restful WS Layer(可能是json)启动一个包含OpenBravo集成的项目。这种集成在开始时很简单,因为它只包含一个休息Web服务客户端,它将执行GET,PUT,POST和DELETE动作。

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. 我的问题是如何管理json对象,以及OpenBravo是否带来了一些转换数据访问对象中json对象的方法,以便于处理。

I have seen OpenBravo DAL (Data Access Layer), Is there a way to mix the rest and dal to crud the OB Objects? 我见过OpenBravo DAL(数据访问层),有没有办法混合其余的和dal来讨论OB对象?

Best Regards, 最好的祝福,

Openbravo has a module called org.openbravo.service.json Openbravo有一个名为org.openbravo.service.json的模块

The above module makes use of JSON and DAL layer of openbravo. 上面的模块使用了openbravo的JSON和DAL层。

When we make a get request for a product, JSON module uses DAL to query the database and convert OB Object to JSON object. 当我们对产品发出get请求时,JSON模块使用DAL查询数据库并将OB Object转换为JSON对象。

When we want to create a new product , JSON module uses DAL to create a new OB Object. 当我们想要创建新产品时,JSON模块使用DAL来创建新的OB对象。

The main class you may need to focus on openbravo side is, 您可能需要关注openbravo方面的主要类是,

  • 1) DefaultJsonDataService 1)DefaultJsonDataService
  • 2) JsonToDataConverter --Converts json data to Openbravo business object(s). 2)JsonToDataConverter - 将json数据转换为Openbravo业务对象。

  • 3) DataToJsonConverter --Is responsible for converting Openbravo business objects to a json representation. 3)DataToJsonConverter - 负责将Openbravo业务对象转换为json表示。

Important link: Openbravo JSON REST 重要链接: Openbravo JSON REST

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

  }

}

In the above code 在上面的代码中

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

is what you are looking for. 是你在找什么。 The signature of convertToJsonObjects() method is convertToJsonObjects()方法的签名是

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

The important class in openbravo for REST Json WS to notice is 用于REST Json WS的openbravo中的重要类是注意到的

import org.openbravo.service.json.DataToJsonConverter

This class has many more Json related methods. 这个类有更多与Json相关的方法。 Hope this will help you. 希望这会帮助你。

If you have any questions then please feel free to ask. 如果您有任何疑问,请随时提出。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM