SocketException: Connection reset for AdUnits

292 views
Skip to first unread message

Padmahas Bn

unread,
May 26, 2017, 9:17:58 AM5/26/17
to Google's DoubleClick for Publishers API Forum
Hello,
In the example API code that I have downloaded, when I ran getAllAdUnits API, gave "socketException: Connection reset" only for 3 days. And now its showing the same error for my colleague. I found this issue in local for "AdUnits" service.
What makes this "Connection reset" exception to occur. The detailed log is given below.

[26 May 2017 15:25:37,480-requestInfoLogger:INFO:main] Request made: Service: "InventoryServiceInterfacePort" Method: "getAdUnitsByStatement" URL: "https://ads.google.com/apis/ads/publisher/v201702/InventoryService" Request ID: "null"
[26 May 2017 15:25:37,549-soapXmlLogger:WARN:main] SOAP Request:
<?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 xmlns:ns1="https://www.google.com/apis/ads/publisher/v201702" soapenv:mustUnderstand="0">
           
<ns1:networkCode>5910</ns1:networkCode>
            <ns1:applicationName>caapp (DfpApi-Java, Dfp-Axis/
3.0.0, Common-Java/3.0.0, Axis/1.4, Java/1.8.0_131, maven)</ns1:applicationName>
       
</ns1:RequestHeader>
    </
soapenv:Header>
   
<soapenv:Body>
       
<getAdUnitsByStatement xmlns="https://www.google.com/apis/ads/publisher/v201702">
           
<filterStatement>
               
<query>WHERE Name = 'AlJamila' ORDER BY id ASC LIMIT 500</query>
            </
filterStatement>
       
</getAdUnitsByStatement>
    </
soapenv:Body>
</soapenv:Envelope>

[26 May 2017 15:25:37,549-soapXmlLogger:WARN:main] SOAP Response:
<?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:Body>
       
<soapenv:Fault>
           
<faultcode>soapenv:Server.userException</faultcode>
            <faultstring>java.net.ConnectException: Connection timed out: connect</
faultstring>
           
<detail>
               
<ns1:stackTrace xmlns:ns1="http://xml.apache.org/axis/">java.net.ConnectException: Connection timed out: connect
    at java
.net.DualStackPlainSocketImpl.connect0(Native Method)
    at java
.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
    at java
.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
    at java
.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
    at java
.net.AbstractPlainSocketImpl.connect(Unknown Source)
    at java
.net.PlainSocketImpl.connect(Unknown Source)
    at java
.net.SocksSocketImpl.connect(Unknown Source)
    at java
.net.Socket.connect(Unknown Source)
    at sun
.security.ssl.SSLSocketImpl.connect(Unknown Source)
    at sun
.security.ssl.SSLSocketImpl.&lt;init&gt;(Unknown Source)
    at sun
.security.ssl.SSLSocketFactoryImpl.createSocket(Unknown Source)
    at org
.apache.axis.components.net.JSSESocketFactory.create(JSSESocketFactory.java:92)
    at org
.apache.axis.transport.http.HTTPSender.getSocket(HTTPSender.java:191)
    at org
.apache.axis.transport.http.HTTPSender.writeToSocket(HTTPSender.java:404)
    at org
.apache.axis.transport.http.HTTPSender.invoke(HTTPSender.java:138)
    at org
.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:32)
    at org
.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118)
    at org
.apache.axis.SimpleChain.invoke(SimpleChain.java:83)
    at org
.apache.axis.client.AxisClient.invoke(AxisClient.java:165)
    at org
.apache.axis.client.Call.invokeEngine(Call.java:2784)
    at org
.apache.axis.client.Call.invoke(Call.java:2767)
    at org
.apache.axis.client.Call.invoke(Call.java:2443)
    at org
.apache.axis.client.Call.invoke(Call.java:2366)
    at org
.apache.axis.client.Call.invoke(Call.java:1812)
    at com
.google.api.ads.dfp.axis.v201702.InventoryServiceSoapBindingStub.getAdUnitsByStatement(InventoryServiceSoapBindingStub.java:1210)
    at sun
.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun
.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun
.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java
.lang.reflect.Method.invoke(Unknown Source)
    at com
.google.api.ads.common.lib.soap.SoapClientHandler.invoke(SoapClientHandler.java:109)
    at com
.google.api.ads.common.lib.soap.axis.AxisHandler.invokeSoapCall(AxisHandler.java:246)
    at com
