我浏览了salesforce SOAP API quick start中的示例代码,但我得到的是第一个登录阶段的超时错误。我创建了一个开发人员登录并生成了wsdl,然后生成了.jar。该程序编译。我正在尝试使用我在其他地方找到的以下示例:
import com.sforce.soap.enterprise.Connector;
import com.sforce.soap.enterprise.EnterpriseConnection;
import com.sforce.ws.ConnectionException;
import com.sforce.ws.ConnectorConfig;
public class Main {
static final String USERNAME = "username redacted";
static final String PASSWORD = "password redacted";
static final String AUTH = "https://login.salesforce.com/services/Soap/c/37.0/0DF58000000L2Vm";
static EnterpriseConnection connection;
public static void main(String[] args) {
ConnectorConfig config = new ConnectorConfig();
config.setUsername(USERNAME);
config.setPassword(PASSWORD);
config.setAuthEndpoint(AUTH);
try {
connection = 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());
} catch (ConnectionException e1) {
e1.printStackTrace();
}
}
}
但是当我运行它时,它会挂起很长时间然后给出一个ConnectException:Connection超时
com.sforce.ws.ConnectionException: Failed to send request to https://login.salesforce.com/services/Soap/c/37.0/0DF58000000L2Vm
at com.sforce.ws.transport.SoapConnection.send(SoapConnection.java:121)
at com.sforce.soap.enterprise.EnterpriseConnection.login(EnterpriseConnection.java:1207)
at com.sforce.soap.enterprise.EnterpriseConnection.<init>(EnterpriseConnection.java:386)
at com.sforce.soap.enterprise.Connector.newConnection(Connector.java:27)
at Main.main(Main.java:18)
Caused by: java.net.ConnectException: Connection timed out
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:579)
at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:637)
at sun.security.ssl.BaseSSLSocketImpl.connect(BaseSSLSocketImpl.java:160)
at sun.net.NetworkClient.doConnect(NetworkClient.java:180)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:432)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:527)
at sun.net.www.protocol.https.HttpsClient.<init>(HttpsClient.java:264)
at sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:367)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConnection.java:191)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:977)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:177)
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:1093)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:250)
at com.sforce.ws.transport.JdkHttpTransport.connectRaw(JdkHttpTransport.java:136)
at com.sforce.ws.transport.JdkHttpTransport.connectLocal(JdkHttpTransport.java:100)
at com.sforce.ws.transport.JdkHttpTransport.connectLocal(JdkHttpTransport.java:95)
at com.sforce.ws.transport.JdkHttpTransport.connect(JdkHttpTransport.java:91)
at com.sforce.ws.transport.SoapConnection.send(SoapConnection.java:95)
... 4 more
我已经使用wireshark和我的系统管理员检查了它不是防火墙:DNS查找正确解析'login.salesforce.com'并且肯定有包出去。还有什么我可能做错了?
答案 0 :(得分:0)
如果您使用-Dhttps.protocols=TLSv1.1,TLSv1.2
,则可以在运行jar时尝试使用jdk 1.7
。
Jdk 1.8兼容TLSv1.1,TLSv1.2所以你也可以使用它
我遇到了同样的问题,我通过传递httpsprotocols解决了这个问题。
如果这对您有用,请告诉我