Monday, December 2, 2013

#290 Accessing Process Payload via JDBC

Here is my process -
















I instantiate an instance of this using em.

I see the following in the dlv_message table -




I select the GUID, in my case 57D6E....

I now look at the DOCUMENT_DLV_MSG_REF table this will contain a reference to the table storing the incoming payload for the BPM process - key is the above GUID.





This gives me the document_id 57DA6....

I now look in the XML_DOCUMENT table




So now I want to retrieve the value of the payload from a Java client -

Firstly, kudos to Arik for his reply on the forum -

https://forums.oracle.com/thread/2515495

Here's my code -

    public String getProcessPayload(String docId) throws SQLException,
                                                         BinXMLException,
                                                         IOException {
        String rtc = "";
        String selectCmd =
            "select document_id, document_type, document from dev_soainfra.xml_document where document_id = '" +
            docId + "'";
        Connection conn = getConnection(jdbcUrl, dbUser, dbPassword);
        Statement statement;
        statement = conn.createStatement();
        ResultSet rs = null;
        try {
            //       System.out.println("SQL = " + selectCmd);
            rs = statement.executeQuery(selectCmd);
            XMLDOMImplementation domimpl = new XMLDOMImplementation();
            while (rs.next()) {
                BinXMLProcessor proc =  BinXMLProcessorFactory.createProcessor();
                  BinXMLStream inpbin = proc.createBinXMLStream(rs.getBlob("DOCUMENT"));
                  BinXMLDecoder dec = inpbin.getDecoder();
                  InfosetReader xmlreader = dec.getReader();
             
                  XMLDocument doc = (XMLDocument)domimpl.createDocument(xmlreader);
                  doc.print(System.out);
                //
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return rtc;
    }

    private static Connection getConnection(String jdbcUrl, String dbUser,
                                            String dbPassword) {


        Connection connection = null;

        try {
            Class.forName("oracle.jdbc.driver.OracleDriver");
            connection =
                    DriverManager.getConnection(jdbcUrl, dbUser, dbPassword);
        } catch (ClassNotFoundException e) {
            throw new RuntimeException("No Driver");
        } catch (SQLException sqle) {
            throw new RuntimeException("SQL Error", sqle);
        }
        return connection;
    }

Here's the client -

public class Tester {
    public Tester() {
        super();
    }

    public static void main(String[] args) throws WorkflowException,
                                                  StaleObjectException,
                                                  Exception {
        Tester tester = new Tester();
        ITaskQueryAPIDemo itq = new ITaskQueryAPIDemo();
   
        itq.getProcessPayload("57DA64F05B3D11E3BF88096B9553B378");
      
      
                                           
         }
}

Here's the output -















Full JDev Project Here


No comments: