Search in sources :

Example 61 with ResourceException

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);
}
Also used : MalformedURLException(java.net.MalformedURLException) OAuthCredential(org.teiid.OAuthCredential) IOException(java.io.IOException) Properties(java.util.Properties) Subject(javax.security.auth.Subject) URL(java.net.URL) SalesforceConnectorConfig(org.teiid.resource.adapter.salesforce.transport.SalesforceConnectorConfig) StringReader(java.io.StringReader) ResourceException(javax.resource.ResourceException) ConnectionException(com.sforce.ws.ConnectionException)

Example 62 with ResourceException

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();
    }
}
Also used : InvalidFieldFault(com.sforce.soap.partner.fault.InvalidFieldFault) InvalidQueryLocatorFault(com.sforce.soap.partner.fault.InvalidQueryLocatorFault) ResourceException(javax.resource.ResourceException) UnexpectedErrorFault(com.sforce.soap.partner.fault.UnexpectedErrorFault) ConnectionException(com.sforce.ws.ConnectionException)

Example 63 with ResourceException

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;
}
Also used : Error(com.sforce.soap.partner.Error) UnexpectedErrorFault(com.sforce.soap.partner.fault.UnexpectedErrorFault) ResourceException(javax.resource.ResourceException) ConnectionException(com.sforce.ws.ConnectionException)

Example 64 with ResourceException

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);
}
Also used : InvalidFieldFault(com.sforce.soap.partner.fault.InvalidFieldFault) InvalidSObjectFault(com.sforce.soap.partner.fault.InvalidSObjectFault) SObject(com.sforce.soap.partner.sobject.SObject) DataPayload(org.teiid.translator.salesforce.execution.DataPayload) ResourceException(javax.resource.ResourceException) UnexpectedErrorFault(com.sforce.soap.partner.fault.UnexpectedErrorFault) InvalidIdFault(com.sforce.soap.partner.fault.InvalidIdFault) ConnectionException(com.sforce.ws.ConnectionException)

Example 65 with ResourceException

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);
}
Also used : InvalidSObjectFault(com.sforce.soap.partner.fault.InvalidSObjectFault) ArrayList(java.util.ArrayList) UnexpectedErrorFault(com.sforce.soap.partner.fault.UnexpectedErrorFault) InvalidFieldFault(com.sforce.soap.partner.fault.InvalidFieldFault) SObject(com.sforce.soap.partner.sobject.SObject) DataPayload(org.teiid.translator.salesforce.execution.DataPayload) ResourceException(javax.resource.ResourceException) InvalidIdFault(com.sforce.soap.partner.fault.InvalidIdFault) ConnectionException(com.sforce.ws.ConnectionException)

Aggregations

ResourceException (javax.resource.ResourceException)163 TranslatorException (org.teiid.translator.TranslatorException)26 SQLException (java.sql.SQLException)18 IOException (java.io.IOException)17 PoolingException (com.sun.appserv.connectors.internal.api.PoolingException)14 ManagedConnection (javax.resource.spi.ManagedConnection)13 ResourceStatus (org.glassfish.resourcebase.resources.api.ResourceStatus)13 NamingException (javax.naming.NamingException)11 InvocationTargetException (java.lang.reflect.InvocationTargetException)10 SObject (com.sforce.soap.partner.sobject.SObject)9 ConnectionException (com.sforce.ws.ConnectionException)9 UnexpectedErrorFault (com.sforce.soap.partner.fault.UnexpectedErrorFault)8 ArrayList (java.util.ArrayList)8 ResourceHandle (com.sun.enterprise.resource.ResourceHandle)7 InvalidSObjectFault (com.sforce.soap.partner.fault.InvalidSObjectFault)6 ResourcePrincipal (com.sun.enterprise.deployment.ResourcePrincipal)6 Set (java.util.Set)6 MessageEndpoint (javax.resource.spi.endpoint.MessageEndpoint)6 XAResource (javax.transaction.xa.XAResource)6 InvalidFieldFault (com.sforce.soap.partner.fault.InvalidFieldFault)5