@Override public EngineConfiguration getClientEngineConfig() { // Only return the custom configuration for compression if the client config has not // been overridden. if (System.getProperty(EngineConfigurationFactoryDefault.OPTION_CLIENT_CONFIG_FILE) == null && adsLibConfiguration.isCompressionEnabled()) { return new FileProvider( this.getClass().getResourceAsStream("wsdd/ads-axis-client-config.wsdd")); } return wrappedFactory.getClientEngineConfig(); }
/** @see AdsServiceClientFactoryHelper#determineVersion(Class) */ @Override public String determineVersion(Class<?> interfaceClass) { Matcher m = VERSION_PATTERN.matcher(interfaceClass.getPackage().getName()); if (m.matches()) { String version = m.group(1); return version.replace('_', '.'); } else { return adsLibConfiguration.getDuckTypedVersion(); } } }
@Override public boolean isIncludeAdsUtilitiesInUserAgent() { Boolean isInclude = config.getBoolean( KEY_PREFIX + "." + INCLUDE_UTILITIES_IN_USER_AGENT_POSTFIX, null); return isInclude != null ? isInclude : super.isIncludeAdsUtilitiesInUserAgent(); }
/** * @see HeaderHandler#setHeaders(Object, * com.google.api.ads.common.lib.client.AdsSession, * com.google.api.ads.common.lib.client.AdsServiceDescriptor) */ @Override public void setHeaders(Object soapClient, AdWordsSession adWordsSession, AdWordsServiceDescriptor adWordsServiceDescriptor) throws AuthenticationException, ServiceException { Preconditions.checkArgument( soapClient instanceof BindingProvider, "soapClient must be BindingProvider but was: %s", soapClient); BindingProvider bindingProvider = (BindingProvider) soapClient; Map<String, Object> headerData = readHeaderElements(adWordsSession); setAuthenticationHeaders(soapClient, headerData, adWordsSession); soapClientHandler.setHeader( bindingProvider, null, null, constructSoapHeader(headerData, adWordsServiceDescriptor)); soapClientHandler.setCompression(bindingProvider, adsLibConfiguration.isCompressionEnabled()); soapClientHandler.setRequestTimeout( bindingProvider, adsLibConfiguration.getSoapRequestTimeout()); }
/** * Gets the OAuth2 header. * * @throws OAuthException if the OAuth2 token could not be refreshed. */ private String getOAuth2Header(OAuth2Compatible oAuth2Compatible) throws OAuthException { if (adsLibConfiguration.isAutoRefreshOAuth2TokenEnabled()) { try { oAuth2Helper.refreshCredential(oAuth2Compatible.getOAuth2Credential()); } catch (IOException e) { throw new OAuthException("OAuth2 token could not be refreshed.", e); } } return oAuth2AuthorizationHeaderProvider.getOAuth2AuthorizationHeader(oAuth2Compatible); } }
/** * Is the proxy set automatically when making HTTP (non-SOAP) clients calls. */ public boolean isAutoSetProxy() { return getBoolean(AUTO_SET_PROXY_KEY); }
/** * @see HeaderHandler#setHeaders(Object, com.google.api.ads.common.lib.client.AdsSession, * com.google.api.ads.common.lib.client.AdsServiceDescriptor) */ @Override public void setHeaders( Object soapClient, AdManagerSession adManagerSession, AdManagerServiceDescriptor adManagerServiceDescriptor) throws AuthenticationException, ServiceException { Preconditions.checkArgument( soapClient instanceof BindingProvider, "soapClient must be BindingProvider but was: %s", soapClient); BindingProvider bindingProvider = (BindingProvider) soapClient; adManagerHttpHeaderHandler.setHttpHeaders(soapClient, adManagerSession); Map<String, Object> headerData = readHeaderElements(adManagerSession); setAuthenticationHeaders(soapClient, adManagerSession); soapClientHandler.setHeader( bindingProvider, null, null, constructSoapHeader(headerData, adManagerServiceDescriptor)); soapClientHandler.setCompression(bindingProvider, adsLibConfiguration.isCompressionEnabled()); soapClientHandler.setRequestTimeout( bindingProvider, adsLibConfiguration.getSoapRequestTimeout()); }
/** * Gets the OAuth2 header. * * @throws OAuthException if the OAuth2 token could not be refreshed. */ private String getOAuth2Header(OAuth2Compatible oAuth2Compatible) throws OAuthException { if (adsLibConfiguration.isAutoRefreshOAuth2TokenEnabled()) { try { oAuth2Helper.refreshCredential(oAuth2Compatible.getOAuth2Credential()); } catch (IOException e) { throw new OAuthException("OAuth2 token could not be refreshed.", e); } } return oAuth2AuthorizationHeaderProvider.getOAuth2AuthorizationHeader(oAuth2Compatible); } }
/** * Is the proxy set automatically when making HTTP (non-SOAP) clients calls. */ public boolean isAutoSetProxy() { return getBoolean(AUTO_SET_PROXY_KEY); }
adWordsSession.isPartialFailure()); soapClientHandler.setCompression(stub, adsLibConfiguration.isCompressionEnabled()); soapClientHandler.setRequestTimeout(stub, adsLibConfiguration.getSoapRequestTimeout());
@Override public EngineConfiguration getClientEngineConfig() { // Only return the custom configuration for compression if the client config has not // been overridden. if (System.getProperty(EngineConfigurationFactoryDefault.OPTION_CLIENT_CONFIG_FILE) == null && adsLibConfiguration.isCompressionEnabled()) { return new FileProvider( this.getClass().getResourceAsStream("wsdd/ads-axis-client-config.wsdd")); } return wrappedFactory.getClientEngineConfig(); }
@Override public boolean isIncludeAdsUtilitiesInUserAgent() { Boolean isInclude = config.getBoolean( KEY_PREFIX + "." + INCLUDE_UTILITIES_IN_USER_AGENT_POSTFIX, null); return isInclude != null ? isInclude : super.isIncludeAdsUtilitiesInUserAgent(); }
/** @see AdsServiceClientFactoryHelper#determineVersion(Class) */ @Override public String determineVersion(Class<?> interfaceClass) { Matcher m = VERSION_PATTERN.matcher(interfaceClass.getPackage().getName()); if (m.matches()) { String version = m.group(1); return version.replace('_', '.'); } else { return adsLibConfiguration.getDuckTypedVersion(); } } }
@Test public void testGetAuthorizationHeader_oAuth2NoRefresh() throws Exception { final Credential credential = new Credential(BearerToken.authorizationHeaderAccessMethod()); OAuth2Session adsSession = () -> credential; when(oAuth2AuthorizationHeaderProvider.getOAuth2AuthorizationHeader( (OAuth2Compatible) adsSession)).thenReturn("OAuth2 Header"); when(adsLibConfiguration.isAutoRefreshOAuth2TokenEnabled()).thenReturn(false); assertEquals("OAuth2 Header", authorizationHeaderProvider.getAuthorizationHeader(adsSession, ENDPOINT_URL.toString())); verify(oAuth2Helper, times(0)).refreshCredential(credential); }
+ adManagerServiceDescriptor.getVersion(); soapClientHandler.setHeader(stub, namespace, "RequestHeader", soapHeader); soapClientHandler.setCompression(stub, adsLibConfiguration.isCompressionEnabled()); soapClientHandler.setRequestTimeout(stub, adsLibConfiguration.getSoapRequestTimeout()); } catch (InstantiationException e) { throw new ServiceException("Unexpected exception.", e);
@Override public String getUserAgent() { Set<AdsUtility> adsUtilities = adsUtilityRegistry.popRegisteredUtilities(); if (!adsLibConfiguration.isIncludeAdsUtilitiesInUserAgent() || adsUtilities.isEmpty()) { return null; } // Adheres to User-Agent product identifiers from RFC 7231. // https://tools.ietf.org/html/rfc7231#section-5.5.3 // Sorts the collection of utilities so output is deterministic. return Joiner.on(", ").skipNulls().join( Sets.newTreeSet(Collections2.transform(adsUtilities, ADS_UTILITY_FUNCTION))); } }
/** * @see AdsServiceClientFactoryHelper#determineVersion(Class) */ @Override public String determineVersion(Class<?> interfaceClass) { Matcher m = VERSION_PATTERN.matcher(interfaceClass.getPackage().getName()); if (m.matches()) { return m.group(1); } else { return adsLibConfiguration.getDuckTypedVersion(); } } }
@Test public void testGetAuthorizationHeader_oAuth2Refresh() throws Exception { final Credential credential = new Credential(BearerToken.authorizationHeaderAccessMethod()); OAuth2Session adsSession = () -> credential; when(oAuth2AuthorizationHeaderProvider.getOAuth2AuthorizationHeader( (OAuth2Compatible) adsSession)).thenReturn("OAuth2 Header"); when(adsLibConfiguration.isAutoRefreshOAuth2TokenEnabled()).thenReturn(true); assertEquals("OAuth2 Header", authorizationHeaderProvider.getAuthorizationHeader(adsSession, ENDPOINT_URL.toString())); verify(oAuth2Helper).refreshCredential(credential); }
adWordsSession.isPartialFailure()); soapClientHandler.setCompression(stub, adsLibConfiguration.isCompressionEnabled()); soapClientHandler.setRequestTimeout(stub, adsLibConfiguration.getSoapRequestTimeout());
@Override public String getUserAgent() { Set<AdsUtility> adsUtilities = adsUtilityRegistry.popRegisteredUtilities(); if (!adsLibConfiguration.isIncludeAdsUtilitiesInUserAgent() || adsUtilities.isEmpty()) { return null; } // Adheres to User-Agent product identifiers from RFC 7231. // https://tools.ietf.org/html/rfc7231#section-5.5.3 // Sorts the collection of utilities so output is deterministic. return Joiner.on(", ").skipNulls().join( Sets.newTreeSet(Collections2.transform(adsUtilities, ADS_UTILITY_FUNCTION))); } }