.google.api.ads.common.lib.soap.SoapServiceClient.callSoapClient(SoapServiceClient.java:62)
    at com
.google.api.ads.common.lib.soap.SoapServiceClient.invoke(SoapServiceClient.java:92)
    at com
.sun.proxy.$Proxy19.getAdUnitsByStatement(Unknown Source)
    at dfp
.axis.v201702.inventoryservice.GetAdUnitsIDByName.runExample(GetAdUnitsIDByName.java:54)
    at dfp
.axis.v201702.inventoryservice.GetAdUnitsIDByName.main(GetAdUnitsIDByName.java:88)
</ns1:stackTrace>
                <ns2:hostname xmlns:ns2="http:/
/xml.apache.org/axis/">Theo-Lap0202</ns2:hostname>
            </detail>
        </soapenv:Fault>
    </soapenv:Body>
</soapenv:Envelope>

Exception in thread "
main" AxisFault
 faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.userException
 faultSubcode:
 faultString: java.net.ConnectException: Connection timed out: connect
 faultActor:
 faultNode:
 faultDetail:
    {http://xml.apache.org/axis/}stackTrace:java.net.ConnectException: Connection timed out: connect
    at java.net.DualStackPlainSocketImpl.connect0(Native Method)
    at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
    at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
    at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
    at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
    at java.net.PlainSocketImpl.connect(Unknown Source)
    at java.net.SocksSocketImpl.connect(Unknown Source)
    at java.net.Socket.connect(Unknown Source)
    at sun.security.ssl.SSLSocketImpl.connect(Unknown Source)
    at sun.security.ssl.SSLSocketImpl.&lt;init&gt;(Unknown Source)
    at sun.security.ssl.SSLSocketFactoryImpl.createSocket(Unknown Source)
    at org.apache.axis.components.net.JSSESocketFactory.create(JSSESocketFactory.java:92)
    at org.apache.axis.transport.http.HTTPSender.getSocket(HTTPSender.java:191)
    at org.apache.axis.transport.http.HTTPSender.writeToSocket(HTTPSender.java:404)
    at org.apache.axis.transport.http.HTTPSender.invoke(HTTPSender.java:138)
    at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:32)
    at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118)
    at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83)
    at org.apache.axis.client.AxisClient.invoke(AxisClient.java:165)
    at org.apache.axis.client.Call.invokeEngine(Call.java:2784)
    at org.apache.axis.client.Call.invoke(Call.java:2767)
    at org.apache.axis.client.Call.invoke(Call.java:2443)
    at org.apache.axis.client.Call.invoke(Call.java:2366)
    at org.apache.axis.client.Call.invoke(Call.java:1812)
    at com.google.api.ads.dfp.axis.v201702.InventoryServiceSoapBindingStub.getAdUnitsByStatement(InventoryServiceSoapBindingStub.java:1210)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at com.google.api.ads.common.lib.soap.SoapClientHandler.invoke(SoapClientHandler.java:109)
    at com.google.api.ads.common.lib.soap.axis.AxisHandler.invokeSoapCall(AxisHandler.java:246)
    at com.google.api.ads.common.lib.soap.SoapServiceClient.callSoapClient(SoapServiceClient.java:62)
    at com.google.api.ads.common.lib.soap.SoapServiceClient.invoke(SoapServiceClient.java:92)
    at com.sun.proxy.$Proxy19.getAdUnitsByStatement(Unknown Source)
    at dfp.axis.v201702.inventoryservice.GetAdUnitsIDByName.runExample(GetAdUnitsIDByName.java:54)
    at dfp.axis.v201702.inventoryservice.GetAdUnitsIDByName.main(GetAdUnitsIDByName.java:88)

    {http://xml.apache.org/axis/}hostname:Theo-Lap0202

java.net.ConnectException: Connection timed out: connect
    at org.apache.axis.AxisFault.makeFault(AxisFault.java:101)
    at org.apache.axis.transport.http.HTTPSender.invoke(HTTPSender.java:154)
    at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:32)
    at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118)
    at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83)
    at org.apache.axis.client.AxisClient.invoke(AxisClient.java:165)
    at org.apache.axis.client.Call.invokeEngine(Call.java:2784)
    at org.apache.axis.client.Call.invoke(Call.java:2767)
    at org.apache.axis.client.Call.invoke(Call.java:2443)
    at org.apache.axis.client.Call.invoke(Call.java:2366)
    at org.apache.axis.client.Call.invoke(Call.java:1812)
    at com.google.api.ads.dfp.axis.v201702.InventoryServiceSoapBindingStub.getAdUnitsByStatement(InventoryServiceSoapBindingStub.java:1210)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at com.google.api.ads.common.lib.soap.SoapClientHandler.invoke(SoapClientHandler.java:109)
    at com.google.api.ads.common.lib.soap.axis.AxisHandler.invokeSoapCall(AxisHandler.java:246)
    at com.google.api.ads.common.lib.soap.SoapServiceClient.callSoapClient(SoapServiceClient.java:62)
    at com.google.api.ads.common.lib.soap.SoapServiceClient.invoke(SoapServiceClient.java:92)
    at com.sun.proxy.$Proxy19.getAdUnitsByStatement(Unknown Source)
    at dfp.axis.v201702.inventoryservice.GetAdUnitsIDByName.runExample(GetAdUnitsIDByName.java:54)
    at dfp.axis.v201702.inventoryservice.GetAdUnitsIDByName.main(GetAdUnitsIDByName.java:88)
