Thursday, November 1, 2012

Access to XmlStore files from within Ws-App java code

Today I needed to have access from within Java Ws-App code to an XML definition located within the XML Store.
Within a Cordys BPM those webservices are available and can be easily drag and dropped into your BPM, but if you need this within your java code it can be easily accomplished by executing a Soap request.

public class XmlStore
    final String NS_CASEMNGT_INST = "";

    public static int getXMLObject(String userDn, String key)
        int retVal = 0;
        int response = 0;

            // Build up the request to send.
            String[] paramNames = { "key" };
            Object[] paramValues = { key };
            SOAPRequestObject sro = new SOAPRequestObject(NS_CASEMNGT_INST , "GetXMLObject", paramNames, 

            // Set the proxy user if passed on
            if (StringUtils.isSet(userDn))

            // Send the actual request.
            response = sro.sendAndWait();

            // Find the response document
            retVal = XPathHelper.selectSingleNode(response, "//xs:old/*", Constants.xmi);
        catch (Exception e)
            throw new CustomException(e, Messages.ERROR_GETTING_FILE_FROM_XML_STORE, key);
        return retVal;

And in the calling function you have than something like this:
Int xmlstoreObject = XMLStore.getXMLObject(BSF.getUser(), "/nl/project/xmlstore/xmlfile.xml");

Don't forget in your calling code to clean-up the NOM element by using the 'Node.delete(node)' function.
Otherwise memory leaks can be easily introduced.

No comments:

Post a Comment