【feat】 优化ORG连接问题
This commit is contained in:
parent
24474a2c8a
commit
b4607439a3
@ -18,6 +18,7 @@ import java.util.HashMap;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Red
|
* @author Red
|
||||||
@ -31,45 +32,57 @@ public class SalesforceConnect {
|
|||||||
@Resource
|
@Resource
|
||||||
private CustomMapper customerMapper;
|
private CustomMapper customerMapper;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建连接
|
* 创建连接
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public PartnerConnection createConnect() {
|
public PartnerConnection createConnect() {
|
||||||
try {
|
int failCount = 0;
|
||||||
List<Map<String, Object>> poll = customerMapper.list("code,value","org_config",null);
|
//重试连接次数
|
||||||
//遍历poll,找出code值为SOURCE_ORG_URL,SOURCE_ORG_USERNAME,SOURCE_ORG_PASSWORD的value值
|
while (true){
|
||||||
Map<String, String> map = new HashMap<>();
|
try {
|
||||||
for (Map<String, Object> map1 : poll) {
|
List<Map<String, Object>> poll = customerMapper.list("code,value","org_config",null);
|
||||||
if ("SOURCE_ORG_URL".equals(map1.get("code"))) {
|
//遍历poll,找出code值为SOURCE_ORG_URL,SOURCE_ORG_USERNAME,SOURCE_ORG_PASSWORD的value值
|
||||||
map.put("url", (String) map1.get("value"));
|
Map<String, String> map = new HashMap<>();
|
||||||
|
for (Map<String, Object> map1 : poll) {
|
||||||
|
if ("SOURCE_ORG_URL".equals(map1.get("code"))) {
|
||||||
|
map.put("url", (String) map1.get("value"));
|
||||||
|
}
|
||||||
|
if ("SOURCE_ORG_USERNAME".equals(map1.get("code"))) {
|
||||||
|
map.put("username", (String) map1.get("value"));
|
||||||
|
}
|
||||||
|
if ("SOURCE_ORG_PASSWORD".equals(map1.get("code"))) {
|
||||||
|
map.put("password", String.valueOf(map1.get("value")));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if ("SOURCE_ORG_USERNAME".equals(map1.get("code"))) {
|
|
||||||
map.put("username", (String) map1.get("value"));
|
String username = map.get("username");
|
||||||
|
ConnectorConfig config = new ConnectorConfig();
|
||||||
|
config.setUsername(username);
|
||||||
|
config.setPassword(map.get("password"));
|
||||||
|
String url = map.get("url");
|
||||||
|
config.setAuthEndpoint(url);
|
||||||
|
config.setServiceEndpoint(url);
|
||||||
|
config.setConnectionTimeout(60 * 60 * 1000);
|
||||||
|
config.setReadTimeout(60 * 60 * 1000);
|
||||||
|
return new PartnerConnection(config);
|
||||||
|
} catch (ConnectionException e) {
|
||||||
|
failCount ++;
|
||||||
|
log.error("源ORG连接异常!休眠一分钟再次发起重试~~", e);
|
||||||
|
try {
|
||||||
|
TimeUnit.MINUTES.sleep(1);
|
||||||
|
}catch (InterruptedException ie) {
|
||||||
|
log.error("休眠异常", ie);
|
||||||
}
|
}
|
||||||
if ("SOURCE_ORG_PASSWORD".equals(map1.get("code"))) {
|
if (failCount > 3) {
|
||||||
map.put("password", String.valueOf(map1.get("value")));
|
String message = "源ORG三次重试连接错误!";
|
||||||
|
String format = String.format("ORG连接异常!, \ncause:\n%s", message);
|
||||||
|
EmailUtil.send("DataDump ERROR", format);
|
||||||
|
log.error("exception message", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String username = map.get("username");
|
|
||||||
ConnectorConfig config = new ConnectorConfig();
|
|
||||||
config.setUsername(username);
|
|
||||||
config.setPassword(map.get("password"));
|
|
||||||
String url = map.get("url");
|
|
||||||
config.setAuthEndpoint(url);
|
|
||||||
config.setServiceEndpoint(url);
|
|
||||||
config.setConnectionTimeout(60 * 60 * 1000);
|
|
||||||
config.setReadTimeout(60 * 60 * 1000);
|
|
||||||
return new PartnerConnection(config);
|
|
||||||
} catch (ConnectionException e) {
|
|
||||||
String message = "源ORG连接配置错误!";
|
|
||||||
String format = String.format("ORG连接异常!, \ncause:\n%s", message);
|
|
||||||
EmailUtil.send("DataDump ERROR", format);
|
|
||||||
log.error("exception message", e);
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -77,41 +90,38 @@ public class SalesforceConnect {
|
|||||||
* @author kris
|
* @author kris
|
||||||
*/
|
*/
|
||||||
public BulkConnection createBulkConnect() {
|
public BulkConnection createBulkConnect() {
|
||||||
try {
|
int failCount = 0;
|
||||||
List<Map<String, Object>> poll = customerMapper.list("code,value","org_config",null);
|
while (true){
|
||||||
//遍历poll,找出code值为SOURCE_ORG_URL,SOURCE_ORG_USERNAME,SOURCE_ORG_PASSWORD的value值
|
try {
|
||||||
Map<String, String> map = new HashMap<>();
|
List<Map<String, Object>> poll = customerMapper.list("code,value","org_config",null);
|
||||||
for (Map<String, Object> map1 : poll) {
|
//遍历poll,找出code值为SOURCE_ORG_URL,SOURCE_ORG_USERNAME,SOURCE_ORG_PASSWORD的value值
|
||||||
if ("SOURCE_ORG_URL".equals(map1.get("code"))) {
|
Map<String, String> map = new HashMap<>();
|
||||||
map.put("url", (String) map1.get("value"));
|
for (Map<String, Object> map1 : poll) {
|
||||||
|
if ("SOURCE_ORG_URL".equals(map1.get("code"))) {
|
||||||
|
map.put("url", (String) map1.get("value"));
|
||||||
|
}
|
||||||
|
if ("SOURCE_ORG_USERNAME".equals(map1.get("code"))) {
|
||||||
|
map.put("username", (String) map1.get("value"));
|
||||||
|
}
|
||||||
|
if ("SOURCE_ORG_PASSWORD".equals(map1.get("code"))) {
|
||||||
|
map.put("password", String.valueOf(map1.get("value")));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if ("SOURCE_ORG_USERNAME".equals(map1.get("code"))) {
|
return BulkUtil.getBulkConnection(map.get("username"),map.get("password"),map.get("url"));
|
||||||
map.put("username", (String) map1.get("value"));
|
} catch (Exception e) {
|
||||||
}
|
failCount ++;
|
||||||
if ("SOURCE_ORG_PASSWORD".equals(map1.get("code"))) {
|
log.error("源ORG连接异常!休眠一分钟再次发起重试~~", e);
|
||||||
map.put("password", String.valueOf(map1.get("value")));
|
try {
|
||||||
|
TimeUnit.MINUTES.sleep(1);
|
||||||
|
}catch (InterruptedException ie) {
|
||||||
|
log.error("休眠异常", ie);
|
||||||
|
} if (failCount > 3) {
|
||||||
|
String message = "源ORG三次重试连接错误!";
|
||||||
|
String format = String.format("ORG连接异常!, \ncause:\n%s", message);
|
||||||
|
EmailUtil.send("DataDump ERROR", format);
|
||||||
|
log.error("exception message", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//
|
|
||||||
// String username = map.get("username");
|
|
||||||
// ConnectorConfig config = new ConnectorConfig();
|
|
||||||
// config.setUsername(username);
|
|
||||||
// config.setPassword(map.get("password"));
|
|
||||||
// String url = map.get("url");
|
|
||||||
// config.setAuthEndpoint(url);
|
|
||||||
// config.setServiceEndpoint(url);
|
|
||||||
// config.setConnectionTimeout(60 * 60 * 1000);
|
|
||||||
// config.setReadTimeout(60 * 60 * 1000);
|
|
||||||
// PartnerConnection connection = new PartnerConnection(config);
|
|
||||||
// config.setRestEndpoint(url);
|
|
||||||
// config.setSessionId(connection.getSessionHeader().getSessionId());
|
|
||||||
return BulkUtil.getBulkConnection(map.get("username"),map.get("password"),map.get("url"));
|
|
||||||
} catch (Exception e) {
|
|
||||||
String message = "源ORG连接配置错误!";
|
|
||||||
String format = String.format("ORG连接异常!, \ncause:\n%s", message);
|
|
||||||
EmailUtil.send("DataDump ERROR", format);
|
|
||||||
log.error("exception message", e);
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -18,6 +18,7 @@ import java.util.HashMap;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@ -30,42 +31,56 @@ public class SalesforceTargetConnect {
|
|||||||
* 创建连接
|
* 创建连接
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public PartnerConnection createConnect() {
|
public PartnerConnection createConnect() {
|
||||||
try {
|
int failCount = 0;
|
||||||
List<Map<String, Object>> poll = customerMapper.list("code,value","org_config",null);
|
//重试连接次数
|
||||||
//遍历poll,找出code值为TARGET_ORG_URL,TARGET_ORG_USERNAME,TARGET_ORG_PASSWORD的value值
|
while (true){
|
||||||
Map<String, String> map = new HashMap<>();
|
try {
|
||||||
for (Map<String, Object> map1 : poll) {
|
List<Map<String, Object>> poll = customerMapper.list("code,value","org_config",null);
|
||||||
if ("TARGET_ORG_URL".equals(map1.get("code"))) {
|
//遍历poll,找出code值为TARGET_ORG_URL,TARGET_ORG_USERNAME,TARGET_ORG_PASSWORD的value值
|
||||||
map.put("url", (String) map1.get("value"));
|
Map<String, String> map = new HashMap<>();
|
||||||
|
for (Map<String, Object> map1 : poll) {
|
||||||
|
if ("TARGET_ORG_URL".equals(map1.get("code"))) {
|
||||||
|
map.put("url", (String) map1.get("value"));
|
||||||
|
}
|
||||||
|
if ("TARGET_ORG_USERNAME".equals(map1.get("code"))) {
|
||||||
|
map.put("username", (String) map1.get("value"));
|
||||||
|
}
|
||||||
|
if ("TARGET_ORG_PASSWORD".equals(map1.get("code"))) {
|
||||||
|
map.put("password", (String) map1.get("value"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if ("TARGET_ORG_USERNAME".equals(map1.get("code"))) {
|
|
||||||
map.put("username", (String) map1.get("value"));
|
|
||||||
}
|
|
||||||
if ("TARGET_ORG_PASSWORD".equals(map1.get("code"))) {
|
|
||||||
map.put("password", (String) map1.get("value"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
String username = map.get("username");
|
String username = map.get("username");
|
||||||
ConnectorConfig config = new ConnectorConfig();
|
ConnectorConfig config = new ConnectorConfig();
|
||||||
config.setUsername(username);
|
config.setUsername(username);
|
||||||
config.setPassword(map.get("password"));
|
config.setPassword(map.get("password"));
|
||||||
String url = map.get("url");
|
String url = map.get("url");
|
||||||
config.setAuthEndpoint(url);
|
config.setAuthEndpoint(url);
|
||||||
config.setServiceEndpoint(url);
|
config.setServiceEndpoint(url);
|
||||||
config.setConnectionTimeout(60 * 60 * 1000);
|
config.setConnectionTimeout(60 * 60 * 1000);
|
||||||
config.setReadTimeout(60 * 60 * 1000);
|
config.setReadTimeout(60 * 60 * 1000);
|
||||||
PartnerConnection connection = new PartnerConnection(config);
|
PartnerConnection connection = new PartnerConnection(config);
|
||||||
String orgId = connection.getUserInfo().getOrganizationId();
|
String orgId = connection.getUserInfo().getOrganizationId();
|
||||||
return connection;
|
return connection;
|
||||||
} catch (ConnectionException e) {
|
} catch (ConnectionException e) {
|
||||||
String message = "目标ORG连接配置错误!";
|
failCount++;
|
||||||
String format = String.format("ORG连接异常!, \ncause:\n%s", message);
|
log.error("目标ORG连接异常!休眠一分钟再次发起重试~~", e);
|
||||||
EmailUtil.send("DataDump ERROR", format);
|
try {
|
||||||
log.error("exception message", e);
|
TimeUnit.MINUTES.sleep(1);
|
||||||
return null;
|
}catch (InterruptedException ie) {
|
||||||
|
log.error("休眠异常", ie);
|
||||||
|
} if (failCount > 3) {
|
||||||
|
String message = "目标ORG三次重试连接错误!";
|
||||||
|
String format = String.format("ORG连接异常!, \ncause:\n%s", message);
|
||||||
|
EmailUtil.send("DataDump ERROR", format);
|
||||||
|
log.error("exception message", e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -73,42 +88,40 @@ public class SalesforceTargetConnect {
|
|||||||
* @author kris
|
* @author kris
|
||||||
*/
|
*/
|
||||||
public BulkConnection createBulkConnect() {
|
public BulkConnection createBulkConnect() {
|
||||||
try {
|
int failCount = 0;
|
||||||
List<Map<String, Object>> poll = customerMapper.list("code,value","org_config",null);
|
while (true){
|
||||||
//遍历poll,找出code值为TARGET_ORG_URL,TARGET_ORG_USERNAME,TARGET_ORG_PASSWORD的value值
|
//重试连接次数
|
||||||
Map<String, String> map = new HashMap<>();
|
try {
|
||||||
for (Map<String, Object> map1 : poll) {
|
List<Map<String, Object>> poll = customerMapper.list("code,value","org_config",null);
|
||||||
if ("TARGET_ORG_URL".equals(map1.get("code"))) {
|
//遍历poll,找出code值为TARGET_ORG_URL,TARGET_ORG_USERNAME,TARGET_ORG_PASSWORD的value值
|
||||||
map.put("url", (String) map1.get("value"));
|
Map<String, String> map = new HashMap<>();
|
||||||
|
for (Map<String, Object> map1 : poll) {
|
||||||
|
if ("TARGET_ORG_URL".equals(map1.get("code"))) {
|
||||||
|
map.put("url", (String) map1.get("value"));
|
||||||
|
}
|
||||||
|
if ("TARGET_ORG_USERNAME".equals(map1.get("code"))) {
|
||||||
|
map.put("username", (String) map1.get("value"));
|
||||||
|
}
|
||||||
|
if ("TARGET_ORG_PASSWORD".equals(map1.get("code"))) {
|
||||||
|
map.put("password", (String) map1.get("value"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if ("TARGET_ORG_USERNAME".equals(map1.get("code"))) {
|
return BulkUtil.getBulkConnection(map.get("username"),map.get("password"),map.get("url"));
|
||||||
map.put("username", (String) map1.get("value"));
|
} catch (Exception e) {
|
||||||
}
|
failCount++;
|
||||||
if ("TARGET_ORG_PASSWORD".equals(map1.get("code"))) {
|
log.error("目标ORG连接异常!休眠一分钟再次发起重试~~", e);
|
||||||
map.put("password", (String) map1.get("value"));
|
try {
|
||||||
|
TimeUnit.MINUTES.sleep(1);
|
||||||
|
}catch (InterruptedException ie) {
|
||||||
|
log.error("休眠异常", ie);
|
||||||
|
} if (failCount > 3) {
|
||||||
|
String message = "目标ORG三次重试连接错误!";
|
||||||
|
String format = String.format("ORG连接异常!, \ncause:\n%s", message);
|
||||||
|
EmailUtil.send("DataDump ERROR", format);
|
||||||
|
log.error("exception message", e);
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// String username = ;
|
|
||||||
// ConnectorConfig config = new ConnectorConfig();
|
|
||||||
// config.setUsername(username);
|
|
||||||
// config.setPassword();
|
|
||||||
// String url = ;
|
|
||||||
// config.setAuthEndpoint(url);
|
|
||||||
// config.setServiceEndpoint(url);
|
|
||||||
// config.setConnectionTimeout(60 * 60 * 1000);
|
|
||||||
// config.setReadTimeout(60 * 60 * 1000);
|
|
||||||
// PartnerConnection connection = new PartnerConnection(config);
|
|
||||||
// config.setRestEndpoint(url);
|
|
||||||
// config.setSessionId(connection.getSessionHeader().getSessionId());
|
|
||||||
return BulkUtil.getBulkConnection(map.get("username"),map.get("password"),map.get("url"));
|
|
||||||
} catch (Exception e) {
|
|
||||||
String message = "目标ORG连接配置错误!";
|
|
||||||
String format = String.format("ORG连接异常!, \ncause:\n%s", message);
|
|
||||||
EmailUtil.send("DataDump ERROR", format);
|
|
||||||
log.error("exception message", e);
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user