Search in sources :

Example 11 with RequestInfo

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

the class ReportServiceLoggerTest method testBuildInfos_failure.

@Test
public void testBuildInfos_failure() {
    RequestInfo requestInfo = reportServiceLogger.buildRequestInfo(httpRequest);
    checkRequestInfoAttributes(requestInfo, true);
    ResponseInfo responseInfo = reportServiceLogger.buildResponseInfo(httpRequest, HttpStatusCodes.STATUS_CODE_BAD_GATEWAY, "Bad gateway");
    checkResponseInfoAttributes(responseInfo, HttpStatusCodes.STATUS_CODE_BAD_GATEWAY, "Bad gateway");
}
Also used : ResponseInfo(com.google.api.ads.common.lib.client.ResponseInfo) RequestInfo(com.google.api.ads.common.lib.client.RequestInfo) Test(org.junit.Test)

Example 12 with RequestInfo

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

the class ReportServiceLoggerTest method testBuildInfos_success.

@Test
public void testBuildInfos_success() {
    RequestInfo requestInfo = reportServiceLogger.buildRequestInfo(httpRequest);
    checkRequestInfoAttributes(requestInfo, true);
    ResponseInfo responseInfo = reportServiceLogger.buildResponseInfo(httpRequest, HttpStatusCodes.STATUS_CODE_OK, null);
    checkResponseInfoAttributes(responseInfo, HttpStatusCodes.STATUS_CODE_OK, null);
}
Also used : ResponseInfo(com.google.api.ads.common.lib.client.ResponseInfo) RequestInfo(com.google.api.ads.common.lib.client.RequestInfo) Test(org.junit.Test)

Example 13 with RequestInfo

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

the class RequestInfoXPathSetTest method testParseActualMessage.

@Test
public void testParseActualMessage() throws SOAPException, IOException, TransformerException {
    Builder builder = new Builder();
    SOAPMessage message = Mockito.mock(SOAPMessage.class);
    SOAPHeader header = Mockito.mock(SOAPHeader.class);
    SOAPPart soapPart = Mockito.mock(SOAPPart.class);
    when(message.getSOAPHeader()).thenReturn(header);
    when(message.getSOAPPart()).thenReturn(soapPart);
    final String payload = "<foo><bar>MyBar</bar></foo>";
    when(transformerSupplier.get()).thenReturn(transformer);
    doAnswer(invocation -> {
        StreamResult streamResult = (StreamResult) invocation.getArguments()[1];
        streamResult.getOutputStream().write(payload.getBytes(StandardCharsets.UTF_8));
        return null;
    }).when(transformer).transform(any(), any());
    assertSame("parseMessage should return the same builder passed in", builder, xPathSet.parseMessage(builder, message));
    RequestInfo requestInfo = builder.build();
    assertEquals("Payload doesn't match", payload, requestInfo.getPayload());
    assertEquals("Context name doesn't match", "bar", requestInfo.getContextName());
}
Also used : StreamResult(javax.xml.transform.stream.StreamResult) Builder(com.google.api.ads.common.lib.client.RequestInfo.Builder) SOAPPart(javax.xml.soap.SOAPPart) RequestInfo(com.google.api.ads.common.lib.client.RequestInfo) SOAPMessage(javax.xml.soap.SOAPMessage) SOAPHeader(javax.xml.soap.SOAPHeader) Test(org.junit.Test)

Example 14 with RequestInfo

use of com.google.api.ads.common.lib.client.RequestInfo 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 15 with RequestInfo

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

the class JaxWsSoapContextHandlerTest method testCaptureServiceAndOperationNames.

@Test
public void testCaptureServiceAndOperationNames() throws Exception {
    when(mockSoapMessageContext.get(MessageContext.WSDL_SERVICE)).thenReturn(wsdlService);
    when(mockSoapMessageContext.getMessage()).thenReturn(mockMessage);
    when(mockMessage.getSOAPBody()).thenReturn(mockSoapBody);
    when(mockSoapBody.getFirstChild()).thenReturn(firstChild);
    when(firstChild.getLocalName()).thenReturn(OPERATION_LOCAL_NAME);
    jaxWsSoapContextHandler.captureServiceAndOperationNames(mockSoapMessageContext);
    RequestInfo requestInfo = jaxWsSoapContextHandler.getLastRequestInfoBuilder().build();
    assertEquals(wsdlService.getLocalPart(), requestInfo.getServiceName());
    assertEquals(OPERATION_LOCAL_NAME, requestInfo.getMethodName());
}
Also used : RequestInfo(com.google.api.ads.common.lib.client.RequestInfo) Test(org.junit.Test)

Aggregations

RequestInfo (com.google.api.ads.common.lib.client.RequestInfo)16 ResponseInfo (com.google.api.ads.common.lib.client.ResponseInfo)11 Test (org.junit.Test)11 RemoteCallReturn (com.google.api.ads.common.lib.client.RemoteCallReturn)6 SOAPException (javax.xml.soap.SOAPException)3 SOAPHeader (javax.xml.soap.SOAPHeader)3 SOAPMessage (javax.xml.soap.SOAPMessage)3 SOAPPart (javax.xml.soap.SOAPPart)3 StreamResult (javax.xml.transform.stream.StreamResult)3 Before (org.junit.Before)3 AdsApiConfiguration (com.google.api.ads.common.lib.conf.AdsApiConfiguration)2 RequestInfoXPathSet (com.google.api.ads.common.lib.soap.RequestInfoXPathSet)2 ResponseInfoXPathSet (com.google.api.ads.common.lib.soap.ResponseInfoXPathSet)2 NodeExtractor (com.google.api.ads.common.lib.utils.NodeExtractor)2 Streams (com.google.api.ads.common.lib.utils.Streams)2 Supplier (com.google.common.base.Supplier)2 OutputStream (java.io.OutputStream)2 Charset (java.nio.charset.Charset)2 HashSet (java.util.HashSet)2 Set (java.util.Set)2