Caused by: java.net.ConnectException: Connection timed out: connect
    at java.net.DualStackPlainSocketImpl.connect0(Native Method)
    at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
    at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
    at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
    at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
    at java.net.PlainSocketImpl.connect(Unknown Source)
    at java.net.SocksSocketImpl.connect(Unknown Source)
    at java.net.Socket.connect(Unknown Source)
    at sun.security.ssl.SSLSocketImpl.connect(Unknown Source)
    at sun.security.ssl.SSLSocketImpl.<init>(Unknown Source)
    at sun.security.ssl.SSLSocketFactoryImpl.createSocket(Unknown Source)
    at org.apache.axis.components.net.JSSESocketFactory.create(JSSESocketFactory.java:92)
    at org.apache.axis.transport.http.HTTPSender.getSocket(HTTPSender.java:191)
    at org.apache.axis.transport.http.HTTPSender.writeToSocket(HTTPSender.java:404)
    at org.apache.axis.transport.http.HTTPSender.invoke(HTTPSender.java:138)
    ... 21 more


And the same error occurs for all kind of services (like getAllTrafficker, getAgency etc) on the apache server where we have deployed our application.
As I know there are no issues in our network.
Thank you.

Sreelakshmi Sasidharan (DFP API Team)

unread,
May 26, 2017, 2:53:15 PM5/26/17
to Google's DoubleClick for Publishers API Forum
Hi Padmahas, 

Sometimes if the server is too busy or due to network latency the API requests might timeout. I tried the same request against your network (5910) and it came back with results. I would strongly suggest that you go through this blog which talks about implementing a retry logic for situations like this. In addition to that, you could also try to increase the soapRequestTimeout in your ads.properties file.  

Please give this a try and let me know how it goes.

Thanks,
Sreelakshmi Sasidharan, DFP API Team

Padmahas Bn

unread,
May 27, 2017, 5:48:34 AM5/27/17
to Google's DoubleClick for Publishers API Forum
Hello Sri Lakshmi,

I'll check by implementing retry logic. But need couple of clarifications.
1. Did I just gave out sensitive info by mentioning network code?
2. When socket exception occurs for one service, say eg: getAllAdUnits, it wont occur for other services like getAllKeysAndValues.etc. This scenario is with respect to local machine. How the same network could reject request for only certain service?
    But in case of server where we have deployed our application, if any service starts giving error all services will be down.

Thank you.

Sreelakshmi Sasidharan (DFP API Team)

unread,
May 30, 2017, 10:56:06 AM5/30/17
to Google's DoubleClick for Publishers API Forum
Hi Padmahas, 

Sure, please give it a try and let me know how it goes.
  1. Network code is not treated as sensitive information. Please check the Tips on posting questions for the guidelines while posting on DFP API Forum. 
  2. To clarify, by 'network' in my previous response I did not mean your DFP API network. I meant the network/internet over which the API requests are being issued. Eg., getAllAdUnits method call might fail because it was not possible to return all the AdUnits in the given time causing the request to timeout. Either because there were too many AdUnits or because there were some issues with the internet at that point of time. If that is the case other services should not have any issues. Please note that this is just a possibility.

Padmahas Bn

