1 Reply Latest reply on Nov 18, 2008 5:09 PM by kw_richards

    Expose service via web service

    kw_richards

      Hi,

      I'm trying to expose a service via a web service. What I'm attempting is different to the quickstart examples (e.g. webservice_producer, webservice_bpel). These quickstart only expose a function (method) via a web service to the ESB, but DOES NOT invoke other actions/services in the ESB.

      Assume I want to expose the following "interface" (method signature) to the outside world.

      public OrderResult ProcessEquipmentOrder (Order orderDetail)

      What I'd like to do is use the ESB action pipeline to perform some actions.
      1. Validate the order
      2. Calculate the order

      A snippet of the jboss-esb.xml might illustrate what I'm trying to do

      ====== snippet ===========
       <service category="OrderProcessor" name="EquipmentOrder" description="Process Equipment orders">
      
       <listeners>
       <jbr-listener name="Http-Gateway" busidref="Http-1" is-gateway="true"/>
       </listeners>
       <actions>
       <action name="JBossWSAdapter" class="org.jboss.soa.esb.actions.soap.SOAPProcessor">
       <property name="jbossws-endpoint" value="processEquipmentOrder"/>
       </action>
       <action name="validate" class="com.example.ValidateOrder"/>
       <action name="calculateOrder" class="com.example.CalculateOrder"/>
       </actions>
       </service>
       </services>
      ===== snippet =========
      


      Without the ESB, i'd typically code the web service as follows (simplistically)
      public class OrderProcessorWS
      {
       public OrderResult processEquipmentOrder (Order orderDetail)
       {
       return new OrderProcessor.processEquipmentOrder( orderDetail);
       }
      
      }
      
      public class OrderProcessor
      {
       public OrderResult processEquipmentOrder (Order orderDetail)
       {
       if (!Validator.validate( orderDetail))
       {
       return new OrderResult( "invalid");
       }
      
       double cost= Calculator.calculatePrice( orderDetail);
       return new OrderDetail( cost);
       }
      }
      

      How do I thus create a web service which will serve as an entrypoint into the action pipeline.

      Thanks

        • 1. Re: Expose service via web service
          kw_richards

          I found the answer to the question, and it's actually fairly obvious (once you reach 12 at night)
          The trick is in using ServiceInvoker from within the webservice.

          Define the jboss-esb.xml as follows (I.e. expose a web service as per quickstart webservice_producer)

          ...
          <service category="OrderProcessor" name="EquipmentOrderInterface" description="Process Equipment orders">
           <listeners>
           <jbr-listener name="Http-Gateway" busidref="Http-1" is-gateway="true"/>
           </listeners>
           <actions>
           <action name="JBossWSAdapter" class="org.jboss.soa.esb.actions.soap.SOAPProcessor">
           <property name="jbossws-endpoint" value="processEquipmentOrder"/>
           </action>
           </actions>
          </service>
          
          <service category="OrderProcessor" name="EquipmentOrderImpl" description="Process Equipment orders">
           <actions>
           <action name="validate" class="com.example.ValidateOrder"/>
           <action name="calculateOrder" class="com.example.CalculateOrder"/>
           </actions>
          </service>
          


          Then write the webservice as follows (using the QuickStart webservice_producer as a general guideline)
          public class OrderProcessorWS
          {
           public OrderResult processEquipmentOrder (Order orderDetail)
           {
           ServiceInvoker service= new ServiceInvoker("OrderProcessor", "EquipmentOrderImpl");
           Message reqMsg= MessageFactory.getInstance().getMessage();
           reqMsg.getBody().add( orderDetail);
          
           Message respMsg= service.deliverSync( reqMsg, 50000);
           return (OrderResult)respMsg.getBody().get();
           }
          
          }
          


          Now you've effectively "wrapped" your esb service in a web service.