Openbravo:如何使用其他Web服务将产品保存在数据库中?

时间:2015-06-10 09:34:23

标签: openbravo

我已成功安装Openbravo,现在我正在测试web services。我已经使用Restful Web服务成功创建并测试了GetProductDetails Web服务。现在我在数据库中保存产品。但它没有用。以下是我保存产品的代码。

public void doPut(String path, HttpServletRequest request,
            HttpServletResponse response) throws Exception {
        // and return something...
        String returnMessage;
        try {
            final SAXReader reader = new SAXReader();
            final Document document = reader.read(request.getInputStream());
            System.out.println("##### document : "+document.asXML());
            // create a converter from xml to Openbravo business objects
            final XMLEntityConverter xec = XMLEntityConverter.newInstance();
            System.out.println("Get Client : "+OBContext.getOBContext().getCurrentClient().getName());
            xec.setClient(OBContext.getOBContext().getCurrentClient());
            System.out.println("Get Organization : "+OBContext.getOBContext().getCurrentOrganization().getName());
            xec.setOrganization(OBContext.getOBContext().getCurrentOrganization());

            // for a webservice referenced entities should not be created, see the javadoc
            // for more information
            xec.getEntityResolver().setOptionCreateReferencedIfNotFound(false);

            // process the dom4j document, does the actual conversion
            xec.process(document);

            // list the new objects (which do not yet exist in the db)
            for (BaseOBObject bob : xec.getToInsert()) {
              System.err.println("New business objects: " + bob.getIdentifier());
            }

            // list the objects which will be updated
            for (BaseOBObject bob : xec.getToUpdate()) {
              System.err.println("Updated business objects: " + bob.getIdentifier());
            }

            returnMessage = WebServiceUtil.getInstance().createResultXMLWithObjectsAndWarning(
                "Action performed successfully", "", xec.getWarningMessages(), xec.getToInsert(),
                xec.getToUpdate(), null);
            final Writer w = response.getWriter();
            w.write(returnMessage);
            w.close();
        } catch (Exception e1) {
            e1.printStackTrace();
        }
    } 

这是我简单的Product xml数据。

<?xml version="1.0" encoding="UTF-8"?>
<Openbravo xmlns="http://www.openbravo.com">
<Product>
<description>Test Description</description>
<imageUrl>Test Image URL</imageUrl>
<listPrice>50</listPrice>
<name>Test Name</name>
<number>number</number>
<purchasePrice>50</purchasePrice>
</Product>
</Openbravo>

我没有得到任何异常,也没有数据保存在数据库中。这是我得到的输出

Output from Server .... 

    <?xml version="1.0" encoding="UTF-8"?>

    <ob:result xmlns:ob="http://www.openbravo.com">
      <msg>Action performed successfully</msg>
    </ob:result>

有什么问题?

1 个答案:

答案 0 :(得分:0)

我使用过JSON rest web服务。现在已成功在数据库中添加产品。