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);
}
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);
}
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);
}
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();
}
}
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());
}
Aggregations