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.
    Author:
    mtaal
    • 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.
        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 result
        log - the log message
        warning - 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 xml
        template - the XSLT template
        Returns:
        the resulting XML