Search in sources :

Example 11 with ResponseInfo

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

the class RemoteCallLoggerDelegate method logRequestSummary.

public void logRequestSummary(RemoteCallReturn remoteCallReturn) {
    if (remoteCallReturn == null) {
        return;
    }
    boolean isSuccess = remoteCallReturn.getException() == null;
    if (!isSummaryLoggable(isSuccess)) {
        return;
    }
    RequestInfo request = remoteCallReturn.getRequestInfo();
    ResponseInfo response = remoteCallReturn.getResponseInfo();
    Object[] logArgs = new Object[10];
    if (request != null) {
        logArgs[0] = request.getServiceName();
        logArgs[1] = request.getMethodName();
        logArgs[2] = request.getContextName();
        logArgs[3] = request.getContextValue();
        logArgs[4] = request.getUrl();
    }
    if (response != null) {
        logArgs[5] = response.getRequestId();
        logArgs[6] = response.getResponseTime();
        logArgs[7] = response.getOperationsCount();
        Throwable throwable = remoteCallReturn.getException();
        logArgs[8] = throwable != null;
        logArgs[9] = truncateThrowable(throwable, MAX_SUMMARY_ERROR_LENGTH);
    }
    if (isSuccess) {
        summaryLogger.info(SUMMARY_TEMPLATE, logArgs);
    } else {
        summaryLogger.warn(SUMMARY_TEMPLATE, logArgs);
    }
}
Also used : ResponseInfo(com.google.api.ads.common.lib.client.ResponseInfo) RequestInfo(com.google.api.ads.common.lib.client.RequestInfo)

Example 12 with ResponseInfo

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

the class RemoteCallLoggerDelegateTest method setUp.

@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    loggerDelegate = new RemoteCallLoggerDelegate(requestInfoLogger, soapXmlLogger, prettyPrinter, RemoteCallType.SOAP);
    RequestInfo requestInfo = new RequestInfo.Builder().withContext("clientCustomerId", "555-555-0000").withServiceName("test service").withMethodName("test method").withUrl("http://www.example.com").withPayload(requestXml).build();
    ResponseInfo responseInfo = new ResponseInfo.Builder().withRequestId("abc123def456").withOperationsCount(1_234L).withResponseTimeMillis(543_210L).withPayload(responseXml).build();
    remoteCallReturn = new RemoteCallReturn.Builder().withException(null).withRequestInfo(requestInfo).withResponseInfo(responseInfo).withReturnValue("some object").build();
    when(prettyPrinter.prettyPrint(requestXml)).thenReturn(prettyRequest);
    when(prettyPrinter.prettyPrint(responseXml)).thenReturn(prettyResponse);
}
Also used : ResponseInfo(com.google.api.ads.common.lib.client.ResponseInfo) RequestInfo(com.google.api.ads.common.lib.client.RequestInfo) Before(org.junit.Before)

Aggregations

ResponseInfo (com.google.api.ads.common.lib.client.ResponseInfo)12 RequestInfo (com.google.api.ads.common.lib.client.RequestInfo)10 Test (org.junit.Test)8 RemoteCallReturn (com.google.api.ads.common.lib.client.RemoteCallReturn)6 Matchers.containsString (org.hamcrest.Matchers.containsString)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 Builder (com.google.api.ads.common.lib.client.ResponseInfo.Builder)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 SOAPHeader (javax.xml.soap.SOAPHeader)1 SOAPMessage (javax.xml.soap.SOAPMessage)1 Before (org.junit.Before)1