0

我正在尝试从 java 类(在我的本地计算机上)连接到 Salesforce。我使用了 WSC-22.jar(webservice 连接器)并使用了与 eclipse 中的库相同的内容。我还将企业 wsdl 解析为 jar 并在 eclipse 中上传了库。我正在运行下面的 java 类,这是错误的。

package wsc;

import com.sforce.soap.enterprise.Connector;
import com.sforce.soap.enterprise.DeleteResult;
import com.sforce.soap.enterprise.EnterpriseConnection;
import com.sforce.soap.enterprise.Error;
import com.sforce.soap.enterprise.QueryResult;
import com.sforce.soap.enterprise.SaveResult;
import com.sforce.soap.enterprise.sobject.Account;
import com.sforce.soap.enterprise.sobject.Contact;
import com.sforce.ws.ConnectionException;
import com.sforce.ws.ConnectorConfig;

public class main {

static final String USERNAME = "username";
static final String PASSWORD = "password + sec token";
static EnterpriseConnection connection;

public static void main(String[] args) {

ConnectorConfig config = new ConnectorConfig();
config.setUsername(USERNAME);
config.setPassword(PASSWORD);
//config.setTraceMessage(true);

try {

  connection = com.sforce.soap.enterprise.Connector.newConnection(config);

  // display some current settings
  System.out.println("Auth EndPoint: "+config.getAuthEndpoint());
  System.out.println("Service EndPoint: "+config.getServiceEndpoint());
  System.out.println("Username: "+config.getUsername());
  System.out.println("SessionId: "+config.getSessionId());

  // run the different examples
  queryContacts();
  createAccounts();
  updateAccounts();
  deleteAccounts();


} catch (ConnectionException e1) {
    System.out.println("hello world");
    e1.printStackTrace();
}  

}
//somemore code----

错误消息:com.sforce.ws.ConnectionException:发送请求失败

https://login.salesforce.com/services/Soap/c/26.0
    at com.sforce.ws.transport.SoapConnection.send(SoapConnection.java:120)
    at com.sforce.soap.enterprise.EnterpriseConnection.login(EnterpriseConnection.java:1)
    at com.sforce.soap.enterprise.EnterpriseConnection.<init>(EnterpriseConnection.java:1)
    at com.sforce.soap.enterprise.Connector.newConnection(Connector.java:1)
    at wsc.main.main(main.java:32)
Caused by: java.net.ConnectException: Connection refused: connect
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:351)hello world

    at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:213)
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:200)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
    at java.net.Socket.connect(Socket.java:529)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:570)
at com.sun.net.ssl.internal.ssl.BaseSSLSocketImpl.connect(BaseSSLSocketImpl.java:141)
at sun.net.NetworkClient.doConnect(NetworkClient.java:163)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:411)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:525)
at sun.net.www.protocol.https.HttpsClient.<init>(HttpsClient.java:272)
at sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:329)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConnection.java:172)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:966)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:158)
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:1031)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:230)
at com.sforce.ws.transport.JdkHttpTransport.connectRaw(JdkHttpTransport.java:133)
at com.sforce.ws.transport.JdkHttpTransport.connectLocal(JdkHttpTransport.java:97)
at com.sforce.ws.transport.JdkHttpTransport.connectLocal(JdkHttpTransport.java:92)
at com.sforce.ws.transport.JdkHttpTransport.connect(JdkHttpTransport.java:88)
at com.sforce.ws.transport.SoapConnection.send(SoapConnection.java:94)

我无法弄清楚如何解决这个问题。由于错误消息显示“无法连接到http://login.salesforce.com./ ...”,我是否应该在 Eclipse 中启用某些设置?

问候山姆

4

2 回答 2

1

你在代理后面吗?

如果是这样,请在 eclipse 中启用代理设置preferences generalnetwork

于 2013-02-08T10:54:35.953 回答
-1

...

  String proxyHost = getUserInput("Enter proxy host:");
  String proxyPort = getUserInput("Enter proxy port:");

  try {

...

     if(proxyHost!=null && !proxyHost.trim().equals("")){
      config.setProxy(proxyHost, Integer.valueOf(proxyPort));
     }

...

于 2015-10-09T03:08:00.637 回答