-Apache Axis2 "axis2-1.3-bin.zip" Where to get it: https://archive.apache.org/dist/ws/axis2/1_3/ After extraction, lib / and everything below is required ・ Force-wsc-34.0.jar Where to get it: http://mvnrepository.com/artifact/com.force.api/force-wsc/34.0
・ Js-1.7R2.jar Where to get it: http://mvnrepository.com/artifact/rhino
・ ST-4.0.8.jar Where to get it: http://www.stringtemplate.org/download/
Place enterprise.wsdl under axis2-1.3 / bin / and execute the command $ sh wsdl2java.sh -Eofv -g -uw -u -uri enterprise.wsdl
Java source files are generated under the com directory
After generating a suitable Java project in Eclipse, put all the above jar files in the clasp path and confirm that you can authenticate and execute SOQL with the following source
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 TestLogin {
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("[email protected]", "xxxx", 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, 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() + "]");
}
}
}
Recommended Posts