Access to add and change pages is restricted. See: https://cwiki.apache.org/confluence/display/OFBIZ/Wiki+access


This page documents how to export a service using SOAP. This is relevant only since revision 892712

Note: I have been able to make successful calls using client code generated from the WSDL in java, but not from C# nor flex 3/actionscript 3 so far (see https://issues.apache.org/jira/browse/OFBIZ-3385)

As I have not been able to make a call using generated client code, I have gone for the dynamically generated client using AXIOM. To find out about AXIOM, I read Chapter 3 and Chapter 9 from http://www.packtpub.com/creating-web-services-with-apache-axis-2/book, however, there are probably free tutorials available online.

UPDATE: since r896347, I am now able to use jax-ws (in Netbeans) to generate the client code to connect to ofbiz. See https://issues.apache.org/jira/browse/OFBIZ-3385 for example code.

Step 1: export service

In the service definition, set the flag export="true", for example the findPartiesById service:

<service name="findPartiesById" engine="java" auth="true"
 location="org.ofbiz.party.party.PartyServices" invoke="findPartyById" export="true">
 <description>Find the partyId corresponding to a reference and a reference type</description>
 <attribute type="String" mode="IN" name="idToFind" optional="false"/>
 <attribute type="String" mode="IN" name="partyIdentificationTypeId" optional="true"/>
 <attribute type="String" mode="IN" name="searchPartyFirst" optional="true"/>
 <attribute type="String" mode="IN" name="searchAllId" optional="true"/>
 <attribute type="org.ofbiz.entity.GenericValue" mode="OUT" name="party" optional="true"/>
 <attribute type="List" mode="OUT" name="partiesFound" optional="true"/>
</service>

Step 2: view the WSDL

To see all the exported services: http://demo-trunk.ofbiz.apache.org/webtools/control/SOAPService?wsdl
To see SOAP services https://demo-trunk.ofbiz.apache.org/webtools/control/ServiceList?constraint=engine_name@soap (credentials: flexadmin/ofbiz)
To view the WSDL for the findPartiesById service: http://demo-trunk.ofbiz.apache.org/webtools/control/SOAPService/findPartiesById?wsdl

I would recommend studying the WSDL for the service, as it documents the AXIOM model you need to later create.

Step 3: Create eclipse project

1) Create an eclipse java project.
2) Download axis2, e.g. http://mirrors.dedipower.com/ftp.apache.org/ws/axis2/1_5_1/axis2-1.5.1-bin.zip
3) Unzip axis2
4) In your new eclipse project, set build path to include all the jar files in the axis distribution lib directory. (you don't need all the jars, but this is a quick howto)

Step 4: Create your axis client

import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMAttribute;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMFactory;
import org.apache.axiom.om.OMNamespace;
import org.apache.axis2.AxisFault;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.client.ServiceClient;

public class Main {

   private static OMFactory fac;
   private static OMNamespace omNs;

   static {
      fac = OMAbstractFactory.getOMFactory();
      omNs = fac.createOMNamespace("http://ofbiz.apache.org/service/", "ns1");
   }

   public static void main(String[] args) throws AxisFault {

      ServiceClient sc = new ServiceClient();
      Options opts = new Options();
      opts.setTo(new EndpointReference(
         "http://demo-trunk.ofbiz.apache.org//webtools/control/SOAPService"));
      opts.setAction("findPartiesById");
      sc.setOptions(opts);
      OMElement res = sc.sendReceive(createPayLoad());
      System.out.println(res);
   }

   private static OMElement createPayLoad() {

      OMElement findPartiesById = fac.createOMElement("findPartiesById", omNs);
      OMElement mapMap = fac.createOMElement("map-Map", omNs);

      findPartiesById.addChild(mapMap);

      mapMap.addChild(createMapEntry("idToFind", "admin"));
      mapMap.addChild(createMapEntry("login.username", "admin"));
      mapMap.addChild(createMapEntry("login.password", "ofbiz"));

      return findPartiesById;
   }

   private static OMElement createMapEntry(String key, String val) {

      OMElement mapEntry = fac.createOMElement("map-Entry", omNs);

      // create the key
      OMElement mapKey = fac.createOMElement("map-Key", omNs);
      OMElement keyElement = fac.createOMElement("std-String", omNs);
      OMAttribute keyAttribute = fac.createOMAttribute("value", null, key);

      mapKey.addChild(keyElement);
      keyElement.addAttribute(keyAttribute);

      // create the value
      OMElement mapValue = fac.createOMElement("map-Value", omNs);
      OMElement valElement = fac.createOMElement("std-String", omNs);
      OMAttribute valAttribute = fac.createOMAttribute("value", null, val);

      mapValue.addChild(valElement);
      valElement.addAttribute(valAttribute);

      // attach to map-Entry
      mapEntry.addChild(mapKey);
      mapEntry.addChild(mapValue);

      return mapEntry;
   }
}

The output was:

<axis2ns17:findPartiesByIdResponse xmlns:axis2ns17="http://ofbiz.apache.org/service/"><map-Map>
        <map-Entry>
            <map-Key>
                <std-String value="responseMessage" />
            </map-Key>
            <map-Value>
                <std-String value="success" />
            </map-Value>
        </map-Entry>
        <map-Entry>
            <map-Key>
                <std-String value="party" />
            </map-Key>
            <map-Value>
                <eeval-Party createdStamp="2009-12-24 16:13:30.949" createdTxStamp="2009-12-24 16:13:30.946" lastUpdatedStamp="2009-12-24 16:13:31.892" lastUpdatedTxStamp="2009-12-24 16:13:31.553" partyId="admin" partyTypeId="PERSON" />
            </map-Value>
        </map-Entry>
        <map-Entry>
            <map-Key>
                <std-String value="partiesFound" />
            </map-Key>
            <map-Value>
                <col-Collection />
            </map-Value>
        </map-Entry>
    </map-Map></axis2ns17:findPartiesByIdResponse>
  • No labels