I have successfully installed Openbravo
, Now I am tesing for web services
. I have successfully created and tested GetProductDetails web service using Restful Web service. Now I am doing save product in database. But it is not working. Below is my code to save product.
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();
}
}
This is my simple Product xml data.
<?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>
I am not getting any exception nor data is save in database. This is the output I get
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>
What is the problem?
I have used JSON rest web service. Now successfully added product in the database.