Search in sources :

Example 1 with BatchJobException

use of com.google.api.ads.adwords.lib.utils.BatchJobException in project googleads-java-lib by googleads.

the class AddCompleteCampaignsUsingBatchJob method main.

public static void main(String[] args) {
    AdWordsSession session;
    try {
        // Generate a refreshable OAuth2 credential.
        Credential oAuth2Credential = new OfflineCredentials.Builder().forApi(Api.ADWORDS).fromFile().build().generateCredential();
        // Construct an AdWordsSession.
        session = new AdWordsSession.Builder().fromFile().withOAuth2Credential(oAuth2Credential).build();
    } catch (ConfigurationLoadException cle) {
        System.err.printf("Failed to load configuration from the %s file. Exception: %s%n", DEFAULT_CONFIGURATION_FILENAME, cle);
        return;
    } catch (ValidationException ve) {
        System.err.printf("Invalid configuration in the %s file. Exception: %s%n", DEFAULT_CONFIGURATION_FILENAME, ve);
        return;
    } catch (OAuthException oe) {
        System.err.printf("Failed to create OAuth credentials. Check OAuth settings in the %s file. " + "Exception: %s%n", DEFAULT_CONFIGURATION_FILENAME, oe);
        return;
    }
    AdWordsServicesInterface adWordsServices = AdWordsServices.getInstance();
    try {
        runExample(adWordsServices, session);
    } catch (ApiException apiException) {
        // ApiException is the base class for most exceptions thrown by an API request. Instances
        // of this exception have a message and a collection of ApiErrors that indicate the
        // type and underlying cause of the exception. Every exception object in the adwords.axis
        // packages will return a meaningful value from toString
        // 
        // ApiException extends RemoteException, so this catch block must appear before the
        // catch block for RemoteException.
        System.err.println("Request failed due to ApiException. Underlying ApiErrors:");
        if (apiException.getErrors() != null) {
            int i = 0;
            for (ApiError apiError : apiException.getErrors()) {
                System.err.printf("  Error %d: %s%n", i++, apiError);
            }
        }
    } catch (RemoteException re) {
        System.err.printf("Request failed unexpectedly due to RemoteException: %s%n", re);
    } catch (InterruptedException ie) {
        System.err.printf("Thread was interrupted: %s%n", ie);
    } catch (TimeoutException te) {
        System.err.printf("Job did not complete after status was polled %s times: %s%n", MAX_POLL_ATTEMPTS, te);
    } catch (BatchJobException be) {
        System.err.printf("Example failed due to BatchJobException: %s%n", be);
    }
}
Also used : Credential(com.google.api.client.auth.oauth2.Credential) ValidationException(com.google.api.ads.common.lib.exception.ValidationException) SelectorBuilder(com.google.api.ads.adwords.axis.utils.v201809.SelectorBuilder) OAuthException(com.google.api.ads.common.lib.exception.OAuthException) AdWordsServicesInterface(com.google.api.ads.adwords.lib.factory.AdWordsServicesInterface) BatchJobException(com.google.api.ads.adwords.lib.utils.BatchJobException) AdWordsSession(com.google.api.ads.adwords.lib.client.AdWordsSession) ConfigurationLoadException(com.google.api.ads.common.lib.conf.ConfigurationLoadException) ApiError(com.google.api.ads.adwords.axis.v201809.cm.ApiError) RemoteException(java.rmi.RemoteException) ApiException(com.google.api.ads.adwords.axis.v201809.cm.ApiException) TimeoutException(java.util.concurrent.TimeoutException)

Example 2 with BatchJobException

use of com.google.api.ads.adwords.lib.utils.BatchJobException in project googleads-java-lib by googleads.

the class AddKeywordsUsingIncrementalBatchJob method main.

