Search in sources :

Example 1 with ConnectorConfig

use of com.sforce.ws.ConnectorConfig in project tdi-studio-se by Talend.

the class SforceBasicBulkConnection method renewSession.

@Override
protected void renewSession() throws ConnectionException {
    ConnectorConfig partnerConfig = new ConnectorConfig();
    partnerConfig.setAuthEndpoint(login_endpoint);
    partnerConfig.setUsername(username);
    partnerConfig.setPassword(password);
    setProxyToConnection(partnerConfig);
    // Creating the connection automatically handles login and stores
    // the session in partnerConfig
    new PartnerConnection(partnerConfig);
    // 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 restEndpoint = soapEndpoint.substring(0, soapEndpoint.indexOf("Soap/")) + "async/" + apiVersion;
    // 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:
    config.setSessionId(partnerConfig.getSessionId());
    config.setRestEndpoint(restEndpoint);
}
Also used : ConnectorConfig(com.sforce.ws.ConnectorConfig) PartnerConnection(com.sforce.soap.partner.PartnerConnection)

Example 2 with ConnectorConfig

use of com.sforce.ws.ConnectorConfig in project tdi-studio-se by Talend.

the class SforceOAuthBulkConnection method init.

private void init() throws Exception {
    config = new ConnectorConfig();
    // This should only be false when doing debugging.
    config.setCompression(needCompression);
    // Set this to true to see HTTP requests and responses on stdout
    config.setTraceMessage(needTraceMessage);
    renewSession();
    connection = new BulkConnection(config);
}
Also used : ConnectorConfig(com.sforce.ws.ConnectorConfig) BulkConnection(com.sforce.async.BulkConnection)

Example 3 with ConnectorConfig

use of com.sforce.ws.ConnectorConfig in project tdi-studio-se by Talend.

the class Connector method newConnection.

public static PartnerConnection newConnection(String username, String password) throws ConnectionException {
    ConnectorConfig config = new ConnectorConfig();
    config.setUsername(username);
    config.setPassword(password);
    return newConnection(config);
}
Also used : ConnectorConfig(com.sforce.ws.ConnectorConfig)

Example 4 with ConnectorConfig

use of com.sforce.ws.ConnectorConfig in project pentaho-kettle by pentaho.

the class SalesforceConnectionIT method testConnectOptions.

@Test
public void testConnectOptions() {
    LogChannelInterface logInterface = mock(LogChannelInterface.class);
    String url = SalesforceConnectionUtils.TARGET_DEFAULT_URL;
    String username = "username";
    String password = "password";
    Integer timeout = 30;
    try {
        SalesforceConnection connection = spy(new SalesforceConnection(logInterface, url, username, password));
        connection.setTimeOut(timeout);
        LoginResult loginResult = mock(LoginResult.class);
        GetUserInfoResult userInfo = mock(GetUserInfoResult.class);
        GetServerTimestampResult serverTime = new GetServerTimestampResult();
        serverTime.setTimestamp(Calendar.getInstance());
        ArgumentCaptor<ConnectorConfig> captorConfig = ArgumentCaptor.forClass(ConnectorConfig.class);
        doReturn(loginResult).when(bindingStub).login(anyString(), anyString());
        doReturn(userInfo).when(bindingStub).getUserInfo();
        when(loginResult.getServerUrl()).thenReturn("http://localhost/services/Soap/u/37.0");
        when(loginResult.getSessionId()).thenReturn(UUID.randomUUID().toString());
        when(userInfo.getUserFullName()).thenReturn(UUID.randomUUID().toString());
        when(userInfo.getUserEmail()).thenReturn(UUID.randomUUID().toString());
        when(userInfo.getUserLanguage()).thenReturn(UUID.randomUUID().toString());
        when(userInfo.getOrganizationName()).thenReturn(UUID.randomUUID().toString());
        doReturn(serverTime).when(bindingStub).getServerTimestamp();
        connection.setTimeOut(timeout);
        connection.setUsingCompression(true);
        connection.setRollbackAllChangesOnError(true);
        try {
            connection.connect();
        } catch (KettleException e) {
        // The connection should fail
        // We just want to see the generated ConnectorConfig
        }
        verify(connection).createBinding(captorConfig.capture());
        ConnectorConfig config = captorConfig.getValue();
        assertNotNull(config);
        assertEquals(url, config.getAuthEndpoint());
        assertTrue(config.isCompression());
        assertTrue(config.isManualLogin());
        assertEquals(timeout, Integer.valueOf(config.getConnectionTimeout()));
        assertEquals(timeout, Integer.valueOf(config.getReadTimeout()));
    } catch (Exception e) {
        fail("Connection fail: " + e.getMessage());
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) GetUserInfoResult(com.sforce.soap.partner.GetUserInfoResult) ConnectorConfig(com.sforce.ws.ConnectorConfig) LoginResult(com.sforce.soap.partner.LoginResult) Matchers.anyString(org.mockito.Matchers.anyString) LogChannelInterface(org.pentaho.di.core.logging.LogChannelInterface) KettleException(org.pentaho.di.core.exception.KettleException) ConnectionException(com.sforce.ws.ConnectionException) RemoteException(java.rmi.RemoteException) GetServerTimestampResult(com.sforce.soap.partner.GetServerTimestampResult) Test(org.junit.Test)

Example 5 with ConnectorConfig

use of com.sforce.ws.ConnectorConfig in project components by Talend.

the class SalesforceRuntimeTestUtil method login.

private void login(String endpoint) throws ConnectionException {
    ConnectorConfig config = new ConnectorConfig();
    config.setAuthEndpoint(endpoint);
    config.setUsername(username);
    config.setPassword(password + securityKey);
    config.setConnectionTimeout(60000);
    config.setUseChunkedPost(true);
    partnerConnection = new PartnerConnection(config);
}
Also used : ConnectorConfig(com.sforce.ws.ConnectorConfig) PartnerConnection(com.sforce.soap.partner.PartnerConnection)

Aggregations

ConnectorConfig (com.sforce.ws.ConnectorConfig)20 PartnerConnection (com.sforce.soap.partner.PartnerConnection)12 BulkConnection (com.sforce.async.BulkConnection)5 ConnectionException (com.sforce.ws.ConnectionException)5 Test (org.junit.Test)4 SessionRenewer (com.sforce.ws.SessionRenewer)3 IOException (java.io.IOException)3 KettleException (org.pentaho.di.core.exception.KettleException)3 AsyncApiException (com.sforce.async.AsyncApiException)2 GetUserInfoResult (com.sforce.soap.partner.GetUserInfoResult)2 LoginResult (com.sforce.soap.partner.LoginResult)2 LoginFault (com.sforce.soap.partner.fault.LoginFault)2 QName (javax.xml.namespace.QName)2 Matchers.anyString (org.mockito.Matchers.anyString)2 LogChannelInterface (org.pentaho.di.core.logging.LogChannelInterface)2 ComponentException (org.talend.components.api.exception.ComponentException)2 SalesforceConnectionProperties (org.talend.components.salesforce.SalesforceConnectionProperties)2 ConnectionHolder (org.talend.components.salesforce.runtime.common.ConnectionHolder)2 UserModel (com.gitblit.models.UserModel)1 GetServerTimestampResult (com.sforce.soap.partner.GetServerTimestampResult)1