NullPointerException when trying to create a new CRMbased user list

98 views
Skip to first unread message

ci.wbd...@gmail.com

unread,
Apr 30, 2019, 9:17:44 AM4/30/19
to AdWords API and Google Ads API Forum
Hi Team,

      I am facing issue when I am trying to mock googleads API calls for unit testing(using wiremock server which by using .withEndpoint option in AdwordsSession routes the Google ADS API call to localhost:8444 server) . I was able to narrow down the issue to mutate operation call in userlistOperation class. But I am unable to proceed further. I even checked the soap XML generated(below) with the SOAP XML that succeeded and I dont see any issues. Kindly help me in debugging the issue. Also please let me know if there is a mock capability available for UserList creation and updating users in them via Google API interface.

PFB the failure log messages:
<----wiremock intercept of post message sent to localhost------>
POST /api/adwords/rm/v201809/AdwordsUserListService HTTP/1.0
Content-Type: text/xml; charset=utf-8
Accept: application/soap+xml, application/dime, multipart/related, text/*
User-Agent: Axis/1.4
Host: localhost:8444
Cache-Control: no-cache
Pragma: no-cache
SOAPAction: ""
Content-Length: 1555
Authorization: Bearer null

<---corresponding SOAP XML created---->
<?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Header><ns1:RequestHeader soapenv:mustUnderstand="0" xmlns:ns1="https://adwords.google.com/api/adwords/rm/v201809"><ns2:clientCustomerId xmlns:ns2="https://adwords.google.com/api/adwords/cm/v201809">123-456-7891</ns2:clientCustomerId><ns3:developerToken xmlns:ns3="https://adwords.google.com/api/adwords/cm/v201809">AWEDEEDDDDDTREWQSDFGYTR</ns3:developerToken><ns4:userAgent xmlns:ns4="https://adwords.google.com/api/adwords/cm/v201809">foo (AwApi-Java, AdWords-Axis/4.4.0, Common-Java/4.4.0, Axis/1.4, Java/1.8.0_201, maven)</ns4:userAgent><ns5:validateOnly xmlns:ns5="https://adwords.google.com/api/adwords/cm/v201809">false</ns5:validateOnly><ns6:partialFailure xmlns:ns6="https://adwords.google.com/api/adwords/cm/v201809">false</ns6:partialFailure></ns1:RequestHeader></soapenv:Header><soapenv:Body><mutate xmlns="https://adwords.google.com/api/adwords/rm/v201809"><operations><ns7:operator xmlns:ns7="https://adwords.google.com/api/adwords/cm/v201809">ADD</ns7:operator><operand xsi:type="ns8:CrmBasedUserList" xmlns:ns8="https://adwords.google.com/api/adwords/rm/v201809"><ns8:name>newlist_Email</ns8:name><ns8:description>new_email_list</ns8:description><ns8:membershipLifeSpan>10000</ns8:membershipLifeSpan><ns8:uploadKeyType>CONTACT_INFO</ns8:uploadKeyType></operand></operations></mutate></soapenv:Body></soapenv:Envelope>

<---Error---->
19/04/30 18:35:33 ERROR SOAPPart: Exception:
java.lang.NullPointerException
java.lang.NullPointerException
        at java.io.FilterInputStream.read(Unknown Source)
        at org.apache.axis.SOAPPart.getAsBytes(SOAPPart.java:453)
        at org.apache.axis.SOAPPart.getAsString(SOAPPart.java:559)
        at org.apache.axis.SOAPPart.writeTo(SOAPPart.java:322)
        at org.apache.axis.SOAPPart.writeTo(SOAPPart.java:269)
        at org.apache.axis.Message.writeTo(Message.java:539)
        at com.google.api.ads.common.lib.soap.ResponseInfoXPathSet.parseMessage(ResponseInfoXPathSet.java:76)
        at com.google.api.ads.common.lib.soap.axis.AxisHandler.invokeSoapCall(AxisHandler.java:249)
- should throw exceptions when Google generation of Custom Audience ID Fails *** FAILED ***
  java.lang.NullPointerException:
  at org.apache.axis.SOAPPart.writeTo(SOAPPart.java:324)
  at org.apache.axis.SOAPPart.writeTo(SOAPPart.java:269)
  at org.apache.axis.Message.writeTo(Message.java:539)
  at com.google.api.ads.common.lib.soap.ResponseInfoXPathSet.parseMessage(ResponseInfoXPathSet.java:76)
  at com.google.api.ads.common.lib.soap.axis.AxisHandler.invokeSoapCall(AxisHandler.java:249)
  at com.google.api.ads.common.lib.soap.SoapServiceClient.callSoapClient(SoapServiceClient.java:63)
  at com.google.api.ads.common.lib.soap.SoapServiceClient.invoke(SoapServiceClient.java:93)
  at com.sun.proxy.$Proxy37.mutate(Unknown Source)
  at com.google.api.ads.common.lib.soap.SoapServiceClient.callSoapClient(SoapServiceClient.java:63)
  at com.google.api.ads.common.lib.soap.SoapServiceClient.invoke(SoapServiceClient.java:93)
  at com.sun.proxy.$Proxy37.mutate(Unknown Source)

googleadsapi...@google.com

unread,
Apr 30, 2019, 4:14:27 PM4/30/19
to AdWords API and Google Ads API Forum
Hello Warner,

Your SOAP request seems to be good. It is not possible to mock the UserList creation and updating users. Could you please share the complete logs and the scenario you are trying to achieve to investigate further?

Regards,
Sai Teja, Google Ads API Team


=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and discussion group:
    https://ads-developers.googleblog.com/search/label/google_ads_api
    https://developers.google.com/adwords/api/community/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

Was your question answered? Please rate your experience with us by taking a short survey.
If not -- reply to this email and tell us what else we can do to help.

Take Survey

Also find us on our blog and discussion group:
http://googleadsdeveloper.blogspot.com/search/label/adwords_api
https://developers.google.com/adwords/api/community/

ci.wbd...@gmail.com

unread,
May 2, 2019, 2:44:45 AM5/2/19
to AdWords API and Google Ads API Forum
Hi Sai Teja,

       PFB the code I am using for mocking the userlist creation:

//Calling Program with endpoint set to localhost so that google ads API will not be called for testing
val session = new AdWordsSession.Builder()
.withClientCustomerId("123-456-7891")
.withDeveloperToken("AWEDEEDDDDDTREWQSDFGYTR")
.withEndpoint("https://localhost:8444")
.withUserAgent("foo")
.withOAuth2Credential(credential).build()
GoogleUtils.createNewAudienceList("newlist", "new_email_list", session)

//Creates audience List
def createNewAudienceList(audienceListName: String, audienceListDescription: String,session:AdWordsSession ): Unit = {

val userListService: AdwordsUserListServiceInterface = adWordsServices.get(session, classOf[AdwordsUserListServiceInterface])
//Create a new UserList
val userList = new CrmBasedUserList()
userList.setDescription(audienceListDescription)

if (audienceListDescription.toUpperCase().contains("EMAIL")) {
val uploadKeyType = CustomerMatchUploadKeyType.CONTACT_INFO
userList.setUploadKeyType(uploadKeyType)
userList.setName(audienceListName+"_Email")
userList.setMembershipLifeSpan(10000L)
}
else {
val uploadKeyType = CustomerMatchUploadKeyType.MOBILE_ADVERTISING_ID
userList.setUploadKeyType(uploadKeyType)
userList.setName(audienceListName+"_Maid")
userList.setAppId(appId)
userList.setMembershipLifeSpan(540L)
}

//Upload the newly created userlist in GoogleAds page using mutate operation
val operation = new UserListOperation()
operation.setOperand(userList)
operation.setOperator(Operator.ADD)
val result = userListService.mutate(Array(operation))
}

//Wiremock Server to intercept localhost calls
System.setProperty("javax.net.ssl.trustStore", System.getProperty("trustStore"))
private val wireMockServer = new WireMockServer(wireMockConfig().port(8080).httpsPort(8444).keystorePath(System.getProperty("trustStore")))
WireMock.configureFor("localhost", 8080)
wireMockServer.start()


Whole Log:

19/04/30 18:35:33 INFO Log4jNotifier: Request received:
POST /api/adwords/rm/v201809/AdwordsUserListService HTTP/1.0
Content-Type: text/xml; charset=utf-8
Accept: application/soap+xml, application/dime, multipart/related, text/*
User-Agent: Axis/1.4
Host: localhost:8444
Cache-Control: no-cache
Pragma: no-cache
SOAPAction: ""
Content-Length: 1555
Authorization: Bearer null

<?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Header><ns1:RequestHeader soapenv:mustUnderstand="0" xmlns:ns1="https://adwords.google.com/api/adwords/rm/v201809"><ns2:clientCustomerId xmlns:ns2="https://adwords.google.com/api/adwords/cm/v201809">123-456-7891</ns2:clientCustomerId><ns3:developerToken xmlns:ns3="https://adwords.google.com/api/adwords/cm/v201809">AWEDEEDDDDDTREWQSDFGYTR</ns3:developerToken><ns4:userAgent xmlns:ns4="https://adwords.google.com/api/adwords/cm/v201809">foo (AwApi-Java, AdWords-Axis/4.4.0, Common-Java/4.4.0, Axis/1.4, Java/1.8.0_201, maven)</ns4:userAgent><ns5:validateOnly xmlns:ns5="https://adwords.google.com/api/adwords/cm/v201809">false</ns5:validateOnly><ns6:partialFailure xmlns:ns6="https://adwords.google.com/api/adwords/cm/v201809">false</ns6:partialFailure></ns1:RequestHeader></soapenv:Header><soapenv:Body><mutate xmlns="https://adwords.google.com/api/adwords/rm/v201809"><operations><ns7:operator xmlns:ns7="https://adwords.google.com/api/adwords/cm/v201809">ADD</ns7:operator><operand xsi:type="ns8:CrmBasedUserList" xmlns:ns8="https://adwords.google.com/api/adwords/rm/v201809"><ns8:name>newlist_Email</ns8:name><ns8:description>new_email_list</ns8:description><ns8:membershipLifeSpan>10000</ns8:membershipLifeSpan><ns8:uploadKeyType>CONTACT_INFO</ns8:uploadKeyType></operand></operations></mutate></soapenv:Body></soapenv:Envelope>
19/04/30 18:35:33 ERROR SOAPPart: Exception:
java.lang.NullPointerException
java.lang.NullPointerException
        at java.io.FilterInputStream.read(Unknown Source)
        at org.apache.axis.SOAPPart.getAsBytes(SOAPPart.java:453)
        at org.apache.axis.SOAPPart.getAsString(SOAPPart.java:559)
        at org.apache.axis.SOAPPart.writeTo(SOAPPart.java:322)
        at org.apache.axis.SOAPPart.writeTo(SOAPPart.java:269)
        at org.apache.axis.Message.writeTo(Message.java:539)
        at com.google.api.ads.common.lib.soap.ResponseInfoXPathSet.parseMessage(ResponseInfoXPathSet.java:76)
        at com.google.api.ads.common.lib.soap.axis.AxisHandler.invokeSoapCall(AxisHandler.java:249)
- should throw exceptions when Google generation of Custom Audience ID Fails *** FAILED ***
  java.lang.NullPointerException:
  at org.apache.axis.SOAPPart.writeTo(SOAPPart.java:324)
  at org.apache.axis.SOAPPart.writeTo(SOAPPart.java:269)
  at org.apache.axis.Message.writeTo(Message.java:539)
  at com.google.api.ads.common.lib.soap.ResponseInfoXPathSet.parseMessage(ResponseInfoXPathSet.java:76)
  at com.google.api.ads.common.lib.soap.axis.AxisHandler.invokeSoapCall(AxisHandler.java:249)
  at com.google.api.ads.common.lib.soap.SoapServiceClient.callSoapClient(SoapServiceClient.java:63)
  at com.google.api.ads.common.lib.soap.SoapServiceClient.invoke(SoapServiceClient.java:93)
  at com.sun.proxy.$Proxy37.mutate(Unknown Source)
        at com.google.api.ads.common.lib.soap.SoapServiceClient.callSoapClient(SoapServiceClient.java:63)
        at com.google.api.ads.common.lib.soap.SoapServiceClient.invoke(SoapServiceClient.java:93)
        at com.sun.proxy.$Proxy37.mutate(Unknown Source)
        at org.scalatest.OutcomeOf$class.outcomeOf(OutcomeOf.scala:85)
        at org.scalatest.OutcomeOf$.outcomeOf(OutcomeOf.scala:104)
        at org.scalatest.Transformer.apply(Transformer.scala:22)
        at org.scalatest.Transformer.apply(Transformer.scala:20)
        at org.scalatest.FlatSpecLike$$anon$1.apply(FlatSpecLike.scala:1682)
        at org.scalatest.TestSuite$class.withFixture(TestSuite.scala:196)
        at org.scalatest.FlatSpec.withFixture(FlatSpec.scala:1685)
        at org.scalatest.FlatSpecLike$class.invokeWithFixture$1(FlatSpecLike.scala:1679)
        at org.scalatest.FlatSpecLike$$anonfun$runTest$1.apply(FlatSpecLike.scala:1692)
        at org.scalatest.FlatSpecLike$$anonfun$runTest$1.apply(FlatSpecLike.scala:1692)
        at org.scalatest.SuperEngine.runTestImpl(Engine.scala:289)
        at org.scalatest.FlatSpecLike$class.runTest(FlatSpecLike.scala:1692)
        at arrow.SyndicateToGoogleTest.org$scalatest$BeforeAndAfter$$super$runTest(SyndicateToGoogleTest.scala:19)
        at org.scalatest.BeforeAndAfter$class.runTest(BeforeAndAfter.scala:203)
        at arrow.SyndicateToGoogleTest.runTest(SyndicateToGoogleTest.scala:19)
        at org.scalatest.FlatSpecLike$$anonfun$runTests$1.apply(FlatSpecLike.scala:1750)
        at org.scalatest.FlatSpecLike$$anonfun$runTests$1.apply(FlatSpecLike.scala:1750)
        at org.scalatest.SuperEngine$$anonfun$traverseSubNodes$1$1.apply(Engine.scala:396)
        at org.scalatest.SuperEngine$$anonfun$traverseSubNodes$1$1.apply(Engine.scala:384)
        at scala.collection.immutable.List.foreach(List.scala:381)
        at org.scalatest.SuperEngine.traverseSubNodes$1(Engine.scala:384)
        at org.scalatest.SuperEngine.org$scalatest$SuperEngine$$runTestsInBranch(Engine.scala:373)
        at org.scalatest.SuperEngine$$anonfun$traverseSubNodes$1$1.apply(Engine.scala:410)
        at org.scalatest.SuperEngine$$anonfun$traverseSubNodes$1$1.apply(Engine.scala:384)
        at scala.collection.immutable.List.foreach(List.scala:381)
        at org.scalatest.SuperEngine.traverseSubNodes$1(Engine.scala:384)
        at org.scalatest.SuperEngine.org$scalatest$SuperEngine$$runTestsInBranch(Engine.scala:379)
        at org.scalatest.SuperEngine.runTestsImpl(Engine.scala:461)
        at org.scalatest.FlatSpecLike$class.runTests(FlatSpecLike.scala:1750)
        at org.scalatest.FlatSpec.runTests(FlatSpec.scala:1685)
        at org.scalatest.Suite$class.run(Suite.scala:1147)
        at org.scalatest.FlatSpec.org$scalatest$FlatSpecLike$$super$run(FlatSpec.scala:1685)
        at org.scalatest.FlatSpecLike$$anonfun$run$1.apply(FlatSpecLike.scala:1795)
        at org.scalatest.FlatSpecLike$$anonfun$run$1.apply(FlatSpecLike.scala:1795)
        at org.scalatest.SuperEngine.runImpl(Engine.scala:521)
        at org.scalatest.FlatSpecLike$class.run(FlatSpecLike.scala:1795)
        at arrow.SyndicateToGoogleTest.org$scalatest$BeforeAndAfter$$super$run(SyndicateToGoogleTest.scala:19)
        at org.scalatest.BeforeAndAfter$class.run(BeforeAndAfter.scala:258)
        at arrow.SyndicateToGoogleTest.run(SyndicateToGoogleTest.scala:19)
        at org.scalatest.Suite$class.callExecuteOnSuite$1(Suite.scala:1210)
        at org.scalatest.Suite$$anonfun$runNestedSuites$1.apply(Suite.scala:1257)
        at org.scalatest.Suite$$anonfun$runNestedSuites$1.apply(Suite.scala:1255)
        at scala.collection.IndexedSeqOptimized$class.foreach(IndexedSeqOptimized.scala:33)
        at scala.collection.mutable.ArrayOps$ofRef.foreach(ArrayOps.scala:186)
        at org.scalatest.Suite$class.runNestedSuites(Suite.scala:1255)
        at org.scalatest.tools.DiscoverySuite.runNestedSuites(DiscoverySuite.scala:30)
        at org.scalatest.Suite$class.run(Suite.scala:1144)
        at org.scalatest.tools.DiscoverySuite.run(DiscoverySuite.scala:30)
        at org.scalatest.tools.SuiteRunner.run(SuiteRunner.scala:45)
        at org.scalatest.tools.Runner$$anonfun$doRunRunRunDaDoRunRun$1.apply(Runner.scala:1346)
        at org.scalatest.tools.Runner$$anonfun$doRunRunRunDaDoRunRun$1.apply(Runner.scala:1340)
        at scala.collection.immutable.List.foreach(List.scala:381)
        at org.scalatest.tools.Runner$.doRunRunRunDaDoRunRun(Runner.scala:1340)
        at org.scalatest.tools.Runner$$anonfun$runOptionallyWithPassFailReporter$2.apply(Runner.scala:1011)
        at org.scalatest.tools.Runner$$anonfun$runOptionallyWithPassFailReporter$2.apply(Runner.scala:1010)

Thanks

googleadsapi...@google.com

unread,
May 2, 2019, 11:10:16 AM5/2/19
to AdWords API and Google Ads API Forum
Hello Warner,

In your code snippet when making mutate call "val result = userListService.mutate(Array(operation))", the mutation will be performed at the Google Ads servers and the result will be fetched and stored in the result variable. Since, you are changing the end point the mutation call is not happening and assigning null to the result variable. This is throwing the NullPointerException at your end. Instead changing the end point, you could make use of our Test accounts for your testing purpose. The test accounts are designed for this purpose only and the Ads in your test account will never serve and no billing information is needed. Otherwise mocking the user lists in your local server is not possible. 


Regards,
Sai Teja, Google Ads API Team


=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and discussion group:
    https://ads-developers.googleblog.com/search/label/google_ads_api
    https://developers.google.com/adwords/api/community/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Reply all
Reply to author
Forward
0 new messages