public static void main(String[] args) {
    AdWordsSession session;
    try {
        // Generate a refreshable OAuth2 credential.
        Credential oAuth2Credential = new OfflineCredentials.Builder().forApi(Api.ADWORDS).fromFile().build().generateCredential();
        // Construct an AdWordsSession.
        session = new AdWordsSession.Builder().fromFile().withOAuth2Credential(oAuth2Credential).build();
    } catch (ConfigurationLoadException cle) {
        System.err.printf("Failed to load configuration from the %s file. Exception: %s%n", DEFAULT_CONFIGURATION_FILENAME, cle);
        return;
    } catch (ValidationException ve) {
        System.err.printf("Invalid configuration in the %s file. Exception: %s%n", DEFAULT_CONFIGURATION_FILENAME, ve);
        return;
    } catch (OAuthException oe) {
        System.err.printf("Failed to create OAuth credentials. Check OAuth settings in the %s file. " + "Exception: %s%n", DEFAULT_CONFIGURATION_FILENAME, oe);
        return;
    }
    AdWordsServicesInterface adWordsServices = AdWordsServices.getInstance();
    AddKeywordsUsingIncrementalBatchJobParams params = new AddKeywordsUsingIncrementalBatchJobParams();
    if (!params.parseArguments(args)) {
        // Either pass the required parameters for this example on the command line, or insert them
        // into the code here. See the parameter class definition above for descriptions.
        params.adGroupId = Long.parseLong("INSERT_AD_GROUP_ID_HERE");
    }
    try {
        runExample(adWordsServices, session, params.adGroupId);
    } catch (ApiException apiException) {
        // ApiException is the base class for most exceptions thrown by an API request. Instances
        // of this exception have a message and a collection of ApiErrors that indicate the
        // type and underlying cause of the exception. Every exception object in the adwords.axis
        // packages will return a meaningful value from toString
        // 
        // ApiException extends RemoteException, so this catch block must appear before the
        // catch block for RemoteException.
        System.err.println("Request failed due to ApiException. Underlying ApiErrors:");
        if (apiException.getErrors() != null) {
            int i = 0;
            for (ApiError apiError : apiException.getErrors()) {
                System.err.printf("  Error %d: %s%n", i++, apiError);
            }
        }
    } catch (RemoteException re) {
        System.err.printf("Request failed unexpectedly due to RemoteException: %s%n", re);
    } catch (InterruptedException ie) {
        System.err.printf("Thread was interrupted: %s%n", ie);
    } catch (TimeoutException te) {
        System.err.printf("Job did not complete after status was polled %s times: %s%n", MAX_POLL_ATTEMPTS, te);
    } catch (BatchJobException be) {
        System.err.printf("Example failed due to BatchJobException: %s%n", be);
    }
}
Also used : Credential(com.google.api.client.auth.oauth2.Credential) ValidationException(com.google.api.ads.common.lib.exception.ValidationException) SelectorBuilder(com.google.api.ads.adwords.axis.utils.v201809.SelectorBuilder) OAuthException(com.google.api.ads.common.lib.exception.OAuthException) AdWordsServicesInterface(com.google.api.ads.adwords.lib.factory.AdWordsServicesInterface) BatchJobException(com.google.api.ads.adwords.lib.utils.BatchJobException) AdWordsSession(com.google.api.ads.adwords.lib.client.AdWordsSession) ConfigurationLoadException(com.google.api.ads.common.lib.conf.ConfigurationLoadException) ApiError(com.google.api.ads.adwords.axis.v201809.cm.ApiError) RemoteException(java.rmi.RemoteException) ApiException(com.google.api.ads.adwords.axis.v201809.cm.ApiException) TimeoutException(java.util.concurrent.TimeoutException)

Example 3 with BatchJobException

use of com.google.api.ads.adwords.lib.utils.BatchJobException in project googleads-java-lib by googleads.

the class BatchJobHelperImpl method downloadBatchJobMutateResponse.

