public boolean bulkApiLogin ( ) throws Exception { log . info ( "Authenticating salesforce bulk api" ) ; boolean success = false ; String hostName = this . workUnitState . getProp ( ConfigurationKeys . SOURCE_CONN_HOST_NAME ) ; String apiVersion = this . workUnitState . getProp ( ConfigurationKeys . SOURCE_CONN_VERSION ) ; if ( Strings . isNullOrEmpty ( apiVersion ) ) { // queryAll was introduced in version 39.0, so need to use a higher version when using queryAll with the bulk api apiVersion = this . bulkApiUseQueryAll ? "42.0" : "29.0" ; } String soapAuthEndPoint = hostName + SALESFORCE_SOAP_SERVICE + "/" + apiVersion ; try { ConnectorConfig partnerConfig = new ConnectorConfig ( ) ; if ( super . workUnitState . contains ( ConfigurationKeys . SOURCE_CONN_USE_PROXY_URL ) && ! super . workUnitState . getProp ( ConfigurationKeys . SOURCE_CONN_USE_PROXY_URL ) . isEmpty ( ) ) { partnerConfig . setProxy ( super . workUnitState . getProp ( ConfigurationKeys . SOURCE_CONN_USE_PROXY_URL ) , super . workUnitState . getPropAsInt ( ConfigurationKeys . SOURCE_CONN_USE_PROXY_PORT ) ) ; } String accessToken = sfConnector . getAccessToken ( ) ; if ( accessToken == null ) { boolean isConnectSuccess = sfConnector . connect ( ) ; if ( isConnectSuccess ) { accessToken = sfConnector . getAccessToken ( ) ; } } if ( accessToken != null ) { String serviceEndpoint = sfConnector . getInstanceUrl ( ) + SALESFORCE_SOAP_SERVICE + "/" + apiVersion ; partnerConfig . setSessionId ( accessToken ) ; partnerConfig . setServiceEndpoint ( serviceEndpoint ) ; } else { String securityToken = this . workUnitState . getProp ( ConfigurationKeys . SOURCE_CONN_SECURITY_TOKEN ) ; String password = PasswordManager . getInstance ( this . workUnitState ) . readPassword ( this . workUnitState . getProp ( ConfigurationKeys . SOURCE_CONN_PASSWORD ) ) ; partnerConfig . setUsername ( this . workUnitState . getProp ( ConfigurationKeys . SOURCE_CONN_USERNAME ) ) ; partnerConfig . setPassword ( password + securityToken ) ; } partnerConfig . setAuthEndpoint ( soapAuthEndPoint ) ; new PartnerConnection ( partnerConfig ) ; String soapEndpoint = partnerConfig . getServiceEndpoint ( ) ; String restEndpoint = soapEndpoint . substring ( 0 , soapEndpoint . indexOf ( "Soap/" ) ) + "async/" + apiVersion ; ConnectorConfig config = new ConnectorConfig ( ) ; config . setSessionId ( partnerConfig . getSessionId ( ) ) ; config . setRestEndpoint ( restEndpoint ) ; config . setCompression ( true ) ; config . setTraceFile ( "traceLogs.txt" ) ; config . setTraceMessage ( false ) ; config . setPrettyPrintXml ( true ) ; if ( super . workUnitState . contains ( ConfigurationKeys . SOURCE_CONN_USE_PROXY_URL ) && ! super . workUnitState . getProp ( ConfigurationKeys . SOURCE_CONN_USE_PROXY_URL ) . isEmpty ( ) ) { config . setProxy ( super . workUnitState . getProp ( ConfigurationKeys . SOURCE_CONN_USE_PROXY_URL ) , super . workUnitState . getPropAsInt ( ConfigurationKeys . SOURCE_CONN_USE_PROXY_PORT ) ) ; } this . bulkConnection = new BulkConnection ( config ) ; success = true ; } catch ( RuntimeException e ) { throw new RuntimeException ( "Failed to connect to salesforce bulk api; error - " + e , e ) ; } return success ; }
Login to salesforce