14 Replies Latest reply on Jul 7, 2006 6:54 AM by ncapito

    BPEL Condition

    ncapito

      Can someone please help me with conditionals in BPEL? I looked at the spec and it said there was a but it seems to error on the line with the if statement. I am trying to do an if check on a string...




      Just looking for a quick and diry example..... this is what i tried:


      <if>
       <condition>
       "bpel:getVariableProperty('request','msg')=string(Fusion1)"
       </condition>
       <assign name="assigncase1">
       <copy>
       <from>
       <literal><![CDATA[CASE1]]></literal>
       </from>
       <to variable="serviceRequest" part="String_1" />
       </copy>
       </assign>
       <invoke operation="writeMessage" partnerLink="fusionService"
       portType="ws:SimpleFileWriter" inputVariable="serviceRequest"
       outputVariable="serviceResponse" />
       <assign name="SimpleFusionResponseAssign">
       <copy>
       <from variable="serviceResponse" part="result" />
       <to variable="response" part="returnMsg" />
       </copy>
       </assign>
      
       <else>
       <assign name="assigncase2">
       <copy>
      
       <from>
       <literal><![CDATA[CASE2]]></literal>
       </from>
       <to variable="serviceRequest" part="String_1" />
       </copy>
       </assign>
       <invoke operation="writeMessage"
       partnerLink="fusionService" portType="ws:SimpleFileWriter"
       inputVariable="serviceRequest" outputVariable="serviceResponse" />
       <assign name="SimpleFusionResponseAssign">
       <copy>
       <from variable="serviceResponse" part="result" />
       <to variable="response" part="returnMsg" />
       </copy>
       </assign>
      
      
       </else>
      
       </if>


        • 1. Re: BPEL Condition
          aguizar

          jBPM BPEL alpha 4 does not parse the new syntax for conditional behavior introduced in WS-BPEL 2. The upcoming beta 1 will parse it. See issue BPEL-162 for details.

          As a workaround, please use the old syntax.

          • 2. Re: BPEL Condition
            aguizar

            BPEL-162 is done. Please check out the code from the head branch of our CVS repo.

            • 3. Re: BPEL Condition
              ncapito

              So i am no longer getting an error about the if clause it is a parsing null pointer error. Is this conecept correct? If it is i will post real code:

              <sequence name="MainFusionSequence">
              
               <receive operation
               </receive>
              
               <if>
               <condition>
               </condition>
               <then>
               <assign>
               <copy>
               <from>
               </from>
               <to variable />
               </copy>
               </assign>
               </then>
               <else>
               <assign>
               .... </assign>
               </else>
              
               </if>
              
              
              
               <invoke operation> ....
              
              
              


              I think it is a simple concept and should work. I orig had a sequence in there and i simplified the if to see if it was something i was doing wrong. In my condition i am trying to compare a string to some literal value... my fear is that the condition is causing the null:

              bpel:getVariableProperty("request","msg")=string(Fusion1)


              I am posting the error below:

              006-05-16 13:09:14,453 ERROR [org.jbpm.bpel.xml.ProblemHandler] JTMFusion.bpel could not read process document
              java.lang.NullPointerException
               at org.jbpm.bpel.xml.BpelReader.readActivity(BpelReader.java:947)
               at org.jbpm.bpel.xml.IfReader.readBranch(IfReader.java:49)
               at org.jbpm.bpel.xml.IfReader.readActivity(IfReader.java:28)
               at org.jbpm.bpel.xml.ActivityReader.read(ActivityReader.java:40)
               at org.jbpm.bpel.xml.BpelReader.readActivity(BpelReader.java:952)
               at org.jbpm.bpel.xml.SequenceReader.readActivity(SequenceReader.java:27)
               at org.jbpm.bpel.xml.ActivityReader.read(ActivityReader.java:40)
               at org.jbpm.bpel.xml.BpelReader.readActivity(BpelReader.java:952)
               at org.jbpm.bpel.xml.BpelReader.readScope(BpelReader.java:440)
               at org.jbpm.bpel.xml.BpelReader.read(BpelReader.java:218)
               at org.jbpm.bpel.xml.BpelReader.read(BpelReader.java:173)
               at org.jbpm.bpel.par.BpelArchiveParser.readFromArchive(BpelArchiveParser.java:28)
               at org.jbpm.jpdl.par.ProcessArchive.parseProcessDefinition(ProcessArchive.java:81)
               at org.jbpm.bpel.web.deploy.DeployServlet.doGet(DeployServlet.java:49)
               at javax.servlet.http.HttpServlet.service(HttpServlet.java:697)
               at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
               at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
               at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
               at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:81)
               at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
               at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
               at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
               at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
               at org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:39)
               at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:159)
               at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:59)
               at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
               at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
               at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
               at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
               at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
               at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
               at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
               at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
               at java.lang.Thread.run(Thread.java:595)
              2006-05-16 13:09:14,453 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/jbpm-bpel].[DeployServlet]] Servlet.service() for servlet DeployServlet threw exception
              org.jbpm.jpdl.JpdlException: [[ERROR] JTMFusion.bpel could not read process document]
               at org.jbpm.jpdl.par.ProcessArchive.parseProcessDefinition(ProcessArchive.java:84)
               at org.jbpm.bpel.web.deploy.DeployServlet.doGet(DeployServlet.java:49)
               at javax.servlet.http.HttpServlet.service(HttpServlet.java:697)
               at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
               at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
               at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
               at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:81)
               at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
               at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
               at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
               at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
               at org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:39)
               at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:159)
               at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:59)
               at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
               at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
               at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
               at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
               at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
               at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
               at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
               at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
               at java.lang.Thread.run(Thread.java:595)
              


              • 4. Re: BPEL Condition
                aguizar

                I took the chance to incorporate the latest < if> syntax. The entry #237 in the WS-BPEL issues list removed the < then> element from the < if> construct.

                The BpelReader throws NPE because it did not find an activity element as a direct child of . This does not require further checking in the parser code because XML Schema validation detects it. Set the xsi:schemaLocation attribute in your process to enable schema validation:

                <process xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                xsi:schemaLocation="http://schemas.xmlsoap.org/ws/2004/03/business-process/
                http://schemas.xmlsoap.org/ws/2004/03/business-process/">
                ...
                </process>



                • 5. Re: BPEL Condition
                  ncapito

                  Okay so now i am confused. The bpel schema will not parse without the


                  2006-05-17 09:24:01,312 ERROR [org.jbpm.bpel.xml.ProblemHandler] JTMFusion.bpel(52) cvc-complex-type.2.4.a: Invalid content was found starting with element 'empty'. One of '{"http://schemas.xmlsoap.org/ws/2004/03/business-process/":then}' is expected.



                   <if>
                   <condition>
                   "bpel:getVariableData('request','msg')='FUSION1'"</condition>
                   <empty/>
                   <else>
                   <empty/>
                   </else>
                   </if>

                  Do i need a different schema?



                  • 6. Re: BPEL Condition
                    ncapito

                    FYI:


                    <?xml version="1.0" encoding="UTF-8"?>
                    <process name="MyBPEL"
                     xmlns="http://schemas.xmlsoap.org/ws/2004/03/business-process/"
                     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                     xmlns:bpel="http://schemas.xmlsoap.org/ws/2004/03/business-process/"
                     xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                     xsi:schemaLocation="http://schemas.xmlsoap.org/ws/2004/03/business-process/
                     http://schemas.xmlsoap.org/ws/2004/03/business-process/">


                    • 7. Re: BPEL Condition
                      ncapito

                      Is switch no longer supported also? I really can't understand why the SPEC seems so simple yet so hard to piece together? When i try a switch it throws this error:


                      2006-05-17 09:39:40,328 ERROR [org.jbpm.bpel.xml.ProblemHandler] JTMFusion.bpel(48) cvc-complex-type.2.4.a: Invalid content was found starting with element 'switch'. One of '{"http://schemas.xmlsoap.org/ws/2004/03/business-process/":empty, "http://schemas.xmlsoap.org/ws/2004/03/business-process/":invoke, "http://schemas.xmlsoap.org/ws/2004/03/business-process/":receive, "http://schemas.xmlsoap.org/ws/2004/03/business-process/":reply, "http://schemas.xmlsoap.org/ws/2004/03/business-process/":assign, "http://schemas.xmlsoap.org/ws/2004/03/business-process/":validate, "http://schemas.xmlsoap.org/ws/2004/03/business-process/":wait, "http://schemas.xmlsoap.org/ws/2004/03/business-process/":throw, "http://schemas.xmlsoap.org/ws/2004/03/business-process/":rethrow, "http://schemas.xmlsoap.org/ws/2004/03/business-process/":exit, "http://schemas.xmlsoap.org/ws/2004/03/business-process/":flow, "http://schemas.xmlsoap.org/ws/2004/03/business-process/":if, "http://schemas.xmlsoap.org/ws/2004/03/business-process/":while, "http://schemas.xmlsoap.org/ws/2004/03/business-process/":repeatUntil, "http://schemas.xmlsoap.org/ws/2004/03/business-process/":sequence, "http://schemas.xmlsoap.org/ws/2004/03/business-process/":pick, "http://schemas.xmlsoap.org/ws/2004/03/business-process/":scope, "http://schemas.xmlsoap.org/ws/2004/03/business-process/":compensate, "http://schemas.xmlsoap.org/ws/2004/03/business-process/":forEach, "http://schemas.xmlsoap.org/ws/2004/03/business-process/":extensionActivity}' is expected.



                      Is there a document that describes what jboss-bpel extension cover for the bpel SPEC?

                      • 8. Re: BPEL Condition
                        aguizar

                        I just got the latest schema for BPEL 2 and posted it to the CVS repository in directory src/bpel/org/jbpm/bpel/xml/util. However, the element still requires the activity under a subelement.

                        When you work with a specification in progress you must be aware that things can change quickly and dramatically. If you prefer stability, write your document against BPEL 1.1. The namespace for that version is http://schemas.xmlsoap.org/ws/2003/03/business-process/

                        The old switch syntax works as expected there. See the examples shipped with the jBPM BPEL distribution for reference.

                        • 9. Re: BPEL Condition
                          ncapito

                           

                          However, the element still requires the activity under a subelement.


                          Then is still needed? I believe the schema in the 2.0 called bpel_2_0.xsd is the one i am supposed to be using. It refers to a then and when i do not have one it will complain in my ide.

                          In my process:


                          <if>
                           <condition>
                           "bpel:getVariableData('request','msg')='FUSION1'"
                           </condition>
                           <then>
                           <empty />
                           </then>
                           <else>
                           <sequence>
                           <empty />
                           </sequence>
                           </else>
                           </if>


                          Is my code. So with this schema it forces me to use a then? The process is as simple as one can get yet i still get my NPE? I don't feel like anything has been solved? Did we go full circle?



                          • 10. Re: BPEL Condition
                            ncapito

                            So i thank you for your help and i have decided to just go with the Switch statement. The only think left i have to do is get my condition statement working. Right now I am using

                            condition="bpel:getVariableData('request','msg')='FUSION1'"


                            Can someone please help me with comparing strings in conditions?




                            Thanks again.



                            Nick

                            • 11. Re: BPEL Condition
                              ncapito

                              I got it. Thanks for the help. I will post a string bpel example later today for anyone that is interested.

                              • 12. Re: BPEL Condition
                                ncapito

                                Sorry this took so long:
                                Request is just a variable with a string part....

                                <sequence name="SwitchSequence">
                                 <switch name="ExampleSwitch">
                                 <case
                                 condition="bpel:getVariableData('request','msg')='STRING_CASE1'">
                                 <sequence name="Case1">
                                 <assign>
                                 <copy>
                                 <from expression="'PROCESSED'"></from>
                                 <to variable="serviceRequest"
                                 part="String_1" />
                                 </copy>
                                 </assign>
                                 </sequence>
                                 </case>
                                 <otherwise>
                                 <sequence name="OtherCase">
                                 <assign>
                                 <copy>
                                 <from expression="'Default'" />
                                 <to variable="serviceRequest"
                                 part="String_1" />
                                 </copy>
                                 </assign>
                                 </sequence>
                                 </otherwise>
                                 </switch>
                                
                                 </sequence>


                                • 13. Re: BPEL Condition
                                  aguizar

                                  Thanks for sharing your example with the community, Nick. I can't find how the expression in your last post differs from the previous one, tough. Am I missing something?

                                  • 14. Re: BPEL Condition
                                    ncapito

                                    There is a good chance it might not be different. I did add it within a case tag. It was a while ago. The reason I posted was that I could not find a complete switch string example in the docs. So i wanted to just throw one that I knew worked into the community.