Class 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.
    • Constructor Detail

      • WebServiceUtil

        public WebServiceUtil()
    • Method Detail

      • 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.
        t - the Throwable used to set the error message
        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>
        content - the content of the result message
        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>
        msg - the content of the result
        log - the log message
        warning - the warning message
        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.
        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.
        path - the request.getPath()
        the first part of the path
      • getSegments

        public String[] getSegments​(String path)
        Splits the path into segments by splitting on the / character
        path - the request.getPath()
        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.
        xml - the source xml
        template - the XSLT template
        the resulting XML