unread,
Jun 9, 2017, 11:47:35 AM6/9/17
to Google's DoubleClick for Publishers API Forum
Hello SriLakshmi,

 From the blog of retrying logic you suggested me, I found its previous blog where we can catch and find exactly which field we have missed or which field we are giving wrong value.
That post suggests using ApiException class which is still valid in v201702 version of the API.
And I implemented that exception and tested by giving wrong values. But that ApiException is never caught.
Also apiError.getApiErrorType(); is deprecated.

Can you please tell me whether I have to catch some other exception and an alternative function to get Error type?

Thank you.

Sreelakshmi Sasidharan (DFP API Team)

unread,
Jun 9, 2017, 4:09:34 PM6/9/17
to Google's DoubleClick for Publishers API Forum
Hi Padmahas, 

Would you be able to confirm what exception your code is throwing? Is it ApiException? If yes, could you please share with me your SOAP request log that you are using for testing? If the exception type is different, my suggestion is to follow the general java exception handling conventions and catch the specific exception. Also, please note that based on the type of failure the exception might be different. The code snippet in the blog might be obsolete now and I think the current API version does not throw ApiException anymore. 

Padmahas Bn

unread,
Jun 12, 2017, 1:30:07 AM6/12/17
to Google's DoubleClick for Publishers API Forum
Hello SreeLakshmi,

I'm giving wron postal code ID.
Location postalCodeLocation = new Location();
//    postalCodeLocation.setId(9000093L);
    postalCodeLocation
.setId(9L);

There are two types of error I get. One is when I remove "Exception" catch block, another is when I keep "Exception" catch block.
The below SOAP response and Exception is thrown when I remove "Exception" catch block.

[12 Jun 2017 10:48:27,201-requestInfoLogger:INFO:main] Request made: Service: "NetworkServiceInterfacePort" Method: "getCurrentNetwork" URL: "https://ads.google.com/apis/ads/publisher/v201702/NetworkService" Request ID: "40db73963f4e947d54df9882a6d853b7"
[12 Jun 2017 10:48:28,336-requestInfoLogger:INFO:main] Request made: Service: "LineItemServiceInterfacePort" Method: "createLineItems" URL: "https://ads.google.com/apis/ads/publisher/v201702/LineItemService" Request ID: "null"
[Fatal Error] :1:1: Content is not allowed in prolog.
ERROR:  'Content is not allowed in prolog.'
[12 Jun 2017 10:48:28,472-soapXmlLogger:WARN:main] SOAP Request:

<?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 xmlns:ns1="https://www.google.com/apis/ads/publisher/v201702" soapenv:mustUnderstand="0">
            <ns1:networkCode>5910</ns1:networkCode>
            <ns1:applicationName>caapp2 (DfpApi-Java, Dfp-Axis/3.0.0, Common-Java/3.0.0, Axis/1.4, Java/1.8.0_102, maven)</ns1:applicationName>

        </ns1:RequestHeader>
    </soapenv:Header>
    <soapenv:Body>
        <createLineItems xmlns="https://www.google.com/apis/ads/publisher/v201702">
            <lineItems>
                <orderId>547945036</orderId>
                <name>APIException1268643242</name>
                <startDateTimeType>IMMEDIATELY</startDateTimeType>
                <endDateTime>
                    <date>
                        <year>2017</year>
                        <month>7</month>
                        <day>12</day>
                    </date>
                    <hour>9</hour>
                    <minute>18</minute>
                    <second>27</second>
                    <timeZoneID>Asia/Dubai</timeZoneID>
                </endDateTime>
                <creativeRotationType>EVEN</creativeRotationType>
                <lineItemType>ADSENSE</lineItemType>
                <priority>4</priority>
                <costPerUnit>
                    <currencyCode>USD</currencyCode>
                    <microAmount>20000</microAmount>
                </costPerUnit>
                <costType>CPM</costType>
                <creativePlaceholders>
                    <size>
                        <width>300</width>
                        <height>250</height>
                        <isAspectRatio>false</isAspectRatio>
                    </size>
                </creativePlaceholders>
                <allowOverbook>true</allowOverbook>
                <webPropertyCode>ca-pub-415070496312123</webPropertyCode>
                <primaryGoal>
                    <goalType>DAILY</goalType>
                    <unitType>IMPRESSIONS</unitType>
                    <units>58</units>
                </primaryGoal>
                <targeting>
                    <geoTargeting>
                        <targetedLocations>
                            <id>2356</id>
                        </targetedLocations>
                        <targetedLocations>
                            <id>20461</id>
                        </targetedLocations>
                        <targetedLocations>
                            <id>9</id>
                        </targetedLocations>
                        <excludedLocations>
                            <id>1016367</id>
                        </excludedLocations>
                        <excludedLocations>
                            <id>200501</id>
                        </excludedLocations>
                    </geoTargeting>
                    <inventoryTargeting>
                        <targetedAdUnits>
                            <adUnitId>5889796</adUnitId>
                            <includeDescendants>true</includeDescendants>
                        </targetedAdUnits>
                    </inventoryTargeting>
                </targeting>
            </lineItems>
        </createLineItems>
    </soapenv:Body>
