@Override public String toString() { return getMessage() + " caused by: [" + trigger + "]"; } }
/** Validates the properties for the Ad Manager session. */ private void validate() throws ValidationException { // Check for at least one authentication mechanism. if (this.oAuth2Credential == null) { throw new ValidationException("OAuth2 authentication must be used.", ""); } // Check that application name is not empty or the default. if (Strings.nullToEmpty(applicationName).trim().isEmpty() || applicationName.contains(DEFAULT_APPLICATION_NAME)) { throw new ValidationException( String.format( "Application name must be set and not be the default [%s]", DEFAULT_APPLICATION_NAME), "applicationName"); } // Make sure they specify a valid endpoint. try { new URL(this.endpoint); } catch (MalformedURLException e) { throw new ValidationException( String.format("Endpoint [%s] not recognized as a valid URL.", this.endpoint), "endpoint", e); } } }
@Override protected boolean matchesSafely(ValidationException ve) { return matcher.matches(ve.getTrigger()); } };
/** * @see SoapClientHandler#setHeader(Object, String, String, Object) */ @Override public void setHeader(BindingProvider soapClient, String namespace, String headerName, Object headerValue) { if (headerValue instanceof SOAPElement) { getContextHandlerFromClient(soapClient).addHeader(namespace, headerName, (SOAPElement) headerValue); } else { throw new ServiceException("Unexpected SOAP header given for JAX-WS binding. Given " + "object of class \"" + headerValue.getClass().toString() + "\" but expecting " + "object of class \"" + SOAPElement.class + "\".", null); } }
/** * Generates a new offline credential and immediately refreshes it. * * @return a newly refreshed offline credential. * @throws OAuthException if the credential could not be refreshed. */ public Credential generateCredential() throws OAuthException { GoogleCredential credential = Strings.isNullOrEmpty(this.jsonKeyFilePath) ? generateCredentialFromClientSecrets() : generateCredentialFromKeyFile(); try { if (!oAuth2Helper.callRefreshToken(credential)) { throw new OAuthException( "Credential could not be refreshed. A newly generated refresh token or " + "secret key may be required."); } } catch (IOException e) { throw new OAuthException("Credential could not be refreshed.", e); } return credential; }
/** * @see SoapClientHandler#setHeader(Object, String, String, Object) */ @Override public void setHeader(BindingProvider soapClient, String namespace, String headerName, Object headerValue) { if (headerValue instanceof SOAPElement) { getContextHandlerFromClient(soapClient).addHeader(namespace, headerName, (SOAPElement) headerValue); } else { throw new ServiceException("Unexpected SOAP header given for JAX-WS binding. Given " + "object of class \"" + headerValue.getClass().toString() + "\" but expecting " + "object of class \"" + SOAPElement.class + "\".", null); } }
/** * Generates a new offline credential and immediately refreshes it. * * @return a newly refreshed offline credential. * @throws OAuthException if the credential could not be refreshed. */ public Credential generateCredential() throws OAuthException { GoogleCredential credential = Strings.isNullOrEmpty(this.jsonKeyFilePath) ? generateCredentialFromClientSecrets() : generateCredentialFromKeyFile(); try { if (!oAuth2Helper.callRefreshToken(credential)) { throw new OAuthException( "Credential could not be refreshed. A newly generated refresh token or " + "secret key may be required."); } } catch (IOException e) { throw new OAuthException("Credential could not be refreshed.", e); } return credential; }
@Override public String toString() { return getMessage() + " caused by: [" + trigger + "]"; } }
/** Validates the properties for the Ad Manager session. */ private void validate() throws ValidationException { // Check for at least one authentication mechanism. if (this.oAuth2Credential == null) { throw new ValidationException("OAuth2 authentication must be used.", ""); } // Check that application name is not empty or the default. if (Strings.nullToEmpty(applicationName).trim().isEmpty() || applicationName.contains(DEFAULT_APPLICATION_NAME)) { throw new ValidationException( String.format( "Application name must be set and not be the default [%s]", DEFAULT_APPLICATION_NAME), "applicationName"); } // Make sure they specify a valid endpoint. try { new URL(this.endpoint); } catch (MalformedURLException e) { throw new ValidationException( String.format("Endpoint [%s] not recognized as a valid URL.", this.endpoint), "endpoint", e); } } }
@Override protected boolean matchesSafely(ValidationException ve) { return matcher.matches(ve.getTrigger()); } };
/** * Updates the child attribute of headerName named childName to childValue. * * @param soapClient the stub * @param parentHeaderName the name of the parent header * @param childName the name of the child * @param childValue the value for the child * * @throws NullPointerException if no header exists named parentHeaderName */ public void setHeaderChild(Stub soapClient, String parentHeaderName, String childName, Object childValue) { SOAPHeaderElement headerElement = (SOAPHeaderElement) getHeader(soapClient, parentHeaderName); Object headerObject = Preconditions.checkNotNull(headerElement, "Parent header named %s does not exist", parentHeaderName).getObjectValue(); try { BeanUtils.setProperty(headerObject, childName, childValue); } catch (IllegalAccessException e) { throw new ServiceException("Failed to set header child " + childName, e); } catch (InvocationTargetException e) { throw new ServiceException("Failed to set header child " + childName, e); } }
/** * 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); } }
/** * Validates the {@code GoogleClientSecrets} object. * @throws ValidationException if the {@code GoogleClientSecrets} did not * validate */ private void validate() throws ValidationException { if (Strings.isNullOrEmpty(clientId) || clientId.startsWith("INSERT_CLIENT_ID_HERE")) { throw new ValidationException(String.format( "Client ID must be set%s\nIf you do not have a client ID or secret, " + "please create one in the API console: https://console.developers.google.com", filePath != null ? generateFilePathWarning("clientId") : "."), "clientId"); } if (Strings.isNullOrEmpty(clientSecret) || clientId.startsWith("INSERT_CLIENT_SECRET_HERE")) { throw new ValidationException(String.format( "Client secret must be set%s\nIf you do not have a client ID or secret, " + "please create one in the API console: https://console.developers.google.com", filePath != null ? generateFilePathWarning("clientSecret") : "."), "clientSecret"); } }
/** * Updates the child attribute of headerName named childName to childValue. * * @param soapClient the stub * @param parentHeaderName the name of the parent header * @param childName the name of the child * @param childValue the value for the child * * @throws NullPointerException if no header exists named parentHeaderName */ public void setHeaderChild(Stub soapClient, String parentHeaderName, String childName, Object childValue) { SOAPHeaderElement headerElement = (SOAPHeaderElement) getHeader(soapClient, parentHeaderName); Object headerObject = Preconditions.checkNotNull(headerElement, "Parent header named %s does not exist", parentHeaderName).getObjectValue(); try { BeanUtils.setProperty(headerObject, childName, childValue); } catch (IllegalAccessException e) { throw new ServiceException("Failed to set header child " + childName, e); } catch (InvocationTargetException e) { throw new ServiceException("Failed to set header child " + childName, e); } }
/** * 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); } }
/** * Validates the {@code GoogleClientSecrets} object. * @throws ValidationException if the {@code GoogleClientSecrets} did not * validate */ private void validate() throws ValidationException { if (Strings.isNullOrEmpty(clientId) || clientId.startsWith("INSERT_CLIENT_ID_HERE")) { throw new ValidationException(String.format( "Client ID must be set%s\nIf you do not have a client ID or secret, " + "please create one in the API console: https://console.developers.google.com", filePath != null ? generateFilePathWarning("clientId") : "."), "clientId"); } if (Strings.isNullOrEmpty(clientSecret) || clientId.startsWith("INSERT_CLIENT_SECRET_HERE")) { throw new ValidationException(String.format( "Client secret must be set%s\nIf you do not have a client ID or secret, " + "please create one in the API console: https://console.developers.google.com", filePath != null ? generateFilePathWarning("clientSecret") : "."), "clientSecret"); } }
/** * @see SoapClientHandler#setHeader(Object, String, String, Object) */ @Override public void setHeader(Stub soapClient, String namespace, String headerName, Object headerValue) { try { QName qName = new QName(namespace, headerName); SOAPHeaderElement soapHeaderElement = new SOAPHeaderElement(qName); soapHeaderElement.setObjectValue(headerValue); soapHeaderElement.setActor(null); soapClient.setHeader(soapHeaderElement); } catch (SOAPException e) { throw new ServiceException("Could not set header.", e); } }
/** * @see SoapClientHandler#setHeader(Object, String, String, Object) */ @Override public void setHeader(Stub soapClient, String namespace, String headerName, Object headerValue) { try { QName qName = new QName(namespace, headerName); SOAPHeaderElement soapHeaderElement = new SOAPHeaderElement(qName); soapHeaderElement.setObjectValue(headerValue); soapHeaderElement.setActor(null); soapClient.setHeader(soapHeaderElement); } catch (SOAPException e) { throw new ServiceException("Could not set header.", e); } }
/** * Creates an {@link AdsServiceClient} given an {@link AdsServiceDescriptor} * descriptor and an {@link AdsSession}. * * @param adsServiceDescriptor descriptor with information on ads service * @param adsSession the session associated with the desired * client * @return the created {@link AdsServiceClient} * @throws ServiceException if the ads service client could not be created */ @Override public C createAdsServiceClient(D adsServiceDescriptor, S adsSession) throws ServiceException { Object soapClient = createSoapClient(adsServiceDescriptor); C adsServiceClient = createServiceClient(soapClient, adsServiceDescriptor, adsSession); try { adsServiceClient.setEndpointAddress(adsServiceDescriptor.getEndpointAddress(adsSession .getEndpoint())); } catch (MalformedURLException e) { throw new ServiceException("Unexpected exception", e); } return adsServiceClient; }
/** * Creates an {@link AdsServiceClient} given an {@link AdsServiceDescriptor} * descriptor and an {@link AdsSession}. * * @param adsServiceDescriptor descriptor with information on ads service * @param adsSession the session associated with the desired * client * @return the created {@link AdsServiceClient} * @throws ServiceException if the ads service client could not be created */ @Override public C createAdsServiceClient(D adsServiceDescriptor, S adsSession) throws ServiceException { Object soapClient = createSoapClient(adsServiceDescriptor); C adsServiceClient = createServiceClient(soapClient, adsServiceDescriptor, adsSession); try { adsServiceClient.setEndpointAddress(adsServiceDescriptor.getEndpointAddress(adsSession .getEndpoint())); } catch (MalformedURLException e) { throw new ServiceException("Unexpected exception", e); } return adsServiceClient; }