Java源码示例:com.sforce.soap.partner.Connector

示例1
private static PartnerConnection createConnectionBySessionId(ForceConnectionInfo info) throws ConnectionException {
    ConnectorConfig partnerConfig = new ConnectorConfig();
    partnerConfig.setSessionId(info.getSessionId());

    if (info.getSandbox() != null) {
        partnerConfig.setServiceEndpoint(ForceService.getPartnerUrl(info.getSessionId(), info.getSandbox()));
        return Connector.newConnection(partnerConfig);
    }

    try {
        partnerConfig.setServiceEndpoint(ForceService.getPartnerUrl(info.getSessionId(), false));
        return Connector.newConnection(partnerConfig);
    } catch (RuntimeException re) {
        try {
            partnerConfig.setServiceEndpoint(ForceService.getPartnerUrl(info.getSessionId(), true));
            return Connector.newConnection(partnerConfig);
        } catch (RuntimeException r) {
            throw new ConnectionException(r.getMessage());
        }
    }
}
 
示例2
private static PartnerConnection createConnectionByUserCredential(ForceConnectionInfo info)
        throws ConnectionException {
    ConnectorConfig partnerConfig = new ConnectorConfig();
    partnerConfig.setUsername(info.getUserName());
    partnerConfig.setPassword(info.getPassword());
    if (info.getSandbox() != null) {
        partnerConfig.setAuthEndpoint(buildAuthEndpoint(info.getSandbox()));
        return Connector.newConnection(partnerConfig);
    }

    try {
        partnerConfig.setAuthEndpoint(buildAuthEndpoint(false));
        return Connector.newConnection(partnerConfig);
    } catch (ConnectionException ce) {
        partnerConfig.setAuthEndpoint(buildAuthEndpoint(true));
        return Connector.newConnection(partnerConfig);
    }
}
 
示例3
@SuppressWarnings("deprecation")
public void checkVersion(SalesforceConfiguration config) {
    try {
        String url = config.getUrl();
        String apiVersion = url.substring(url.lastIndexOf('/') + 1, url.length());
        Field f = Connector.class.getDeclaredField("END_POINT"); //$NON-NLS-1$
        f.setAccessible(true);
        if (f.isAccessible()) {
            String endPoint = (String) f.get(null);
            String javaApiVersion = endPoint.substring(endPoint.lastIndexOf('/') + 1, endPoint.length());
            if (!javaApiVersion.equals(apiVersion)) {
                logger.warn("Accessing remote API version" + apiVersion + "with Java API version " + javaApiVersion
                        + "may not be compatible");
            }
        }
    } catch (Exception e) {

    }
}
 
示例4
/**
 * Ges the Connection to SalesForce using the WSC wrapper
 * 
 * @param _session
 * @param argStruct
 * @return
 * @throws cfmRunTimeException
 * @throws ConnectionException
 */
protected PartnerConnection getConnection(cfSession _session, cfArgStructData argStruct) throws cfmRunTimeException, ConnectionException {
	String	email	= getNamedStringParam(argStruct, "email", null );
	if ( email == null )
		throwException( _session, "email was not properly defined" );

	String	passwordtoken	= getNamedStringParam(argStruct, "passwordtoken", null );
	if ( passwordtoken == null )
		throwException( _session, "passwordtoken was not properly defined" );

	// Make the connection to SalesForce
	ConnectorConfig config = new ConnectorConfig();
   config.setUsername(email);
   config.setPassword(passwordtoken);
   
   int timeout =	getNamedIntParam(argStruct, "timeout", -1 );
   if ( timeout > 0 )
     config.setReadTimeout(timeout);

   return Connector.newConnection(config);
}
 
示例5
@Override
public SessionRenewalHeader renewSession(ConnectorConfig config) throws ConnectionException {
  LOG.info("Renewing Salesforce session");

  try {
    partnerConnection = Connector.newConnection(ForceUtils.getPartnerConfig(conf, new ForceSessionRenewer()));
  } catch (StageException e) {
    throw new ConnectionException("Can't create partner config", e);
  }

  SessionRenewalHeader header = new SessionRenewalHeader();
  header.name = new QName("urn:enterprise.soap.sforce.com", "SessionHeader");
  header.headerElement = partnerConnection.getSessionHeader();
  return header;
}
 