</soapenv:Envelope>

[12 Jun 2017 10:48:28,488-soapXmlLogger:WARN:main] SOAP Response:
eldPathElements><field>targeting</field></fieldPathElements><fieldPathElements><field>geoTargeting</field></fieldPathElements><fieldPathElements><field>targetedLocations</field></fieldPathElements><fieldPathElements><field>id</field></fieldPathElements><trigger>9</trigger><errorString>CommonError.NOT_FOUND</errorString><reason>NOT_FOUND</reason></errors></ApiExceptionFault></detail></soap:Fault></soap:Body></soap:Envelope>

Exception in thread "main" AxisFault
 faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.userException
 faultSubcode:
 faultString: org.xml.sax.SAXException: Invalid element in com.google.api.ads.dfp.axis.v201702.CommonError - fieldPathElements
 faultActor:
 faultNode:
 faultDetail:
    {http://xml.apache.org/axis/}stackTrace:org.xml.sax.SAXException: Invalid element in com.google.api.ads.dfp.axis.v201702.CommonError - fieldPathElements
    at org.apache.axis.encoding.ser.BeanDeserializer.onStartChild(BeanDeserializer.java:258)
    at org.apache.axis.encoding.DeserializationContext.startElement(DeserializationContext.java:1035)
    at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:509)
    at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:374)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2784)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:602)
    at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:112)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:505)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:841)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:770)
    at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
    at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1213)
    at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:643)
    at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl.parse(SAXParserImpl.java:327)
    at org.apache.axis.encoding.DeserializationContext.parse(DeserializationContext.java:227)
    at org.apache.axis.SOAPPart.getAsSOAPEnvelope(SOAPPart.java:696)
    at org.apache.axis.Message.getSOAPEnvelope(Message.java:435)
    at org.apache.axis.handlers.soap.MustUnderstandChecker.invoke(MustUnderstandChecker.java:62)
    at org.apache.axis.client.AxisClient.invoke(AxisClient.java:206)

    at org.apache.axis.client.Call.invokeEngine(Call.java:2784)
    at org.apache.axis.client.Call.invoke(Call.java:2767)
    at org.apache.axis.client.Call.invoke(Call.java:2443)
    at org.apache.axis.client.Call.invoke(Call.java:2366)
    at org.apache.axis.client.Call.invoke(Call.java:1812)
    at com.google.api.ads.dfp.axis.v201702.LineItemServiceSoapBindingStub.createLineItems(LineItemServiceSoapBindingStub.java:1964)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)

    at com.google.api.ads.common.lib.soap.SoapClientHandler.invoke(SoapClientHandler.java:109)
    at com.google.api.ads.common.lib.soap.axis.AxisHandler.invokeSoapCall(AxisHandler.java:246)
    at com.google.api.ads.common.lib.soap.SoapServiceClient.callSoapClient(SoapServiceClient.java:62)
    at com.google.api.ads.common.lib.soap.SoapServiceClient.invoke(SoapServiceClient.java:92)
    at com.sun.proxy.$Proxy19.createLineItems(Unknown Source)
    at dfp.axis.v201702.lineitemservice.CreateLineItemsExceptionHandling.runExample(CreateLineItemsExceptionHandling.java:223)
    at dfp.axis.v201702.lineitemservice.CreateLineItemsExceptionHandling.main(CreateLineItemsExceptionHandling.java:267)

    {http://xml.apache.org/axis/}hostname:Theo-tech1422

org.xml.sax.SAXException: Invalid element in com.google.api.ads.dfp.axis.v201702.CommonError - fieldPathElements
    at org.apache.axis.AxisFault.makeFault(AxisFault.java:101)
    at org.apache.axis.SOAPPart.getAsSOAPEnvelope(SOAPPart.java:701)
    at org.apache.axis.Message.getSOAPEnvelope(Message.java:435)
    at org.apache.axis.handlers.soap.MustUnderstandChecker.invoke(MustUnderstandChecker.java:62)
    at org.apache.axis.client.AxisClient.invoke(AxisClient.java:206)

    at org.apache.axis.client.Call.invokeEngine(Call.java:2784)
    at org.apache.axis.client.Call.invoke(Call.java:2767)
    at org.apache.axis.client.Call.invoke(Call.java:2443)
    at org.apache.axis.client.Call.invoke(Call.java:2366)
    at org.apache.axis.client.Call.invoke(Call.java:1812)
    at com.google.api.ads.dfp.axis.v201702.LineItemServiceSoapBindingStub.createLineItems(LineItemServiceSoapBindingStub.java:1964)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)

    at com.google.api.ads.common.lib.soap.SoapClientHandler.invoke(SoapClientHandler.java:109)
    at com.google.api.ads.common.lib.soap.axis.AxisHandler.invokeSoapCall(AxisHandler.java:246)
    at com.google.api.ads.common.lib.soap.SoapServiceClient.callSoapClient(SoapServiceClient.java:62)
    at com.google.api.ads.common.lib.soap.SoapServiceClient.invoke(SoapServiceClient.java:92)
    at com.sun.proxy.$Proxy19.createLineItems(Unknown Source)
    at dfp.axis.v201702.lineitemservice.CreateLineItemsExceptionHandling.runExample(CreateLineItemsExceptionHandling.java:223)
    at dfp.axis.v201702.lineitemservice.CreateLineItemsExceptionHandling.main(CreateLineItemsExceptionHandling.java:267)
