Package org.openbravo.service.web
Class WebServiceUtil
- java.lang.Object
-
- org.openbravo.service.web.WebServiceUtil
-
- All Implemented Interfaces:
OBProvidable
,OBSingleton
public class WebServiceUtil extends Object implements OBSingleton
Utility class for webservices, contains convenience methods for creating result xml messages.- Author:
- mtaal
-
-
Constructor Summary
Constructors Constructor Description WebServiceUtil()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description String
applyTemplate(String xml, InputStream template, String url)
Applies an XSLT template on the XML in the sourceDocument.String
createErrorXML(Throwable t)
Creates an error xml result String using the information from the passed in Throwable.String
createResultXML(String content)
Creates a standard result xml: <result>My Result</result>String
createResultXMLWithLogWarning(String msg, String log, String warning)
Creates a standard result xml with log and warning: <result><msg>My Result</msg><log>My Log</log><warning>My Warning</warning></result>String
createResultXMLWithObjectsAndWarning(String msg, String log, String warning, List<BaseOBObject> inserted, List<BaseOBObject> updated, List<BaseOBObject> deleted)
Creates a full result xml with message, log, warning and the id and identifiers of the inserted, updated and deleted objects.String
getFirstSegment(String path)
Returns the first segment of a path, for example: /openbravo/webservice will return openbravo here.static WebServiceUtil
getInstance()
String[]
getSegments(String path)
Splits the path into segments by splitting on the / characterstatic void
setInstance(WebServiceUtil instance)
-
-
-
Method Detail
-
getInstance
public static WebServiceUtil getInstance()
-
setInstance
public static void setInstance(WebServiceUtil instance)
-
createErrorXML
public String createErrorXML(Throwable t)
Creates an error xml result String using the information from the passed in Throwable.- Parameters:
t
- the Throwable used to set the error message- Returns:
- the xml error String, e.g. <error><message>An error occurred</message></error>
-
createResultXML
public String createResultXML(String content)
Creates a standard result xml: <result>My Result</result>- Parameters:
content
- the content of the result message- Returns:
- a xml result string
-
createResultXMLWithLogWarning
public String createResultXMLWithLogWarning(String msg, String log, String warning)
Creates a standard result xml with log and warning: <result><msg>My Result</msg><log>My Log</log><warning>My Warning</warning></result>- Parameters:
msg
- the content of the resultlog
- the log messagewarning
- the warning message- Returns:
- a xml result string
-
createResultXMLWithObjectsAndWarning
public String createResultXMLWithObjectsAndWarning(String msg, String log, String warning, List<BaseOBObject> inserted, List<BaseOBObject> updated, List<BaseOBObject> deleted)
Creates a full result xml with message, log, warning and the id and identifiers of the inserted, updated and deleted objects. Especially id's are required because the caller of the webservice (which inserts objects) needs to be able to retrieve the id's of the inserted objects to retrieve these objects later again.- Returns:
- the xml message containing the message, log, warning and id and identifiers of inserted, updated and deleted messages
-
getFirstSegment
public String getFirstSegment(String path)
Returns the first segment of a path, for example: /openbravo/webservice will return openbravo here. This method is used to find the name of the webservice which is requested.- Parameters:
path
- the request.getPath()- Returns:
- the first part of the path
-
getSegments
public String[] getSegments(String path)
Splits the path into segments by splitting on the / character- Parameters:
path
- the request.getPath()- Returns:
- the segments of the path
-
applyTemplate
public String applyTemplate(String xml, InputStream template, String url)
Applies an XSLT template on the XML in the sourceDocument. The resulting Dom4j Document is returned.- Parameters:
xml
- the source xmltemplate
- the XSLT template- Returns:
- the resulting XML
-
-