示例6
@Override
public SessionRenewalHeader renewSession(ConnectorConfig config) throws ConnectionException {
  try {
    partnerConnection = Connector.newConnection(ForceUtils.getPartnerConfig(conf, new ForceSessionRenewer()));
  } catch (StageException e) {
    throw new ConnectionException("Can't create partner config", e);
  }

  SessionRenewalHeader header = new SessionRenewalHeader();
  header.name = new QName("urn:enterprise.soap.sforce.com", "SessionHeader");
  header.headerElement = partnerConnection.getSessionHeader();
  return header;
}
 
示例7
@Override
public SessionRenewalHeader renewSession(ConnectorConfig config) throws ConnectionException {
  try {
    connection = Connector.newConnection(ForceUtils.getPartnerConfig(conf, new WaveSessionRenewer()));
  } catch (StageException e) {
    throw new ConnectionException("Can't create partner config", e);
  }

  SessionRenewalHeader header = new SessionRenewalHeader();
  header.name = new QName("urn:enterprise.soap.sforce.com", "SessionHeader");
  header.headerElement = connection.getSessionHeader();
  return header;
}
 
示例8
/**
 * {@inheritDoc}
 */
@Override
protected List<ConfigIssue> init() {
  // Validate configuration values and open any required resources.
  List<ConfigIssue> issues = super.init();
  Optional
      .ofNullable(conf.init(getContext(), CONF_PREFIX ))
      .ifPresent(issues::addAll);

  try {
    ConnectorConfig partnerConfig = ForceUtils.getPartnerConfig(conf, new WaveSessionRenewer());
    connection = Connector.newConnection(partnerConfig);
    LOG.info("Successfully authenticated as {}", conf.username);
    if (conf.mutualAuth.useMutualAuth) {
      ForceUtils.setupMutualAuth(partnerConfig, conf.mutualAuth);
    }

    String soapEndpoint = connection.getConfig().getServiceEndpoint();
    restEndpoint = soapEndpoint.substring(0, soapEndpoint.indexOf("services/Soap/"));

    httpClient = new HttpClient(ForceUtils.makeSslContextFactory(conf));
    if (conf.useProxy) {
      ForceUtils.setProxy(httpClient, conf);
    }
    httpClient.start();
  } catch (Exception e) {
    LOG.error("Exception during init()", e);
    issues.add(getContext().createConfigIssue(Groups.FORCE.name(),
        ForceConfigBean.CONF_PREFIX + "authEndpoint",
        Errors.WAVE_00,
        ForceUtils.getExceptionCode(e) + ", " + ForceUtils.getExceptionMessage(e)
    ));
  }

  // If issues is not empty, the UI will inform the user of each configuration issue in the list.
  return issues;
}
 
示例9
@Override
public SessionRenewalHeader renewSession(ConnectorConfig config) throws ConnectionException {
  LOG.info("Renewing Salesforce session");

  try {
    partnerConnection = Connector.newConnection(ForceUtils.getPartnerConfig(conf, new ForceSessionRenewer()));
  } catch (StageException e) {
    throw new ConnectionException("Can't create partner config", e);
  }

  SessionRenewalHeader header = new SessionRenewalHeader();
  header.name = new QName("urn:enterprise.soap.sforce.com", "SessionHeader");
  header.headerElement = partnerConnection.getSessionHeader();
  return header;
}
 
示例10
@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 );
  config.setManualLogin( true ); // Required to prevent connection attempt during test

  assertNull( conn.getBinding() );

  conn.createBinding( config );
  PartnerConnection binding1 = conn.getBinding();
  conn.createBinding( config );
  PartnerConnection binding2 = conn.getBinding();
  assertSame( binding1, binding2 );
}
 
示例11
/**
 * {@inheritDoc}
 */
