use of javax.resource.ResourceException in project teiid by teiid.
the class SalesforceConnectionImpl method login.
private void login(SalesForceManagedConnectionFactory mcf) throws ResourceException {
config = new SalesforceConnectorConfig();
String username = mcf.getUsername();
String password = mcf.getPassword();
// if security-domain is specified and caller identity is used; then use
// credentials from subject
boolean useCXFTransport = mcf.getConfigFile() != null;
Subject subject = ConnectionContext.getSubject();
if (subject != null) {
OAuthCredential oauthCredential = ConnectionContext.getSecurityCredential(subject, OAuthCredential.class);
if (oauthCredential != null) {
config.setCredential(OAuthCredential.class.getName(), oauthCredential);
useCXFTransport = true;
} else {
username = ConnectionContext.getUserName(subject, mcf, username);
password = ConnectionContext.getPassword(subject, mcf, username, password);
}
}
config.setCxfConfigFile(mcf.getConfigFile());
if (useCXFTransport) {
config.setTransport(SalesforceCXFTransport.class);
}
config.setCompression(true);
config.setTraceMessage(false);
// set the catch all properties
String props = mcf.getConfigProperties();
if (props != null) {
Properties p = new Properties();
try {
p.load(new StringReader(props));
} catch (IOException e) {
throw new ResourceException(e);
}
PropertiesUtils.setBeanProperties(config, p, null);
}
config.setUsername(username);
config.setPassword(password);
config.setAuthEndpoint(mcf.getURL());
// set proxy if needed
if (mcf.getProxyURL() != null) {
try {
URL proxyURL = new URL(mcf.getProxyURL());
config.setProxy(proxyURL.getHost(), proxyURL.getPort());
config.setProxyUsername(mcf.getProxyUsername());
config.setProxyPassword(mcf.getProxyPassword());
} catch (MalformedURLException e) {
throw new ResourceException(e);
}
}
if (mcf.getConnectTimeout() != null) {
config.setConnectionTimeout((int) Math.min(Integer.MAX_VALUE, mcf.getConnectTimeout()));
}
if (mcf.getRequestTimeout() != null) {
config.setReadTimeout((int) Math.min(Integer.MAX_VALUE, mcf.getRequestTimeout()));
}
try {
partnerConnection = new TeiidPartnerConnection(config);
String endpoint = config.getServiceEndpoint();
// 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'
// $NON-NLS-1$
int index = endpoint.indexOf("Soap/u/");
int endIndex = endpoint.indexOf('/', index + 7);
apiVersion = endpoint.substring(index + 7, endIndex);
// $NON-NLS-1$ //$NON-NLS-2$
String bulkEndpoint = endpoint.substring(0, endpoint.indexOf("Soap/")) + "async/" + apiVersion;
config.setRestEndpoint(bulkEndpoint);
// This value identifies Teiid as a SF certified solution.
// It was provided by SF and should not be changed.
// $NON-NLS-1$
partnerConnection.setCallOptions("RedHat/MetaMatrix/", null);
bulkConnection = new BulkConnection(config);
// Test the connection.
partnerConnection.getUserInfo();
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
restEndpoint = endpoint.substring(0, endpoint.indexOf("Soap/")) + "data/" + "v30.0";
} catch (AsyncApiException e) {
throw new ResourceException(e);
} catch (ConnectionException e) {
throw new ResourceException(e);
}
// $NON-NLS-1$
LogManager.logTrace(LogConstants.CTX_CONNECTOR, "Login was successful for username", username);
}
use of javax.resource.ResourceException in project teiid by teiid.
the class SalesforceConnectionImpl method queryMore.
public QueryResult queryMore(String queryLocator, int batchSize) throws ResourceException {
if (batchSize > 2000) {
batchSize = 2000;
// $NON-NLS-1$
LogManager.logDetail(LogConstants.CTX_CONNECTOR, "reduced.batch.size");
}
partnerConnection.setQueryOptions(batchSize);
try {
return partnerConnection.queryMore(queryLocator);
} catch (InvalidFieldFault e) {
throw new ResourceException(e);
} catch (UnexpectedErrorFault e) {
throw new ResourceException(e);
} catch (InvalidQueryLocatorFault e) {
throw new ResourceException(e);
} catch (ConnectionException e) {
throw new ResourceException(e);
} finally {
partnerConnection.clearQueryOptions();
}
}
use of javax.resource.ResourceException in project teiid by teiid.
the class SalesforceConnectionImpl method delete.
public int delete(String[] ids) throws ResourceException {
DeleteResult[] results = null;
try {
results = partnerConnection.delete(ids);
} catch (UnexpectedErrorFault e) {
throw new ResourceException(e);
} catch (ConnectionException e) {
throw new ResourceException(e);
}
boolean allGood = true;
StringBuffer errorMessages = new StringBuffer();
for (int i = 0; i < results.length; i++) {
DeleteResult result = results[i];
if (!result.isSuccess()) {
if (allGood) {
// $NON-NLS-1$
errorMessages.append("Error(s) executing DELETE: ");
allGood = false;
}
Error[] errors = result.getErrors();
if (null != errors && errors.length > 0) {
for (int x = 0; x < errors.length; x++) {
Error error = errors[x];
errorMessages.append(error.getMessage()).append(';');
}
}
}
}
if (!allGood) {
throw new ResourceException(errorMessages.toString());
}
return results.length;
}
use of javax.resource.ResourceException in project teiid by teiid.
the class SalesforceConnectionImpl method create.
public int create(DataPayload data) throws ResourceException {
SObject toCreate = new SObject();
toCreate.setType(data.getType());
for (DataPayload.Field field : data.getMessageElements()) {
toCreate.addField(field.name, field.value);
}
SObject[] objects = new SObject[] { toCreate };
SaveResult[] result;
try {
result = partnerConnection.create(objects);
} catch (InvalidFieldFault e) {
throw new ResourceException(e);
} catch (InvalidSObjectFault e) {
throw new ResourceException(e);
} catch (InvalidIdFault e) {
throw new ResourceException(e);
} catch (UnexpectedErrorFault e) {
throw new ResourceException(e);
} catch (ConnectionException e) {
throw new ResourceException(e);
}
return analyzeResult(result);
}
use of javax.resource.ResourceException in project teiid by teiid.
the class SalesforceConnectionImpl method update.
public int update(List<DataPayload> updateDataList) throws ResourceException {
List<SObject> params = new ArrayList<SObject>(updateDataList.size());
for (int i = 0; i < updateDataList.size(); i++) {
DataPayload data = updateDataList.get(i);
SObject toCreate = new SObject();
toCreate.setType(data.getType());
toCreate.setId(data.getID());
for (DataPayload.Field field : data.getMessageElements()) {
toCreate.addField(field.name, field.value);
}
params.add(i, toCreate);
}
SaveResult[] result;
try {
result = partnerConnection.update(params.toArray(new SObject[params.size()]));
} catch (InvalidFieldFault e) {
throw new ResourceException(e);
} catch (InvalidSObjectFault e) {
throw new ResourceException(e);
} catch (InvalidIdFault e) {
throw new ResourceException(e);
} catch (UnexpectedErrorFault e) {
throw new ResourceException(e);
} catch (ConnectionException e) {
throw new ResourceException(e);
}
return analyzeResult(result);
}
Aggregations