use of com.sforce.ws.ConnectorConfig in project MiscellaneousStudy by mikoto2000.
the class BulkInsertExample method getBulkConnection.
/**
* Create the BulkConnection used to call Bulk API operations.
*/
private BulkConnection getBulkConnection(String userName, String password) throws ConnectionException, AsyncApiException {
ConnectorConfig partnerConfig = new ConnectorConfig();
partnerConfig.setUsername(userName);
partnerConfig.setPassword(password);
partnerConfig.setAuthEndpoint("https://login.salesforce.com/services/Soap/u/34.0");
// Creating the connection automatically handles login and stores
// the session in partnerConfig
partnerConnection = new PartnerConnection(partnerConfig);
// When PartnerConnection is instantiated, a login is implicitly
// executed and, if successful,
// a valid session is stored in the ConnectorConfig instance.
// Use this key to initialize a BulkConnection:
ConnectorConfig config = new ConnectorConfig();
config.setSessionId(partnerConfig.getSessionId());
// The endpoint for the Bulk API service is the same as for the normal
// SOAP uri until the /Soap/ part. From here it's '/async/versionNumber'
String soapEndpoint = partnerConfig.getServiceEndpoint();
String apiVersion = "34.0";
String restEndpoint = soapEndpoint.substring(0, soapEndpoint.indexOf("Soap/")) + "async/" + apiVersion;
config.setRestEndpoint(restEndpoint);
// This should only be false when doing debugging.
config.setCompression(true);
// Set this to true to see HTTP requests and responses on stdout
config.setTraceMessage(false);
BulkConnection connection = new BulkConnection(config);
return connection;
}
use of com.sforce.ws.ConnectorConfig in project MiscellaneousStudy by mikoto2000.
the class BulkQueryExample method getBulkConnection.
/**
* Create the BulkConnection used to call Bulk API operations.
*/
private BulkConnection getBulkConnection(String userName, String password) throws ConnectionException, AsyncApiException {
ConnectorConfig partnerConfig = new ConnectorConfig();
partnerConfig.setUsername(userName);
partnerConfig.setPassword(password);
partnerConfig.setAuthEndpoint("https://login.salesforce.com/services/Soap/u/34.0");
// Creating the connection automatically handles login and stores
// the session in partnerConfig
partnerConnection = new PartnerConnection(partnerConfig);
// When PartnerConnection is instantiated, a login is implicitly
// executed and, if successful,
// a valid session is stored in the ConnectorConfig instance.
// Use this key to initialize a BulkConnection:
ConnectorConfig config = new ConnectorConfig();
config.setSessionId(partnerConfig.getSessionId());
// The endpoint for the Bulk API service is the same as for the normal
// SOAP uri until the /Soap/ part. From here it's '/async/versionNumber'
String soapEndpoint = partnerConfig.getServiceEndpoint();
String apiVersion = "34.0";
String restEndpoint = soapEndpoint.substring(0, soapEndpoint.indexOf("Soap/")) + "async/" + apiVersion;
config.setRestEndpoint(restEndpoint);
// This should only be false when doing debugging.
config.setCompression(true);
// Set this to true to see HTTP requests and responses on stdout
config.setTraceMessage(false);
BulkConnection connection = new BulkConnection(config);
return connection;
}
use of com.sforce.ws.ConnectorConfig in project pentaho-kettle by pentaho.
the class SalesforceConnection method connect.
public void connect() throws KettleException {
ConnectorConfig config = new ConnectorConfig();
config.setAuthEndpoint(getURL());
config.setServiceEndpoint(getURL());
config.setUsername(getUsername());
config.setPassword(getPassword());
config.setCompression(isUsingCompression());
config.setManualLogin(true);
String proxyUrl = System.getProperty("http.proxyHost", null);
if (StringUtils.isNotEmpty(proxyUrl)) {
int proxyPort = Integer.parseInt(System.getProperty("http.proxyPort", "80"));
String proxyUser = System.getProperty("http.proxyUser", null);
String proxyPassword = Encr.decryptPasswordOptionallyEncrypted(System.getProperty("http.proxyPassword", null));
config.setProxy(proxyUrl, proxyPort);
config.setProxyUsername(proxyUser);
config.setProxyPassword(proxyPassword);
}
// Set timeout
if (getTimeOut() > 0) {
if (log.isDebug()) {
log.logDebug(BaseMessages.getString(PKG, "SalesforceInput.Log.SettingTimeout", "" + this.timeout));
}
config.setConnectionTimeout(getTimeOut());
config.setReadTimeout(getTimeOut());
}
try {
PartnerConnection pConnection = createBinding(config);
if (log.isDetailed()) {
log.logDetailed(BaseMessages.getString(PKG, "SalesforceInput.Log.LoginURL", config.getAuthEndpoint()));
}
if (isRollbackAllChangesOnError()) {
// Set the SOAP header to rollback all changes
// unless all records are processed successfully.
pConnection.setAllOrNoneHeader(true);
}
// Attempt the login giving the user feedback
if (log.isDetailed()) {
log.logDetailed(BaseMessages.getString(PKG, "SalesforceInput.Log.LoginNow"));
log.logDetailed("----------------------------------------->");
log.logDetailed(BaseMessages.getString(PKG, "SalesforceInput.Log.LoginURL", getURL()));
log.logDetailed(BaseMessages.getString(PKG, "SalesforceInput.Log.LoginUsername", getUsername()));
if (getModule() != null) {
log.logDetailed(BaseMessages.getString(PKG, "SalesforceInput.Log.LoginModule", getModule()));
}
log.logDetailed("<-----------------------------------------");
}
// Login
this.loginResult = pConnection.login(config.getUsername(), Encr.decryptPasswordOptionallyEncrypted(config.getPassword()));
if (log.isDebug()) {
log.logDebug(BaseMessages.getString(PKG, "SalesforceInput.Log.SessionId") + " : " + this.loginResult.getSessionId());
log.logDebug(BaseMessages.getString(PKG, "SalesforceInput.Log.NewServerURL") + " : " + this.loginResult.getServerUrl());
}
// Create a new session header object and set the session id to that
// returned by the login
pConnection.setSessionHeader(loginResult.getSessionId());
config.setServiceEndpoint(loginResult.getServerUrl());
// Return the user Infos
this.userInfo = pConnection.getUserInfo();
if (log.isDebug()) {
log.logDebug(BaseMessages.getString(PKG, "SalesforceInput.Log.UserInfos") + " : " + this.userInfo.getUserFullName());
log.logDebug("----------------------------------------->");
log.logDebug(BaseMessages.getString(PKG, "SalesforceInput.Log.UserName") + " : " + this.userInfo.getUserFullName());
log.logDebug(BaseMessages.getString(PKG, "SalesforceInput.Log.UserEmail") + " : " + this.userInfo.getUserEmail());
log.logDebug(BaseMessages.getString(PKG, "SalesforceInput.Log.UserLanguage") + " : " + this.userInfo.getUserLanguage());
log.logDebug(BaseMessages.getString(PKG, "SalesforceInput.Log.UserOrganization") + " : " + this.userInfo.getOrganizationName());
log.logDebug("<-----------------------------------------");
}
this.serverTimestamp = pConnection.getServerTimestamp().getTimestamp().getTime();
if (log.isDebug()) {
BaseMessages.getString(PKG, "SalesforceInput.Log.ServerTimestamp", getServerTimestamp());
}
if (log.isDetailed()) {
log.logDetailed(BaseMessages.getString(PKG, "SalesforceInput.Log.Connected"));
}
} catch (LoginFault ex) {
// The LoginFault derives from AxisFault
ExceptionCode exCode = ex.getExceptionCode();
if (exCode == ExceptionCode.FUNCTIONALITY_NOT_ENABLED || exCode == ExceptionCode.INVALID_CLIENT || exCode == ExceptionCode.INVALID_LOGIN || exCode == ExceptionCode.LOGIN_DURING_RESTRICTED_DOMAIN || exCode == ExceptionCode.LOGIN_DURING_RESTRICTED_TIME || exCode == ExceptionCode.ORG_LOCKED || exCode == ExceptionCode.PASSWORD_LOCKOUT || exCode == ExceptionCode.SERVER_UNAVAILABLE || exCode == ExceptionCode.TRIAL_EXPIRED || exCode == ExceptionCode.UNSUPPORTED_CLIENT) {
throw new KettleException(BaseMessages.getString(PKG, "SalesforceInput.Error.InvalidUsernameOrPassword"));
}
throw new KettleException(BaseMessages.getString(PKG, "SalesforceInput.Error.Connection"), ex);
} catch (Exception e) {
throw new KettleException(BaseMessages.getString(PKG, "SalesforceInput.Error.Connection"), e);
}
}
use of com.sforce.ws.ConnectorConfig in project pentaho-kettle by pentaho.
the class SalesforceConnectionIT method testConnect.
private void testConnect(String password) throws Exception {
LogChannelInterface logInterface = mock(LogChannelInterface.class);
String url = "http://localhost/services/Soap/u/37.0";
String username = "MySampleUsername";
SalesforceConnection connection;
connection = spy(new SalesforceConnection(logInterface, url, username, password));
ArgumentCaptor<ConnectorConfig> captorConfig = ArgumentCaptor.forClass(ConnectorConfig.class);
ConnectorConfig mockConfig = mock(ConnectorConfig.class);
doReturn(UUID.randomUUID().toString()).when(mockConfig).getUsername();
doReturn(UUID.randomUUID().toString()).when(mockConfig).getPassword();
doReturn(mockConfig).when(bindingStub).getConfig();
doReturn(mock(LoginResult.class)).when(bindingStub).login(anyString(), anyString());
try {
connection.connect();
} catch (KettleException e) {
// The connection should fail
// We just want to see the generated ConnectorConfig
}
verify(connection).createBinding(captorConfig.capture());
assertEquals(username, captorConfig.getValue().getUsername());
// Password is unchanged (not decrypted) when setting in ConnectorConfig
assertEquals(password, captorConfig.getValue().getPassword());
}
use of com.sforce.ws.ConnectorConfig in project pentaho-kettle by pentaho.
the class SalesforceConnectionTest method testCreateBinding.
@Test
public void testCreateBinding() throws KettleException, ConnectionException {
SalesforceConnection conn = new SalesforceConnection(null, "http://localhost:1234", "aUser", "aPass");
ConnectorConfig config = new ConnectorConfig();
config.setAuthEndpoint(Connector.END_POINT);
// Required to prevent connection attempt during test
config.setManualLogin(true);
assertNull(conn.getBinding());
conn.createBinding(config);
PartnerConnection binding1 = conn.getBinding();
conn.createBinding(config);
PartnerConnection binding2 = conn.getBinding();
assertSame(binding1, binding2);
}
Aggregations