Search in sources :

Example 6 with RemoteCallReturn

use of com.google.api.ads.common.lib.client.RemoteCallReturn in project googleads-java-lib by googleads.

the class ReportServiceLogger method logRequest.

/**
 * Logs the specified request and response information.
 *
 * <p>Note that in order to avoid any temptation to consume the contents of the response, this
 * does <em>not</em> take an {@link com.google.api.client.http.HttpResponse} object, but instead
 * accepts the status code and message from the response.
 */
public void logRequest(@Nullable HttpRequest request, int statusCode, @Nullable String statusMessage) {
    boolean isSuccess = HttpStatusCodes.isSuccess(statusCode);
    if (!loggerDelegate.isSummaryLoggable(isSuccess) && !loggerDelegate.isDetailsLoggable(isSuccess)) {
        return;
    }
    // Populate the RequestInfo builder from the request.
    RequestInfo requestInfo = buildRequestInfo(request);
    // Populate the ResponseInfo builder from the response.
    ResponseInfo responseInfo = buildResponseInfo(request, statusCode, statusMessage);
    RemoteCallReturn.Builder remoteCallReturnBuilder = new RemoteCallReturn.Builder().withRequestInfo(requestInfo).withResponseInfo(responseInfo);
    if (!isSuccess) {
        remoteCallReturnBuilder.withException(new ReportException(String.format("%s: %s", statusCode, statusMessage)));
    }
    RemoteCallReturn remoteCallReturn = remoteCallReturnBuilder.build();
    loggerDelegate.logRequestSummary(remoteCallReturn);
    loggerDelegate.logRequestDetails(remoteCallReturn);
}
Also used : ResponseInfo(com.google.api.ads.common.lib.client.ResponseInfo) ReportException(com.google.api.ads.adwords.lib.utils.ReportException) RequestInfo(com.google.api.ads.common.lib.client.RequestInfo) RemoteCallReturn(com.google.api.ads.common.lib.client.RemoteCallReturn)

Example 7 with RemoteCallReturn

use of com.google.api.ads.common.lib.client.RemoteCallReturn in project googleads-java-lib by googleads.

the class BatchJobLogger method logUpload.

/**
 * Logs a batch job operations upload.
 *
 * @param uploadContents the contents of the upload.
 * @param uploadUri the URI for the upload.
 * @param batchJobUploadResponse the upload response.
 * @param throwable the throwable that occurred during upload, or {@code null} if the upload
 *     succeeded.
 */
public void logUpload(String uploadContents, URI uploadUri, @Nullable BatchJobUploadResponse batchJobUploadResponse, @Nullable Throwable throwable) {
    RequestInfo requestInfo = new RequestInfo.Builder().withServiceName("batchjobupload").withContext(CONTEXT_NAME, null).withUrl(uploadUri.toString()).withPayload(Strings.nullToEmpty(uploadContents).trim()).build();
    ResponseInfo.Builder responseInfoBuilder = new ResponseInfo.Builder();
    if (batchJobUploadResponse != null) {
        responseInfoBuilder.withPayload(String.format("%d %s%n", batchJobUploadResponse.getHttpStatus(), batchJobUploadResponse.getHttpResponseMessage()));
    }
    RemoteCallReturn remoteCallReturn = new RemoteCallReturn.Builder().withRequestInfo(requestInfo).withResponseInfo(responseInfoBuilder.build()).withException(throwable).build();
    loggerDelegate.logRequestSummary(remoteCallReturn);
    loggerDelegate.logRequestDetails(remoteCallReturn);
}
Also used : ResponseInfo(com.google.api.ads.common.lib.client.ResponseInfo) RequestInfo(com.google.api.ads.common.lib.client.RequestInfo) RemoteCallReturn(com.google.api.ads.common.lib.client.RemoteCallReturn)

Example 8 with RemoteCallReturn

use of com.google.api.ads.common.lib.client.RemoteCallReturn in project googleads-java-lib by googleads.

the class BatchJobLogger method logDownload.

/**
 * Logs a batch job results download.
 *
 * @param downloadUrl the download URL for the batch job.
 * @param response the response - only not null if the download succeeded.
 * @param throwable the throwable that occurred during download, or {@code null} if the download
 *     succeeded.
 */
public <O, E, R extends BatchJobMutateResultInterface<O, E>> void logDownload(String downloadUrl, @Nullable BatchJobMutateResponseInterface<O, E, R> response, @Nullable Throwable throwable) {
    RequestInfo requestInfo = new RequestInfo.Builder().withServiceName("batchjobdownload").withContext(CONTEXT_NAME, null).withUrl(downloadUrl).build();
    int resultsCount = 0;
    if (response != null && response.getMutateResults() != null) {
        resultsCount = response.getMutateResults().length;
    }
    // The response payload could be massive, so simply indicate the number of results instead.
    ResponseInfo responseInfo = new ResponseInfo.Builder().withPayload(String.format("Results count: %d", resultsCount)).build();
    RemoteCallReturn remoteCallReturn = new RemoteCallReturn.Builder().withRequestInfo(requestInfo).withResponseInfo(responseInfo).withException(throwable).build();
    loggerDelegate.logRequestSummary(remoteCallReturn);
    loggerDelegate.logRequestDetails(remoteCallReturn);
}
Also used : ResponseInfo(com.google.api.ads.common.lib.client.ResponseInfo) RequestInfo(com.google.api.ads.common.lib.client.RequestInfo) RemoteCallReturn(com.google.api.ads.common.lib.client.RemoteCallReturn)

