Can i use Axis2 to write a client for SalesForce API?

Yes. Just run WSDL2Java with the following Options (with the forthcoming Axis2 1.3 Final):

wsdl2java -Eofv -g -uw -u -uri enterprise.wsdl

Notes:

  • -Eofv : tells wsdl2java to be a little lax with the schema validation
  • -g : tells wsdl2java generate all the classes specified in the schema, since usually WSDL2Java with ADB databinding generates only those complextypes / elements that are actually used in the wsdl
  • -uw : Unwrap the parameters, makes it a little bit easier to write code
  • -u : Unpacks the databinding classes, since by default when generating clients WSDL2Java generates all data types in the same Stub class
  • -uri : location of the wsdl

 

Here's some sample code:

import com.sforce.soap.enterprise.LoginResult;
import com.sforce.soap.enterprise.QueryResult;
import com.sforce.soap.enterprise.SessionHeader;
import com.sforce.soap.enterprise.SforceServiceStub;
import com.sforce.soap.enterprise.sobject.Account;
import com.sforce.soap.enterprise.sobject.SObject;

import org.apache.axis2.client.Options;
import org.apache.axis2.transport.http.HTTPConstants;


public class Main {
public static void main(String[] args) throws Exception {
SforceServiceStub stub = new SforceServiceStub();
Options options = stub._getServiceClient().getOptions();
options.setProperty(HTTPConstants.MC_ACCEPT_GZIP, Boolean.TRUE);
options.setProperty(HTTPConstants.MC_GZIP_REQUEST, Boolean.TRUE);

LoginResult lr = stub.login("my@gmail.com", "abcdef", null);

SessionHeader sh = new SessionHeader();
sh.setSessionId(lr.getSessionId());

stub = new SforceServiceStub(lr.getServerUrl());
options = stub._getServiceClient().getOptions();
options.setProperty(HTTPConstants.MC_ACCEPT_GZIP, Boolean.TRUE);
options.setProperty(HTTPConstants.MC_GZIP_REQUEST, Boolean.TRUE);

QueryResult qr = stub.query("select Name, numberOfEmployees, Id, Industry from Account",
sh, null, null);

System.out.println("Query has " + qr.getSize() + " records total");

SObject[] sObjects = qr.getRecords();

for (int i = 0; i < sObjects.length; i++) {
Account sObject = (Account) sObjects[i];
System.out.println(i + "\t: [" + sObject.getId() + "][" +
sObject.getName() + "]");
}
}
}
 

Here's the sample output:

C:\axis2-1.3\sforce\client>java Main
Query has 13 records total
0 : [0017000000Kn04OAAR][GenePoint]
1 : [0017000000Kn04PAAR][United Oil & Gas, UK]
2 : [0017000000Kn06qAAB][United Oil & Gas, Singapore]
3 : [0017000000Kn06rAAB][Edge Communications]
4 : [0017000000Kn06sAAB][Burlington Textiles Corp of America]
5 : [0017000000Kn06tAAB][Pyramid Construction Inc.]
6 : [0017000000Kn06uAAB][Dickenson plc]
7 : [0017000000Kn06vAAB][Grand Hotels & Resorts Ltd]
8 : [0017000000Kn06wAAB][Express Logistics and Transport]
9 : [0017000000Kn06xAAB][University of Arizona]
10 : [0017000000Kn06yAAB][United Oil & Gas Corp.]
11 : [0017000000Kn06zAAB][sForce]
12 : [0017000000KmzIhAAJ][ABCED]
library project main code
Learn Cloud
Learn
Cloud

The WSO2 Application Server is a reliable application server that can host your enterprise web applications. The WSO2 Application Server as a Service is offered in StratosLive, the WSO2 Platform as a Service. This article explains how a simple web application can be developed and deployed from Carbon Studio to the WSO2 Application Server...

Latest Webinar
Different groups within an organization need to monitor different Key Performance Indicators (KPIs) - An operations team will be interested in the response times of business services and loads of each service,..
Thursday, February 9th 2012, 09.00 AM (PST)

Thursday, February 9th 2012, 10.00 AM (GMT)