-->

Parse BPEL File to extract activities + XPath

2019-08-09 08:04发布

问题:

I need to extract the activities and their XPath of a BPEL Process out of the xml file.

I'm familiar with the theory behind BPEL but not the fileformat itself. If I read a BPEL file I have difficulties to identify the specific activities. Not to speak of the XPath.

How do I parse a BPEL file in a way that I get every activity, no mather what orchestration type, and its XPath?

ps: in java

EDIT: what I want to extract

<name>CallService1Op2</name>
<xpath>/process/sequence[1]/invoke[1]</xpath>

(the xml-tags are not actually in the xml. it's just for pointing out what I want.)

From the following bpel:sequence

    <bpel:sequence name="main">

        <!-- Receive input from requester. 
             Note: This maps to operation defined in LoadProcess.wsdl 
             -->
        <bpel:receive name="receiveInput" partnerLink="client"
                 portType="tns:LoadProcess"
                 operation="process" variable="input"
                 createInstance="yes"/>

        <!-- Generate reply to synchronous request -->
        <bpel:assign validate="no" name="Assign">


            <bpel:copy>
                <bpel:from><bpel:literal><impl:callService2 xmlns:impl="http://loadWS.iaas.unistuttgart.de" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <impl:sleepMiliSeconds>0</impl:sleepMiliSeconds>
</impl:callService2>
</bpel:literal></bpel:from>
                <bpel:to variable="Service1PLRequest" part="parameters"></bpel:to>
            </bpel:copy>
            <bpel:copy>
                <bpel:from part="payload" variable="input">
                    <bpel:query queryLanguage="urn:oasis:names:tc:wsbpel:2.0:sublang:xpath1.0"><![CDATA[tns:input]]></bpel:query>
                </bpel:from>
                <bpel:to part="parameters" variable="Service1PLRequest">
                    <bpel:query queryLanguage="urn:oasis:names:tc:wsbpel:2.0:sublang:xpath1.0"><![CDATA[ns:sleepMiliSeconds]]></bpel:query>
                </bpel:to>
            </bpel:copy>
        </bpel:assign>
        <bpel:invoke name="CallService1Op2" partnerLink="Service1PL" operation="callService2" portType="ns:Service1" inputVariable="Service1PLRequest" outputVariable="Service1PLResponse"></bpel:invoke>
        <bpel:assign validate="no" name="Assign1">
            <bpel:copy>
                <bpel:from><bpel:literal><tns:LoadProcessResponse xmlns:tns="de.unistuttgart.iaas.bpel.loadProcess" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <tns:result>tns:result</tns:result>
</tns:LoadProcessResponse>
</bpel:literal></bpel:from>
                <bpel:to variable="output" part="payload"></bpel:to>
            </bpel:copy>
            <bpel:copy>
                <bpel:from part="parameters" variable="Service1PLResponse">
                    <bpel:query queryLanguage="urn:oasis:names:tc:wsbpel:2.0:sublang:xpath1.0"><![CDATA[ns:callService2Return]]></bpel:query>
                </bpel:from>
                <bpel:to part="payload" variable="output">
                    <bpel:query queryLanguage="urn:oasis:names:tc:wsbpel:2.0:sublang:xpath1.0"><![CDATA[tns:result]]></bpel:query>
                </bpel:to>
            </bpel:copy>
        </bpel:assign>
        <bpel:reply name="replyOutput" 
               partnerLink="client"
               portType="tns:LoadProcess"
               operation="process" 
               variable="output"
               />
    </bpel:sequence>

the above is a quite simple example. the xpath more often looks like

/process/sequence[1]/sequence[1]/repeatUntil[1]/sequence[1]/invoke[1]

because the activity is nested into squences, flows, loops, ifs or what not.

EDIT2:

Usecase: BPEL Process is running on Apache-ODE. Apache-ODE puts out events for start/stop/whatever of a Process/Activity. The event contains only the XPath. But I want to see the name, so I have to match against the XPath.

回答1:

I think you should chek this post: Get Xpath from the org.w3c.dom.Node

Also in it is mentionned this lib: http://code.google.com/p/joox/ which seems useful

What I'd do: A generic Xpath to list all the activity nodes from the xml. Then using Dom or the joox lib if it works well for you (disclaimer, not tested) you get the name and an xpath string...

Hope this helps