Example 9 with RemoteCallReturn

use of com.google.api.ads.common.lib.client.RemoteCallReturn in project googleads-java-lib by googleads.

the class JaxWsHandler method invokeSoapCall.

/**
 * Invoke a SOAP call.
 *
 * @param soapCall the call to make to a SOAP web service
 * @return information about the SOAP response
 */
@Override
public RemoteCallReturn invokeSoapCall(SoapCall<BindingProvider> soapCall) {
    BindingProvider webService = soapCall.getSoapClient();
    RemoteCallReturn.Builder builder = new RemoteCallReturn.Builder();
    synchronized (webService) {
        Object result = null;
        try {
            result = invoke(soapCall);
        } catch (InvocationTargetException e) {
            builder.withException(e.getTargetException());
        } catch (Exception e) {
            builder.withException(e);
        } finally {
            JaxWsSoapContextHandler contextHandler = getContextHandlerFromClient(webService);
            String url = getEndpointAddress(webService);
            builder.withRequestInfo(contextHandler.getLastRequestInfoBuilder().withUrl(url).build());
            builder.withResponseInfo(contextHandler.getLastResponseInfoBuilder().build());
        }
        return builder.withReturnValue(result).build();
    }
}
Also used : BindingProvider(javax.xml.ws.BindingProvider) InvocationTargetException(java.lang.reflect.InvocationTargetException) SOAPException(javax.xml.soap.SOAPException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ServiceException(com.google.api.ads.common.lib.exception.ServiceException) RemoteCallReturn(com.google.api.ads.common.lib.client.RemoteCallReturn)

Example 10 with RemoteCallReturn

use of com.google.api.ads.common.lib.client.RemoteCallReturn in project googleads-java-lib by googleads.

the class RemoteCallLoggerDelegateTest method testLogRequestSummary_failure.

@Test
public void testLogRequestSummary_failure() {
    Throwable returnedException = new Throwable();
    remoteCallReturn = new RemoteCallReturn.Builder().withRequestInfo(remoteCallReturn.getRequestInfo()).withResponseInfo(remoteCallReturn.getResponseInfo()).withException(returnedException).build();
    when(requestInfoLogger.isWarnEnabled()).thenReturn(true);
    loggerDelegate.logRequestSummary(remoteCallReturn);
    RequestInfo requestInfo = remoteCallReturn.getRequestInfo();
    ResponseInfo responseInfo = remoteCallReturn.getResponseInfo();
    verify(requestInfoLogger).warn(RemoteCallLoggerDelegate.SUMMARY_TEMPLATE, requestInfo.getServiceName(), requestInfo.getMethodName(), requestInfo.getContextName(), requestInfo.getContextValue(), requestInfo.getUrl(), responseInfo.getRequestId(), responseInfo.getResponseTime(), responseInfo.getOperationsCount(), true, returnedException.toString());
}
Also used : ResponseInfo(com.google.api.ads.common.lib.client.ResponseInfo) RequestInfo(com.google.api.ads.common.lib.client.RequestInfo) RemoteCallReturn(com.google.api.ads.common.lib.client.RemoteCallReturn) Test(org.junit.Test)

Aggregations

RemoteCallReturn (com.google.api.ads.common.lib.client.RemoteCallReturn)17 Test (org.junit.Test)11 ResponseInfo (com.google.api.ads.common.lib.client.ResponseInfo)8 RequestInfo (com.google.api.ads.common.lib.client.RequestInfo)7 Matchers.containsString (org.hamcrest.Matchers.containsString)3 ServiceException (com.google.api.ads.common.lib.exception.ServiceException)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Method (java.lang.reflect.Method)2 SOAPException (javax.xml.soap.SOAPException)2 BindingProvider (javax.xml.ws.BindingProvider)2 BatchJobMutateResultInterface (com.google.api.ads.adwords.lib.utils.BatchJobMutateResultInterface)1 BatchJobUploadResponse (com.google.api.ads.adwords.lib.utils.BatchJobUploadResponse)1 ReportException (com.google.api.ads.adwords.lib.utils.ReportException)1 SoapCall (com.google.api.ads.common.lib.soap.SoapCall)1 CampaignServiceInterface (com.google.api.ads.common.lib.soap.jaxws.testing.mocks.CampaignServiceInterface)1 CampaignServiceInterfaceImpl (com.google.api.ads.common.lib.soap.jaxws.testing.mocks.CampaignServiceInterfaceImpl)1 InputStream (java.io.InputStream)1 MessageContext (org.apache.axis.MessageContext)1 Stub (org.apache.axis.client.Stub)1