Caused by: org.xml.sax.SAXException: Invalid element in com.google.api.ads.dfp.axis.v201702.CommonError - fieldPathElements
    at org.apache.axis.encoding.ser.BeanDeserializer.onStartChild(BeanDeserializer.java:258)
    at org.apache.axis.encoding.DeserializationContext.startElement(DeserializationContext.java:1035)
    at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:509)
    at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:374)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2784)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:602)
    at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:112)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:505)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:841)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:770)
    at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
    at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1213)
    at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:643)
    at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl.parse(SAXParserImpl.java:327)
    at org.apache.axis.encoding.DeserializationContext.parse(DeserializationContext.java:227)
    at org.apache.axis.SOAPPart.getAsSOAPEnvelope(SOAPPart.java:696)
    ... 20 more


This is thrown when I keep "Exception" catch block. This time its NullPointerException.

[12 Jun 2017 10:53:39,706-requestInfoLogger:INFO:main] Request made: Service: "NetworkServiceInterfacePort" Method: "getCurrentNetwork" URL: "https://ads.google.com/apis/ads/publisher/v201702/NetworkService" Request ID: "6baf76f100f33355c77f2defc6b64044"
[12 Jun 2017 10:53:41,543-requestInfoLogger:INFO:main] Request made: Service: "LineItemServiceInterfacePort" Method: "createLineItems" URL: "https://ads.google.com/apis/ads/publisher/v201702/LineItemService" Request ID: "null"
[Fatal Error] :1:1: Content is not allowed in prolog.
ERROR:  'Content is not allowed in prolog.'
[12 Jun 2017 10:53:41,584-soapXmlLogger:WARN:main] SOAP Request:

