Openbravo rest web services

青春壹個敷衍的年華 提交于 2019-12-24 10:45:12

问题


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.

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.

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

Best Regards,


回答1:


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

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

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

import org.openbravo.service.json.DataToJsonConverter

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

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




回答2:


Openbravo has a module called org.openbravo.service.json

The above module makes use of JSON and DAL layer of openbravo.

When we make a get request for a product, JSON module uses DAL to query the database and convert OB Object to JSON object.

When we want to create a new product , JSON module uses DAL to create a new OB Object.

The main class you may need to focus on openbravo side is,

  • 1) DefaultJsonDataService
  • 2) JsonToDataConverter --Converts json data to Openbravo business object(s).

  • 3) DataToJsonConverter --Is responsible for converting Openbravo business objects to a json representation.

Important link: Openbravo JSON REST



来源:https://stackoverflow.com/questions/17214445/openbravo-rest-web-services

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!