/** * Creates the SOAP client from the SOAP client handler. */ @VisibleForTesting Object createSoapClient(D adsServiceDescriptor) { return soapClientHandler.createSoapClient(adsServiceDescriptor); }
/** Sets the HTTP headers on the SOAP client. */ @SuppressWarnings("unchecked") /* See constructor comments. */ public void setHttpHeaders(Object soapClient, AdManagerSession adManagerSession) { Map<String, String> headersMap = Maps.newHashMap(); soapClientHandler.putAllHttpHeaders(soapClient, headersMap); }
/** * Called from {@link #invoke(Object, Method, Object[])} if the method is * intended for the SOAP client. Extending classes should override this method * if they wish to wrap the call, such in cases of reauthentication or * exception handling. The actual SOAP call is synchronized on the SOAP client * so that only one request to the SOAP client can be made with without * interruption, useful for logging and exception handling. * * @param soapCall the call to send to the SOAP client * @return the return value from the {@code soapCall} */ protected synchronized RemoteCallReturn callSoapClient(SoapCall<T> soapCall) { return soapClientHandler.invokeSoapCall(soapCall); }
/** * Sets the authorization header created from the session on the soap client. * * @param soapClient the SOAP client to set the HTTP header on * @param adsSession the session * @throws AuthenticationException if the authorization header could not be * created */ @SuppressWarnings("unchecked") /* See constructor comments. */ public void setAuthorization(Object soapClient, AdsSession adsSession) throws AuthenticationException { final String authorizationHeader = authorizationHeaderProvider.getAuthorizationHeader(adsSession, soapClientHandler.getEndpointAddress(soapClient)); soapClientHandler.putAllHttpHeaders(soapClient, new HashMap<String, String>() { { put("Authorization", authorizationHeader); } }); } }
@Override protected void setHeaders() throws ServiceException, AuthenticationException { getSoapClientHandler().clearHeaders(getSoapClient()); headerHandler.setHeaders(getSoapClient(), adsSession, adsServiceDescriptor); } }
/** * Sets the endpoint address of the underlying SOAP client. */ public void setEndpointAddress(String endpointAddress) { soapClientHandler.setEndpointAddress(soapClient, endpointAddress); }
createSoapCall(soapClientHandler.getSoapClientMethod(soapClient, method), args)); logSoapCall(remoteCallReturn); return unwrapRemoteCallReturn(remoteCallReturn);
/** * Sets the authorization header created from the session on the soap client. * * @param soapClient the SOAP client to set the HTTP header on * @param adsSession the session * @throws AuthenticationException if the authorization header could not be * created */ @SuppressWarnings("unchecked") /* See constructor comments. */ public void setAuthorization(Object soapClient, AdsSession adsSession) throws AuthenticationException { final String authorizationHeader = authorizationHeaderProvider.getAuthorizationHeader(adsSession, soapClientHandler.getEndpointAddress(soapClient)); soapClientHandler.putAllHttpHeaders(soapClient, new HashMap<String, String>() { { put("Authorization", authorizationHeader); } }); } }
@Override protected void setHeaders() throws ServiceException, AuthenticationException { getSoapClientHandler().clearHeaders(getSoapClient()); headerHandler.setHeaders(getSoapClient(), adsSession, adsServiceDescriptor); } }
/** * Sets the endpoint address of the underlying SOAP client. */ public void setEndpointAddress(String endpointAddress) { soapClientHandler.setEndpointAddress(soapClient, endpointAddress); }
createSoapCall(soapClientHandler.getSoapClientMethod(soapClient, method), args)); logSoapCall(remoteCallReturn); return unwrapRemoteCallReturn(remoteCallReturn);
@SuppressWarnings("unchecked") @Test public void testSetAuthorization() throws Exception { String authorizationHeaderValue = "IAmAuthorized"; final String endpoint = "endpoint"; Object soapClient = new Object(); AdsSession adsSession = () -> endpoint; @SuppressWarnings("rawtypes") ArgumentCaptor<Map> headers = ArgumentCaptor.forClass(Map.class); when(soapClientHandler.getEndpointAddress(soapClient)).thenReturn(endpoint); when(authorizationHeaderProvider.getAuthorizationHeader( same(adsSession), eq(endpoint))).thenReturn(authorizationHeaderValue); authorizationHeaderHandler.setAuthorization(soapClient, adsSession); verify(soapClientHandler).putAllHttpHeaders(eq(soapClient), headers.capture()); String actualAuthorizationHeaderValue = (String) headers.getValue().get("Authorization"); assertEquals(authorizationHeaderValue, actualAuthorizationHeaderValue); } }
/** * Creates the SOAP client from the SOAP client handler. */ @VisibleForTesting Object createSoapClient(D adsServiceDescriptor) { return soapClientHandler.createSoapClient(adsServiceDescriptor); }
/** Sets the HTTP headers on the SOAP client. */ @SuppressWarnings("unchecked") /* See constructor comments. */ public void setHttpHeaders(Object soapClient, AdManagerSession adManagerSession) { Map<String, String> headersMap = Maps.newHashMap(); soapClientHandler.putAllHttpHeaders(soapClient, headersMap); }
@Test public void testSetHeaders() throws Exception { adsServiceClient.setHeaders(); verify(soapClientHandler).clearHeaders(soapClient); verify(headerHandler).setHeaders(soapClient, adsSession, adsServiceDescriptor); } }
/** * Called from {@link #invoke(Object, Method, Object[])} if the method is * intended for the SOAP client. Extending classes should override this method * if they wish to wrap the call, such in cases of reauthentication or * exception handling. The actual SOAP call is synchronized on the SOAP client * so that only one request to the SOAP client can be made with without * interruption, useful for logging and exception handling. * * @param soapCall the call to send to the SOAP client * @return the return value from the {@code soapCall} */ protected synchronized RemoteCallReturn callSoapClient(SoapCall<T> soapCall) { return soapClientHandler.invokeSoapCall(soapCall); }
@Test public void testCreateSoapClient() { when(soapClientHandler.createSoapClient(adsServiceDescriptor)) .thenReturn(soapClient); Object testSoapClient = abstractAdsServiceClientFactoryHelper.createSoapClient(adsServiceDescriptor); assertSame(soapClient, testSoapClient); }
/** * Tests setting the headers. */ @SuppressWarnings("unchecked") @Test public void testSetHeaders() throws Exception { Object soapClient = new Object(); Credential credential = new Credential(BearerToken.authorizationHeaderAccessMethod()); AdManagerSession adManagerSession = new AdManagerSession.Builder() .withApplicationName("FooBar") .withOAuth2Credential(credential) .withEndpoint("https://ads.google.com") .withNetworkCode("networkCode") .build(); adManagerHttpHeaderHandler.setHttpHeaders(soapClient, adManagerSession); verify(soapClientHandler).putAllHttpHeaders(eq(soapClient), any(Map.class)); }
@Test public void testCreateAdsServiceClient() { when(soapClientHandler.createSoapClient(adsServiceDescriptor)).thenReturn(soapClient); when(adsServiceClientFactory.create(soapClient, adsServiceDescriptor, adsSession)) .thenReturn(adsServiceClient); AdsServiceClient<AdsSession, AdsServiceDescriptor> testAdsServiceClient = abstractAdsServiceClientFactoryHelper.createAdsServiceClient(adsServiceDescriptor, adsSession); assertSame(adsServiceClient, testAdsServiceClient); }