/** 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); }
/** 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); }
/** * 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); } }); } }
/** * 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); } }); } }
@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); } }
/** * 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)); }