<?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 xmlns:ns1="https://www.google.com/apis/ads/publisher/v201702" soapenv:mustUnderstand="0">
            <ns1:networkCode>5910</ns1:networkCode>
            <ns1:applicationName>caapp2 (DfpApi-Java, Dfp-Axis/3.0.0, Common-Java/3.0.0, Axis/1.4, Java/1.8.0_102, maven)</ns1:applicationName>

        </ns1:RequestHeader>
    </soapenv:Header>
    <soapenv:Body>
        <createLineItems xmlns="https://www.google.com/apis/ads/publisher/v201702">
            <lineItems>
                <orderId>547945036</orderId>
                <name>APIException1512890192</name>
                <startDateTimeType>IMMEDIATELY</startDateTimeType>
                <endDateTime>
                    <date>
                        <year>2017</year>
                        <month>7</month>
                        <day>12</day>
                    </date>
                    <hour>9</hour>
                    <minute>23</minute>
                    <second>39</second>
                    <timeZoneID>Asia/Dubai</timeZoneID>
                </endDateTime>
                <creativeRotationType>EVEN</creativeRotationType>
                <lineItemType>ADSENSE</lineItemType>
                <priority>4</priority>
                <costPerUnit>
                    <currencyCode>USD</currencyCode>
                    <microAmount>20000</microAmount>
                </costPerUnit>
                <costType>CPM</costType>
                <creativePlaceholders>
                    <size>
                        <width>300</width>
                        <height>250</height>
                        <isAspectRatio>false</isAspectRatio>
                    </size>
                </creativePlaceholders>
                <allowOverbook>true</allowOverbook>
                <webPropertyCode>ca-pub-415070496312123</webPropertyCode>
                <primaryGoal>
                    <goalType>DAILY</goalType>
                    <unitType>IMPRESSIONS</unitType>
                    <units>58</units>
                </primaryGoal>
                <targeting>
                    <geoTargeting>
                        <targetedLocations>
                            <id>2356</id>
                        </targetedLocations>
                        <targetedLocations>
                            <id>20461</id>
                        </targetedLocations>
                        <targetedLocations>
                            <id>9</id>
                        </targetedLocations>
                        <excludedLocations>
                            <id>1016367</id>
                        </excludedLocations>
                        <excludedLocations>
                            <id>200501</id>
                        </excludedLocations>
                    </geoTargeting>
                    <inventoryTargeting>
                        <targetedAdUnits>
                            <adUnitId>5889796</adUnitId>
                            <includeDescendants>true</includeDescendants>
                        </targetedAdUnits>
                    </inventoryTargeting>
                </targeting>
            </lineItems>
        </createLineItems>
    </soapenv:Body>
</soapenv:Envelope>

[12 Jun 2017 10:53:41,585-soapXmlLogger:WARN:main] SOAP Response:
eldPathElements><field>targeting</field></fieldPathElements><fieldPathElements><field>geoTargeting</field></fieldPathElements><fieldPathElements><field>targetedLocations</field></fieldPathElements><fieldPathElements><field>id</field></fieldPathElements><trigger>9</trigger><errorString>CommonError.NOT_FOUND</errorString><reason>NOT_FOUND</reason></errors></ApiExceptionFault></detail></soap:Fault></soap:Body></soap:Envelope>
Exception caught.
Exception in thread "main" java.lang.NullPointerException
    at dfp.axis.v201702.lineitemservice.CreateLineItemsExceptionHandling.runExample(CreateLineItemsExceptionHandling.java:246)
    at dfp.axis.v201702.lineitemservice.CreateLineItemsExceptionHandling.main(CreateLineItemsExceptionHandling.java:268)


Padmahas Bn

unread,
Jun 12, 2017, 1:53:19 AM6/12/17
to Google's DoubleClick for Publishers API Forum
To add to the previous post,
v201702 still contains ApiException class. May be I'm using it in wrong way. Below is the Exception handling code. Its same as given in the post.

try
    {
        // Create the line item on the server.
        lineItems = lineItemService.createLineItems(new LineItem[] {lineItem});
    }
    catch(ApiException e)
    {
        ApiError[] apiErrors = e.getErrors();
        for (ApiError apiError : apiErrors) {
          StringBuilder errorMessage = new StringBuilder();
          errorMessage.append(String.format(
              "There was an error of type '%s', on the field '%s',"
              + "caused by an invalid "
              + "value '%s', with the error message '%s'",
              apiError.getFieldPath(),
              apiError.getTrigger(), apiError.getErrorString()));
         
          System.err.println(errorMessage.toString());
        }
    }

When debugging, I fond variable "name" containing APIException.
I've copied all variables below.
 
