2 Replies Latest reply on Jan 28, 2008 12:18 AM by Shefali Agarwal

    How to invoke web-service from Bpel process

    Shefali Agarwal Newbie

      Hello,
      I' working with Eclipse europa and the Eclipse BPEL Designer Runtimes 0.2.0.
      The server is jBoss 4.0.5 GA with jbpm-bpel-1.1.GA.
      I'm developing a very simple bpel process with an invocation to a external web service (the ticket service of the atm example).
      I have the following files:
      ticket.wsdl greet.wsdl greetArtifacts.wsdl greet.bpel greet.bpelex WsClient.java

      Desc of each file
      Ticket.wsdl: interface to ticket web-service
      greet.bpel: process file
      greet.bpelex: bpel extensions file (automatically generated)
      greet.wsdl: interface to bpel process
      greetArtifacts.wsdl: automatically generated
      WsClient.java: Java client program to invoke the service

      Code of each file:

      -----------------------------greet.bpel--------------------------------------------
      <?xml version="1.0" encoding="UTF-8"?>
      <bpws:process exitOnStandardFault="yes" name="greet"
      targetNamespace="http://eclipse.org/bpel/sample"
      xmlns:bpws="http://docs.oasis-open.org/wsbpel/2.0/process/executable"
      xmlns:grt="http://eclipse.org/bpel/sample"
      xmlns:ns="http://eclipse.org/bpel/sampleArtifacts"
      xmlns:tic="http://jbpm.org/examples/ticket" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
      <bpws:import importType="http://schemas.xmlsoap.org/wsdl/"
      location="greet.wsdl" namespace="http://eclipse.org/bpel/sample"/>
      <bpws:import importType="http://schemas.xmlsoap.org/wsdl/"
      location="interface/ticket.wsdl" namespace="http://jbpm.org/examples/ticket"/>
      <bpws:import importType="http://schemas.xmlsoap.org/wsdl/"
      location="greetArtifacts.wsdl" namespace="http://eclipse.org/bpel/sampleArtifacts"/>
      <bpws:import importType="http://schemas.xmlsoap.org/wsdl/"
      location="interface/ticket.wsdl" namespace="http://jbpm.org/examples/ticket"/>
      <bpws:partnerLinks>
      <bpws:partnerLink myRole="greetProvider" name="client" partnerLinkType="grt:greet"/>
      <bpws:partnerLink name="ticket"
      partnerLinkType="ns:Front-Ticket" partnerRole="TicketIssuer"/>
      </bpws:partnerLinks>
      <bpws:variables>
      <bpws:variable messageType="tic:ticketMessage" name="ticketResponse"/>
      <bpws:variable messageType="tic:ticketRequest" name="ticketRequest"/>
      </bpws:variables>
      <bpws:sequence name="main">
      <bpws:receive createInstance="yes" name="receiveInput"
      operation="process" partnerLink="client"
      portType="grt:greet" variable="ticketRequest"/>
      <bpws:invoke inputVariable="ticketRequest" name="CreateTicket"
      operation="createTicket" outputVariable="ticketResponse"
      partnerLink="ticket" portType="tic:TicketIssuer"/>
      <bpws:reply name="replyOutput" operation="process"
      partnerLink="client" portType="grt:greet" variable="ticketResponse"/>
      </bpws:sequence>
      </bpws:process>
      -------------------------------------------------------------------------------------
      ----------------------------------greet.bpelex------------------------------------
      <?xml version="1.0" encoding="ASCII"?>
      <extensionmodel:ExtensionMap xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:extensionmodel="http:///extensionmodel.ecore" xmlns:org.eclipse.bpel.ui.uiextensionmodel="http:///org/eclipse/bpel/ui/uiextensionmodel.ecore" namespace="http://org.eclipse.bpel.ui/">


      <extensionObject xsi:type="org.eclipse.bpel.ui.uiextensionmodel:VariableExtension"/>



      <extensionObject xsi:type="org.eclipse.bpel.ui.uiextensionmodel:VariableExtension"/>



      <extensionObject xsi:type="org.eclipse.bpel.ui.uiextensionmodel:ActivityExtension"/>



      <extensionObject xsi:type="org.eclipse.bpel.ui.uiextensionmodel:ActivityExtension"/>



      <extensionObject xsi:type="org.eclipse.bpel.ui.uiextensionmodel:ActivityExtension"/>



      <extensionObject xsi:type="org.eclipse.bpel.ui.uiextensionmodel:ProcessExtension" modificationStamp="1201170068297"/>



      <extensionObject xsi:type="org.eclipse.bpel.ui.uiextensionmodel:ActivityExtension"/>



      <extensionObject xsi:type="org.eclipse.bpel.ui.uiextensionmodel:CopyExtension"/>

      </extensionmodel:ExtensionMap>
      --------------------------------------------------------------------------------------
      -----------------------------------greet.wsdl---------------------------------------
      <?xml version="1.0"?>
      <definitions name="greet"
      targetNamespace="http://eclipse.org/bpel/sample"
      xmlns:grt="http://eclipse.org/bpel/sample" xmlns:tic="http://jbpm.org/examples/ticket"
      xmlns:plnk="http://docs.oasis-open.org/wsbpel/2.0/plnktype"
      xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
      >



      <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      TYPE DEFINITION - List of types participating in this BPEL process
      The BPEL Designer will generate default request and response types
      but you can define or import any XML Schema type and use them as part
      of the message types.
      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
      <!--


















      -->


      <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      MESSAGE TYPE DEFINITION - Definition of the message types used as
      part of the port type defintions
      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
      <!--

      -->
      <!--







      -->

      <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      PORT TYPE DEFINITION - A port type groups a set of operations into
      a logical service unit.
      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->

      <!-- portType implemented by the greet BPEL process -->








      <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      PARTNER LINK TYPE DEFINITION
      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
      <plnk:partnerLinkType name="greet">
      <plnk:role name="greetProvider" portType="grt:greet"/>
      </plnk:partnerLinkType>


      --------------------------------------------------------------------------------------
      ------------------------------------greetArtifacts.wsdl----------------------------
      <?xml version="1.0" encoding="UTF-8" standalone="no"?>
      <definitions xmlns:plnk="http://docs.oasis-open.org/wsbpel/2.0/plnktype" xmlns:tns="http://eclipse.org/bpel/sampleArtifacts" xmlns:vprop="http://docs.oasis-open.org/wsbpel/2.0/varprop" xmlns:wsdl="http://jbpm.org/examples/ticket" name="greetArtifacts" targetNamespace="http://eclipse.org/bpel/sampleArtifacts" xmlns="http://schemas.xmlsoap.org/wsdl/">

      <plnk:partnerLinkType name="Front-Ticket">
      <plnk:role name="TicketIssuer" portType="wsdl:TicketIssuer"/>
      </plnk:partnerLinkType>

      --------------------------------------------------------------------------------------
      ---------------------------------ticket.wsdl-----------------------------------------
      <?xml version="1.0" encoding="UTF-8"?>
      <definitions targetNamespace="http://jbpm.org/examples/ticket"
      xmlns:tns="http://jbpm.org/examples/ticket" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
      xmlns="http://schemas.xmlsoap.org/wsdl/">


      ticket creation request



      ticket number wrapper




      interface to ticket issuer service


      generate a ticket number, distinct from previous calls





      --------------------------------------------------------------------------------------
      ----------------------------------WsClient.java------------------------------------
      package com.test;

      import java.net.URL;

      import javax.xml.namespace.QName;
      import javax.xml.rpc.Call;
      import javax.xml.rpc.Service;
      import javax.xml.rpc.ServiceFactory;


      public class WsClient
      {
      private static String invokeWS() throws Exception
      {
      Service service;
      String namespace = "http://eclipse.org/bpel/sample";
      //In out case: "http://net.luminis.bpel"

      URL url = new URL("http://ddc1a-01-378:8080/greet/greetProvider?wsdl");
      //Our location: "http://localhost:8080/active-bpel/services/ProofOfConcept?wsdl"

      QName qname = new QName(namespace, "greetService");

      ServiceFactory factory = ServiceFactory.newInstance();
      service = factory.createService(url, qname);

      QName operation = new QName(namespace, "process");
      QName port = new QName(namespace, "greetProviderPort");

      Call call = service.createCall(port, operation);

      return (String) call.invoke(null);
      }

      public static void main(String[] args)
      {
      try {
      System.out.println("Invoke: " + invokeWS() );
      System.out.println("XercesImpl version being used: " + org.apache.xerces.impl.Version.getVersion());

      } catch (Exception e) {
      // System.out.println("An error has occured!");
      //System.out.println(e);
      e.printStackTrace();
      }
      }
      }
      --------------------------------------------------------------------------------------

      The BPEL process is getting deployed but when I try to invoke the process through client program, following exceptions occur in java console:

      java.rmi.ServerException: The service is not in an appropiate state for the requested operation
      at com.sun.xml.rpc.client.StreamingSender._raiseFault(StreamingSender.java:510)
      at com.sun.xml.rpc.client.StreamingSender._send(StreamingSender.java:307)
      at com.sun.xml.rpc.client.dii.CallInvokerImpl.doInvoke(CallInvokerImpl.java:103)
      at com.sun.xml.rpc.client.dii.BasicCall.invoke(BasicCall.java:486)
      at com.test.WsClient.invokeWS(WsClient.java:32)
      at com.test.WsClient.main(WsClient.java:38)


      and following exceptions in jboss console:

      2008-01-25 13:18:41,622 ERROR [org.jbpm.bpel.integration.jms.StartListener] request delivery failed due to non-recoverable exception, giving up
      org.jbpm.bpel.BpelException: no port implements the required port type: portType={http://jbpm.org/examples/ticket}TicketIssuer
      at org.jbpm.bpel.endpointref.SoapEndpointReference.selectPort(SoapEndpointReference.java:97)
      at org.jbpm.bpel.endpointref.SoapEndpointReference.selectPort(SoapEndpointReference.java:52)
      at org.jbpm.bpel.integration.jms.IntegrationControl.createPartnerClient(IntegrationControl.java:258)
      at org.jbpm.bpel.integration.jms.IntegrationControl.getPartnerClient(IntegrationControl.java:239)
      at org.jbpm.bpel.integration.jms.JmsIntegrationService.invoke(JmsIntegrationService.java:172)
      at org.jbpm.bpel.integration.def.InvokeAction.execute(InvokeAction.java:76)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:585)
      at org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.invoke(CGLIBLazyInitializer.java:185)
      at org.jbpm.graph.def.Action$$EnhancerByCGLIB$$d59d8d76.execute()
      at org.jbpm.graph.def.GraphElement.executeAction(GraphElement.java:264)
      at org.jbpm.graph.def.Node.execute(Node.java:339)
      at org.jbpm.bpel.graph.def.Activity.enter(Activity.java:110)
      at org.jbpm.graph.def.Transition.take(Transition.java:151)
      at org.jbpm.graph.def.Node.leave(Node.java:394)
      at org.jbpm.bpel.graph.def.Activity.leave(Activity.java:200)
      at org.jbpm.bpel.graph.basic.Receive.messageReceived(Receive.java:53)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:585)
      at org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.invoke(CGLIBLazyInitializer.java:185)
      at org.jbpm.bpel.graph.basic.Receive$$EnhancerByCGLIB$$952e287.messageReceived()
      at org.jbpm.bpel.integration.def.ReceiveAction.deliverMessage(ReceiveAction.java:99)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:585)
      at org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.invoke(CGLIBLazyInitializer.java:185)
      at org.jbpm.bpel.integration.def.ReceiveAction$$EnhancerByCGLIB$$88609d70.deliverMessage()
      at org.jbpm.bpel.integration.jms.StartListener.deliverRequest(StartListener.java:222)
      at org.jbpm.bpel.integration.jms.StartListener.onMessage(StartListener.java:168)
      at org.jboss.mq.SpyMessageConsumer.run(SpyMessageConsumer.java:696)
      at java.lang.Thread.run(Thread.java:595)


      Please, can someone help me?
      Sorry for the long post and thanks in advance

      Shefali

        • 1. Re: How to invoke web-service from Bpel process
          Alejandro Guizar Master

          Shefali,

          Maybe you did not register the ticket service in the service catalog. To check this, point your browser to http://localhost:8080/jbpm-bpel/partners.jsp and make sure the ticket service is listed there. If you do not see it, you can register it using the form that also appears in that page.

          You can also use Ant to register partner services. Look for target register.partners in the build file of the atm example.

          <target name="register.partners"
           depends="define.register.task"
           description="register partner services">
           <registerpartner baselocation="http://localhost:8080/ticket/ticketIssuer?wsdl" />
           <registerpartner baselocation="http://localhost:8080/account/accountSystem?wsdl" />
          </target>

          Here, the baselocation attribute specifies the absolute location of the WSDL document that describes the partner service. You may want to define this target in your own build file so that partner registration occurs automatically. If you do, remove the registerpartner task for the accountSystem service as you are not using that service.

          • 2. Re: How to invoke web-service from Bpel process
            Shefali Agarwal Newbie

            Thanks Alejandro for your response. It works :)