@Test @SuppressWarnings("unchecked") public void testSetHeaders() throws ServiceException, AuthenticationException { String namespacePrefix = "http: String topLevelNamespace = String.format("http: String namespace = "http: Map<String, String> expectedHeaders = new HashMap<String, String>(); String libSig = "libSig"; adWordsSession.setValidateOnly(true); expectedHeaders.put("developerToken", DEVELOPER_TOKEN); expectedHeaders.put("clientCustomerId", CLIENT_CUSTOMER_ID); expectedHeaders.put("validateOnly", "true"); expectedHeaders.put("userAgent", libSig); when(adWordsApiConfiguration.getNamespacePrefix()).thenReturn(namespacePrefix); when(userAgentCombiner.getUserAgent(USER_AGENT)).thenReturn(libSig); headerHandler.setHeaders(soapClient, adWordsSession, adWordsServiceDescriptor); ArgumentCaptor<Object> headerArg = ArgumentCaptor.forClass(Object.class); verify(soapClientHandler).setHeader(eq(soapClient), (String) eq(null), (String) eq(null), headerArg.capture()); if (headerArg.getValue() instanceof SOAPElement) { SOAPElement soapValue = (SOAPElement) headerArg.getValue(); assertEquals("RequestHeader", soapValue.getLocalName()); assertEquals(topLevelNamespace, soapValue.getNamespaceURI()); ArrayList<Node> children = Lists.newArrayList(soapValue.getChildElements()); assertEquals(expectedHeaders.size(), children.size()); children.forEach( child -> { assertEquals(namespace, child.getNamespaceURI()); assertTrue(child.getLocalName(), expectedHeaders.containsKey(child.getLocalName())); assertEquals( child.getLocalName(), expectedHeaders.get(child.getLocalName()), child.getFirstChild().getTextContent()); }); } else { fail("Generated headerValue is not a SOAPElement: " + headerArg.getValue()); } }
@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()); }
AdWordsJaxWsHeaderHandler implements
    HeaderHandler<AdWordsSession, AdWordsServiceDescriptor> { @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()); } }
AdWordsJaxWsHeaderHandler implements
    HeaderHandler<AdWordsSession, AdWordsServiceDescriptor> { @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()); } @Inject  AdWordsJaxWsHeaderHandler(
      JaxWsHandler soapClientHandler,
      AdWordsApiConfiguration adWordsApiConfiguration,
      AdsLibConfiguration adsLibConfiguration,
      AuthorizationHeaderHandler authorizationHeaderHandler,
      UserAgentCombiner userAgentCombiner); }
AdWordsJaxWsHeaderHandler implements
    HeaderHandler<AdWordsSession, AdWordsServiceDescriptor> { @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()); } @Inject  AdWordsJaxWsHeaderHandler(
      JaxWsHandler soapClientHandler,
      AdWordsApiConfiguration adWordsApiConfiguration,
      AdsLibConfiguration adsLibConfiguration,
      AuthorizationHeaderHandler authorizationHeaderHandler,
      UserAgentCombiner userAgentCombiner); @Override void setHeaders(Object soapClient, AdWordsSession adWordsSession,
      AdWordsServiceDescriptor adWordsServiceDescriptor); }
AdWordsJaxWsHeaderHandler implements
    HeaderHandler<AdWordsSession, AdWordsServiceDescriptor> { @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()); } @Inject  AdWordsJaxWsHeaderHandler(
      JaxWsHandler soapClientHandler,
      AdWordsApiConfiguration adWordsApiConfiguration,
      AdsLibConfiguration adsLibConfiguration,
      AuthorizationHeaderHandler authorizationHeaderHandler,
      UserAgentCombiner userAgentCombiner); @Override void setHeaders(Object soapClient, AdWordsSession adWordsSession,
      AdWordsServiceDescriptor adWordsServiceDescriptor);  }