arg0    LineItem[1]  (id=51)   
    [0]    LineItem  (id=55)   
        __equalsCalc    null   
        __equalsCalc    null   
        __hashCodeCalc    false   
        __hashCodeCalc    false   
        activityAssociations    null   
        adExchangeAuctionOpeningPriority    null   
        allowOverbook    Boolean  (id=57)   
        appliedLabels    null   
        autoExtensionDays    null   
        budget    null   
        companionDeliveryOption    null   
        contractedUnitsBought    null   
        costPerUnit    Money  (id=60)   
        costType    CostType  (id=62)   
        creationDateTime    null   
        creativePersistenceType    null   
        creativePlaceholders    CreativePlaceholder[1]  (id=64)   
        creativeRotationType    CreativeRotationType  (id=67)   
        creativeTargetings    null   
        customFieldValues    null   
        deliveryData    null   
        deliveryIndicator    null   
        deliveryRateType    null   
        disableSameAdvertiserCompetitiveExclusion    null   
        discount    null   
        discountType    null   
        effectiveAppliedLabels    null   
        endDateTime    DateTime  (id=69)   
        environmentType    null   
        externalId    null   
        frequencyCaps    null   
        grpSettings    null   
        id    null   
        isArchived    null   
        isMissingCreatives    null   
        isPrioritizedPreferredDealsEnabled    null   
        isSetTopBoxEnabled    null   
        lastModifiedByApp    null   
        lastModifiedDateTime    null   
        lineItemType    LineItemType  (id=71)   
        name    "APIException1156638590" (id=73)   
        notes    null   
        orderId    Long  (id=76)   
        orderName    null   
        primaryGoal    Goal  (id=79)   
        priority    Integer  (id=81)   
        reservationStatus    null   
        reserveAtCreation    null   
        roadblockingType    null   
        secondaryGoals    null   
        setTopBoxDisplayInfo    null   
        skipCrossSellingRuleWarningChecks    null   
        skipInventoryCheck    null   
        startDateTime    null   
        startDateTimeType    StartDateTimeType  (id=390)   
        stats    null   
        status    null   
        targeting    Targeting  (id=393)   
        unlimitedEndDateTime    null   
        valueCostPerUnit    null   
        videoMaxDuration    null   
        webPropertyCode    "ca-pub-415070496312123" (id=400)

Thank you.

Padmahas Bn

unread,
Jun 12, 2017, 10:02:25 AM6/12/17
to Google's DoubleClick for Publishers API Forum
Hi SreeLakshmi,

The connection reset error occurred on one of the server. And I had applied the retry logic to "getLabels" service. When I hit that API, it took certain amount of time (which includes 2 sec waiting time for 5 times and response time, totally around 30 to 40 seconds) and again the same error.

All it was able to do is, it delayed the final response. Anyway I'm also looking for other solutions to get detailed log from log4j, which is not giving most recent log. It always shows logs which is registered 15 min or 3 hours back.
Just wanted to notify you.

Thank you.

Sreelakshmi Sasidharan (DFP API Team)

unread,
Jun 12, 2017, 2:35:20 PM6/12/17
to Google's DoubleClick for Publishers API Forum
Hi Padmahas, 

Thanks for sharing the details and the log. Yes, the response seems to return the APIException and 
I was able to test the code snippet. I could see that the attribute "ApiErrorType" is not available anymore. However, the ApiError array has all the other attributes: errorString, fieldPath, fieldPathElements, reason, trigger.

The code was working after the mapping for ApiErrorType was removed. Please note that in case of an exception/error the response object from the API will be null. You will need to have a null check before iterating on the response object. In this case, there should be a null check for the array 'lineItems' before performing the for loop. I am suspecting that it is where your code is failing with nullPointerException. You could verify what is happening at the specific line in your code 'CreateLineItemsExceptionHandling.java:246' to make sure if that is where it is failing. 


Hope this helps.

Padmahas Bn

unread,
Jun 13, 2017, 4:26:05 AM6/13/17
to Google's DoubleClick for Publishers API Forum
Hi SreeLakshmi,

The exception is occurring as soon as I hit the DFP API at Line No 212. That is, I'm not even able to check whether the array is null or not.
However another observation, APIException is caught when the I gave wrong refresh token.

Thank you.

Sreelakshmi Sasidharan (DFP API Team)

unread,
Jun 13, 2017, 11:18:41 AM6/13/17
to Google's DoubleClick for Publishers API Forum
Hi Padmahas,

Ideally the Line No 212 should be within the try block in your code and if that throws an exception, the catch block should handle it. If you would like, the entire logic of handling the response too can be done with in the try block or you could have appropriate null checks in place. The blog that was shared earlier about handling the error is a sample that you can follow and how you want to implement that in your application would depend on your applications's requirements. 

On your second observation, for a request with invalid refresh token, I believe you should be getting an OAuth error (Invalid_grant error is one possibility).

Padmahas Bn

unread,
Jun 14, 2017, 9:49:03 PM6/14/17
to Google's DoubleClick for Publishers API Forum
Thank you SreeLakshmi,

Let me create a new thread for API exception, since its totally different from the socket exception.

Thank you again.

Reply all
Reply to author
Forward
0 new messages