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 XMLRPC and connect to it using a Java client. These instructions should work from ofbiz r4.0 onwards.

XMLRPC is a simpler and quicker alternative to using SOAP.

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: Create eclipse project

1) Create an eclipse java project.
2) Download ws-xmlrpc, e.g. http://apache.mirror.anlx.net/ws/xmlrpc/apache-xmlrpc-current-bin.zip
3) Unzip ws-xmlrpc
4) In your new eclipse project, set build path to include all the jar files in the ws-xmlrpc distribution lib directory.

Step 3: Create your java client

import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;

import org.apache.xmlrpc.XmlRpcException;
import org.apache.xmlrpc.client.XmlRpcClient;
import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;

public class Main {

	public static void main(String[] args) throws MalformedURLException, XmlRpcException {

	    XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
	    config.setServerURL(new URL("http://127.0.0.1/webtools/control/xmlrpc"));
	    config.setEnabledForExceptions(true);
	    config.setEnabledForExtensions(true);
	   
	    XmlRpcClient client = new XmlRpcClient();
	    client.setConfig(config);
	    
	    Map paramMap = new HashMap();
	    paramMap.put("login.username", "admin");
	    paramMap.put("login.password", "ofbiz");
	    paramMap.put("idToFind", "admin");
	   
	    Object[] params = new Object[]{paramMap};
	    
	    Map result = (Map) client.execute("findPartiesById", params);		
	    
	    System.out.println(result.toString());
	}
}

The output was (formatted for your convenience):

{partiesFound=[Ljava.lang.Object;@13a317a, 
    party={
       lastUpdatedStamp=Thu Dec 24 16:13:31 GMT 2009, 
       preferredCurrencyUomId=null, 
       partyTypeId=PERSON, 
       externalId=null, 
       dataSourceId=null, 
       isUnread=null, 
       statusId=null, 
       createdTxStamp=Thu Dec 24 16:13:30 GMT 2009, 
       lastModifiedByUserLogin=null, 
       createdStamp=Thu Dec 24 16:13:30 GMT 2009, 
       partyId=admin, 
       description=null, 
       lastModifiedDate=null,
       lastUpdatedTxStamp=Thu Dec 24 16:13:31 GMT 2009, 
       createdDate=null, 
       createdByUserLogin=null}}

Other information

Flex 3 / Actionscript 3 client example coming soon...

  • No labels