Search in sources :

Example 1 with ExceptionCode

use of com.sforce.soap.partner.fault.ExceptionCode 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);
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) ConnectorConfig(com.sforce.ws.ConnectorConfig) PartnerConnection(com.sforce.soap.partner.PartnerConnection) LoginFault(com.sforce.soap.partner.fault.LoginFault) ExceptionCode(com.sforce.soap.partner.fault.ExceptionCode) SOAPException(javax.xml.soap.SOAPException) KettleException(org.pentaho.di.core.exception.KettleException) ConnectionException(com.sforce.ws.ConnectionException) IOException(java.io.IOException)

Aggregations

PartnerConnection (com.sforce.soap.partner.PartnerConnection)1 ExceptionCode (com.sforce.soap.partner.fault.ExceptionCode)1 LoginFault (com.sforce.soap.partner.fault.LoginFault)1 ConnectionException (com.sforce.ws.ConnectionException)1 ConnectorConfig (com.sforce.ws.ConnectorConfig)1 IOException (java.io.IOException)1 SOAPException (javax.xml.soap.SOAPException)1 KettleException (org.pentaho.di.core.exception.KettleException)1