0
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Axis2 Enterprise WSDLを使って JavaからForec.comへアクセス

Last updated at Posted at 2018-06-26

nterprise WSDLを元にJavaからSalesforceへアクセスできるライブラリを作成する手順

1. 「開発 > API」リンクよりEnterprise WSDLをダウンロード&enterprise.wsdlの名前で保存

2. wsdlファイルからJavaのクラス群を生成するためのライブラリを準備

・Apache Axis2「axis2-1.3-bin.zip」
入手先:https://archive.apache.org/dist/ws/axis2/1_3/
展開後、lib/以下すべて必要
・force-wsc-34.0.jar
入手先:http://mvnrepository.com/artifact/com.force.api/force-wsc/34.0

・js-1.7R2.jar
入手先:http://mvnrepository.com/artifact/rhino

・ST-4.0.8.jar
入手先:http://www.stringtemplate.org/download/

3. 上記jarファイルをダウンロード後、axis2-1.3/lib/にコピーしてコンパイル

axis2-1.3/bin/以下にenterprise.wsdlを配置してコマンドを実行
$ sh wsdl2java.sh -Eofv -g -uw -u -uri enterprise.wsdl
*Macの場合、環境変数が必要なのでこういうコマンドを実行
export JAVA_HOME=/usr/libexec/java_home -v 1.8

4. 確認

comディレクトリ以下にJavaソース・ファイルが生成される

5. 動作確認

Eclipseで適当なJavaプロジェクトを生成後、上記のjarファイルをすべてクラズパスに入れて次のソースで認証とSOQLの実行ができることを確認

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("xxx@xxx.jp", "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() + "]");
        }
    }
}
0
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?