@Override
protected List<ConfigIssue> init() {
  // Validate configuration values and open any required resources.
  List<ConfigIssue> issues = super.init();
  Target.Context context = getContext();
  Optional
      .ofNullable(conf.init(context, CONF_PREFIX))
      .ifPresent(issues::addAll);

  errorRecordHandler = new DefaultErrorRecordHandler(context);

  sObjectNameVars = getContext().createELVars();
  sObjectNameEval = context.createELEval(SOBJECT_NAME);
  ELUtils.validateExpression(conf.sObjectNameTemplate,
      context,
      Groups.FORCE.getLabel(),
      SOBJECT_NAME,
      Errors.FORCE_12, issues
  );

  externalIdFieldVars = getContext().createELVars();
  externalIdFieldEval = context.createELEval(EXTERNAL_ID_NAME);
  ELUtils.validateExpression(conf.externalIdField,
      context,
      Groups.FORCE.getLabel(),
      EXTERNAL_ID_NAME,
      Errors.FORCE_24, issues
  );

  if (issues.isEmpty()) {
    customMappings = new TreeMap<>();
    for (ForceFieldMapping mapping : conf.fieldMapping) {
      // SDC-7446 Allow colon as well as period as field separator
      // SDC-13117 But only if it's a Bulk Loader syntax field name
      String salesforceField = (conf.useBulkAPI && BULK_LOADER_FIELD_PATTERN.matcher(mapping.salesforceField).matches())
          ? mapping.salesforceField.replace(':', '.')
          : mapping.salesforceField;
      customMappings.put(salesforceField, mapping.sdcField);
    }

    try {
      ConnectorConfig partnerConfig = ForceUtils.getPartnerConfig(conf, new ForceSessionRenewer());
      partnerConnection = Connector.newConnection(partnerConfig);
      if (conf.mutualAuth.useMutualAuth) {
        ForceUtils.setupMutualAuth(partnerConfig, conf.mutualAuth);
      }
      bulkConnection = ForceUtils.getBulkConnection(partnerConfig, conf);
      LOG.info("Successfully authenticated as {}", conf.username);
    } catch (ConnectionException | AsyncApiException | StageException | URISyntaxException ce) {
      LOG.error("Can't connect to SalesForce", ce);
      issues.add(getContext().createConfigIssue(Groups.FORCE.name(),
          "connectorConfig",
          Errors.FORCE_00,
          ForceUtils.getExceptionCode(ce) + ", " + ForceUtils.getExceptionMessage(ce)
      ));
    }
  }

  // If issues is not empty, the UI will inform the user of each configuration issue in the list.
  return issues;
}
 
示例12
/**
 * Constructor that sets up the connection to a Salesforce organization
 *
 * @param username
 * @param password
 * @param securityToken
 * @param server
 * @param pollWaitString
 * @param maxPollString
 * @param proxyServer
 * @param proxyUser
 * @param proxyPort
 * @param proxyPass
 * @throws Exception
 */
public SMAConnection(String username,
                     String password,
                     String securityToken,
                     String server,
                     String pollWaitString,
                     String maxPollString,
                     String proxyServer,
                     String proxyUser,
                     String proxyPass,
                     Integer proxyPort) throws Exception
{
    System.setProperty("https.protocols", "TLSv1,TLSv1.1,TLSv1.2");

    API_VERSION = Double.valueOf(SMAMetadataTypes.getAPIVersion());
    this.pollWaitString = pollWaitString;
    this.maxPollString = maxPollString;

    String endpoint = server + "/services/Soap/u/" + String.valueOf(API_VERSION);

    initConfig.setUsername(username);
    initConfig.setPassword(password + securityToken);
    initConfig.setAuthEndpoint(endpoint);
    initConfig.setServiceEndpoint(endpoint);
    initConfig.setManualLogin(true);

    //Proxy support
    if (!proxyServer.isEmpty()) {
        initConfig.setProxy(proxyServer, proxyPort);
        if (!proxyPass.isEmpty()) {
            initConfig.setProxyUsername(proxyUser);
            initConfig.setProxyPassword(proxyPass);
        }
    }



    partnerConnection = Connector.newConnection(initConfig);

    LoginResult loginResult = new LoginResult();

    loginResult = partnerConnection.login(initConfig.getUsername(), initConfig.getPassword());
    metadataConfig.setServiceEndpoint(loginResult.getMetadataServerUrl());
    metadataConfig.setSessionId(loginResult.getSessionId());
    metadataConfig.setProxy(initConfig.getProxy());
    metadataConfig.setProxyUsername(initConfig.getProxyUsername());
    metadataConfig.setProxyPassword(initConfig.getProxyPassword());

    metadataConnection = new MetadataConnection(metadataConfig);
}