@Override
public BatchJobMutateResponse downloadBatchJobMutateResponse(String downloadUrl, int startIndex, int numberResults) throws BatchJobException {
    /*
     * Deserialize using the generated cm.MutateResult class instead of the batchjob.MutateResult
     * class. The MutateResult and ErrorList types in the batchjob package have properties defined
     * in the BatchJobMutateResultInterface and BatchJobErrorListInterface interfaces, respectively.
     * On some Hotspot JVMs, if java.beans.Introspector (used by Axis) encounters a property
     * defined via an implemented interface, it will return a PropertyDescriptor where
     * getPropertType() returns the interface class instead of the type declared in the
     * implementing class (e.g., BatchJobErrorListInterface instead of ErrorList). This causes
     * problems during Axis deserialization because Axis relies on the presence of a static
     * getTypeDesc method on each property it encounters.
     */
    List<com.google.api.ads.adwords.axis.v201809.cm.MutateResult> cmMutateResults;
    try {
        cmMutateResults = deserializer.deserializeBatchJobMutateResults(new URL(downloadUrl), getServiceTypeMappings(), com.google.api.ads.adwords.axis.v201809.cm.MutateResult.class, resultQName, startIndex, numberResults);
    } catch (Exception e) {
        batchJobLogger.logDownload(downloadUrl, null, e);
        throw new BatchJobException("Failed to download batch job mutate response from URL: " + downloadUrl, e);
    }
    // Translate the cm.MutateResults into batchjob.MutateResults.
    BatchJobMutateResponse response = new BatchJobMutateResponse();
    List<MutateResult> mutateResults = Lists.newArrayList();
    for (com.google.api.ads.adwords.axis.v201809.cm.MutateResult cmMutateResult : cmMutateResults) {
        MutateResult mutateResult = new MutateResult();
        mutateResult.setIndex(cmMutateResult.getIndex());
        mutateResult.setOperand(cmMutateResult.getResult());
        if (cmMutateResult.getErrorList() != null) {
            mutateResult.setErrorList(new ErrorList());
            if (cmMutateResult.getErrorList().getErrors() != null) {
                mutateResult.getErrorList().setErrors(cmMutateResult.getErrorList().getErrors());
            }
        }
        mutateResults.add(mutateResult);
    }
    response.setMutateResults(mutateResults.toArray(new MutateResult[mutateResults.size()]));
    batchJobLogger.logDownload(downloadUrl, response, null);
    return response;
}
Also used : URL(java.net.URL) BatchJobException(com.google.api.ads.adwords.lib.utils.BatchJobException) ServiceException(javax.xml.rpc.ServiceException) RemoteException(java.rmi.RemoteException) BatchJobException(com.google.api.ads.adwords.lib.utils.BatchJobException)

Example 4 with BatchJobException

use of com.google.api.ads.adwords.lib.utils.BatchJobException in project googleads-java-lib by googleads.

the class BatchJobHelperImpl method downloadBatchJobMutateResponse.

@Override
public BatchJobMutateResponse downloadBatchJobMutateResponse(String downloadUrl, int startIndex, int numberResults) throws BatchJobException {
    try {
        BatchJobMutateResponse response = deserializer.deserializeBatchJobMutateResults(BatchJobMutateResponse.class, new URL(downloadUrl), startIndex, numberResults);
        batchJobLogger.logDownload(downloadUrl, response, null);
        return response;
    } catch (Exception e) {
        batchJobLogger.logDownload(downloadUrl, null, e);
        throw new BatchJobException("Failed to download batch job mutate response from URL: " + downloadUrl, e);
    }
}
Also used : BatchJobException(com.google.api.ads.adwords.lib.utils.BatchJobException) URL(java.net.URL) BatchJobException(com.google.api.ads.adwords.lib.utils.BatchJobException)

Aggregations

BatchJobException (com.google.api.ads.adwords.lib.utils.BatchJobException)4 RemoteException (java.rmi.RemoteException)3 SelectorBuilder (com.google.api.ads.adwords.axis.utils.v201809.SelectorBuilder)2 ApiError (com.google.api.ads.adwords.axis.v201809.cm.ApiError)2 ApiException (com.google.api.ads.adwords.axis.v201809.cm.ApiException)2 AdWordsSession (com.google.api.ads.adwords.lib.client.AdWordsSession)2 AdWordsServicesInterface (com.google.api.ads.adwords.lib.factory.AdWordsServicesInterface)2 ConfigurationLoadException (com.google.api.ads.common.lib.conf.ConfigurationLoadException)2 OAuthException (com.google.api.ads.common.lib.exception.OAuthException)2 ValidationException (com.google.api.ads.common.lib.exception.ValidationException)2 Credential (com.google.api.client.auth.oauth2.Credential)2 URL (java.net.URL)2 TimeoutException (java.util.concurrent.TimeoutException)2 ServiceException (javax.xml.rpc.ServiceException)1