Problem while using the API in ColdFusion

107 views
Skip to first unread message

Kevin

unread,
Feb 23, 2016, 9:11:31 AM2/23/16
to AdWords API Forum
Hello all,

I tried to use the Google AdWords API Java Classes in ColdFusion, but encountered an error/problem I don't have an answer to yet. Here is what I did so far.

I started with creating an refresh token and it works without any major problems.
Afterwards I started to adapt the GetCampaigns Example from Java to ColdFusion.

Here is the code I use:
    function getCampaigns() {
        // sure these fixed variables are set to the correct values in my app... :)
        var CLIENT_ID       = "";
        var CLIENT_SECRET   = "";
        var REFRESH_TOKEN   = "";
        var DEVELOPER_TOKEN = "";

        var oAuth2Credential = createObject("java", "com.google.api.ads.common.lib.auth.OfflineCredentials$Builder").init()
                                    .forApi(createObject("java", "com.google.api.ads.common.lib.auth.OfflineCredentials$Api").ADWORDS)
                                    .withClientSecrets(CLIENT_ID, CLIENT_SECRET)
                                    .withRefreshToken(REFRESH_TOKEN)
                                    .build()
                                    .generateCredential();
        
        // Construct an AdWordsSession.
        var session = createObject("java", "com.google.api.ads.adwords.lib.client.AdWordsSession$Builder").init()
                        .withOAuth2Credential(oAuth2Credential)
                        .withDeveloperToken(DEVELOPER_TOKEN)
                        .withUserAgent("TimoCom-AdWords-Scheduler") // I have to set it | I don't know if it matters or not or what else.
                        .build();
        
        var campaignService = createObject("java", "com.google.api.ads.adwords.axis.factory.AdWordsServices").init()
                                .get(session, createObject("java", "com.google.api.ads.adwords.axis.v201601.cm.CampaignServiceInterface").getClass());
        
        var builder = createObject("java", "com.google.api.ads.adwords.axis.utils.v201601.SelectorBuilder").init();
        
        var CampaignField = createObject("java", "com.google.api.ads.adwords.lib.selectorfields.v201601.cm.CampaignField"); // enum
        
        var offset = 0;
        var PAGE_SIZE = 100;
        
        var usedCampaignFields = javaCast("com.google.api.ads.adwords.lib.selectorfields.EntityField[]", [CampaignField.Id, CampaignField.Name]);
        
        var selector = builder
                        .fields(usedCampaignFields)
                        .orderAscBy(CampaignField.Name)
                        .offset(offset)
                        .limit(PAGE_SIZE)
                        .build();

        writeDump(var=usedCampaignFields);
        writeDump(var=selector);
        writeDump(var=campaignService);

If I only use this code it is working, like it should. I get the dumps(output of public information) of the variables/classes.
But when I try to get the campaigns with the following line, the application crashes without throwing or logging the error.
var page = campaignService.get(selector).getEntries();
// or simply writeDump(campaignService.get(selector));
The error isn't handled within the onError method in our Application.cfc nor is it logged in the Coldfusion logs nor in the Catalina Logs of Apache.
Every other Error I got previously was handled by the onError method and I could see it and adapt my code to have it working, but not this error.

I don't know if I'm doing something wrong or it's an unhandled error in the AdWords API, in Apache, in ColdFusion, in Java, or what is happening here.
Therefore I hope that one of you can help me.


We're using ColdFusion 9 V9,0,1,274733 on a Linux with Java V1.8.0_71.

Umesh Dengale

unread,
Feb 24, 2016, 9:29:46 AM2/24/16
to AdWords API Forum
Hello,

Could you provide your application logs which make the AdWords API call? The logs will help us to investigate further. Just click Reply privately to author in the forum when responding. 

Regards,
Umesh, AdWords API Team.

Kevin

unread,
Feb 25, 2016, 3:04:53 AM2/25/16
to AdWords API Forum
Hello,

After investigation more into the problem of not logging the errors I found a way to get the stacktrace of the error.

Here is the error message:
java.lang.NullPointerException
        at
com
.google.api.ads.common.lib.soap.axis.AxisHandler.invokeSoapCall(AxisHandler.java:239)

        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.$Proxy17.get(Unknown Source)
        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:497)
        at coldfusion
.runtime.StructBean.invoke(StructBean.java:508)
        at coldfusion
.runtime.CfJspPage._invoke(CfJspPage.java:2393)
        at
cfindex2ecfm69063337$funcTESTSHIT
.runFunction(/opt/tomc12180/webapps/ROOT/WWW/sec/500000/module/content/marketing/adWordsAPI/index.cfm:104)

        at coldfusion
.runtime.UDFMethod.invoke(UDFMethod.java:472)
        at
coldfusion
.runtime.UDFMethod$ArgumentCollectionFilter.invoke(UDFMethod.java:368)

        at
coldfusion
.filter.FunctionAccessFilter.invoke(FunctionAccessFilter.java:55)

        at coldfusion
.runtime.UDFMethod.runFilterChain(UDFMethod.java:321)
        at coldfusion
.runtime.UDFMethod.invoke(UDFMethod.java:220)
        at coldfusion
.runtime.CfJspPage._invokeUDF(CfJspPage.java:2582)
        at
cfindex2ecfm69063337
.runPage(/opt/tomc12180/webapps/ROOT/WWW/sec/500000/module/content/marketing/adWordsAPI/index.cfm:115)

        at coldfusion
.runtime.CfJspPage.invoke(CfJspPage.java:231)
        at coldfusion
.tagext.lang.IncludeTag.doStartTag(IncludeTag.java:416)
        at coldfusion
.filter.CfincludeFilter.invoke(CfincludeFilter.java:65)
        at
coldfusion
.filter.ApplicationFilter.invoke(ApplicationFilter.java:360)
        at
coldfusion
.filter.RequestMonitorFilter.invoke(RequestMonitorFilter.java:48)

        at coldfusion
.filter.MonitoringFilter.invoke(MonitoringFilter.java:40)
        at coldfusion
.filter.PathFilter.invoke(PathFilter.java:94)
        at coldfusion
.filter.ExceptionFilter.invoke(ExceptionFilter.java:70)
        at
coldfusion
.filter.ClientScopePersistenceFilter.invoke(ClientScopePersistenceFilter.java:28)

        at coldfusion
.filter.BrowserFilter.invoke(BrowserFilter.java:38)
        at coldfusion
.filter.NoCacheFilter.invoke(NoCacheFilter.java:46)
        at coldfusion
.filter.GlobalsFilter.invoke(GlobalsFilter.java:38)
        at coldfusion
.filter.DatasourceFilter.invoke(DatasourceFilter.java:22)
        at coldfusion
.filter.CachingFilter.invoke(CachingFilter.java:62)
        at coldfusion
.CfmServlet.service(CfmServlet.java:200)
        at
coldfusion
.bootstrap.BootstrapServlet.service(BootstrapServlet.java:89)
        at
org
.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)

        at
org
.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)

        at
coldfusion
.monitor.event.MonitoringServletFilter.doFilter(MonitoringServletFilter.java:42)

        at
coldfusion
.bootstrap.BootstrapFilter.doFilter(BootstrapFilter.java:46)
        at
org
.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)

        at
org
.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)

        at
org
.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
        at
org
.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)

        at
org
.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)

        at
org
.apache.catalina.filters.ExpiresFilter.doFilter(ExpiresFilter.java:1201)

        at
org
.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)

        at
org
.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)

        at
org
.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)

        at
org
.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)

        at
org
.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)

        at
org
.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)

        at
org
.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)

        at
org
.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)

        at
org
.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)

        at
org
.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:436)

        at
org
.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1078)

        at
org
.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625)

        at
org
.apache.tomcat.util.net.AprEndpoint$SocketWithOptionsProcessor.run(AprEndpoint.java:2454)

        at
java
.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)

        at
java
.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)

        at
org
.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)

        at java
.lang.Thread.run(Thread.java:745)      

Michael Cloonan (AdWords API Team)

unread,
Feb 25, 2016, 9:50:47 AM2/25/16
to AdWords API Forum
Hello,

I apologize if the previous request wasn't clear. Unfortunately, we are only able to help with the AdWords API specifically, so the request was for logs to the AdWords API. I understand that you may not be getting as far as actually invoking a call to the AdWords API, however, as it appears the error you're encountering happens before that.

We are not able to provide assistance with ColdFusion specifically, however. Are you able to make calls to the AdWords API without using that framework?

Regards,
Mike, AdWords API Team
...

Kevin

unread,
Mar 8, 2016, 8:56:07 AM3/8/16
to AdWords API Forum
Hello,

sorry for the late reply.

I think you mean the logfile created by log4j, or? I'm sorry, but I can't provide you the log file as I can't find it on the system. I think the error handling if handled by the build in error logging system in ColdFusion.
So here is the only information I can provide you with at the moment:  java.lang.NullPointerException at com.google.api.ads.common.lib.soap.axis.AxisHandler.invokeSoapCall(AxisHandler.java:239)

Just for your Information: ColdFusion is an Application Servlet Container working on top of Java on a Tomcat Server (in our case) which has it's own language. As it sit's on top of Java you can use most parts of Java.


I'll try to develop the required part completly in Java, but as I haven't developed anything with Java yet I'm not sure if it will work in the end.

Josh Radcliff (AdWords API Team)

unread,
Mar 8, 2016, 9:58:16 AM3/8/16
to AdWords API Forum
Hi,

The client library uses the Guice dependency injection framework pretty heavily, so I wonder if ColdFusion doesn't play nice with Guice. Are you able to step through the code in a debugger to see if the MessageContext on 236 of AxisHandler.java is null? I'm trying to figure out if that's the source of the NPE or if instead it's because messageContext.getRequestMessage() returns null.

Thanks,
Josh, AdWords API Team

Kevin

unread,
Mar 17, 2016, 4:49:14 AM3/17/16
to AdWords API Forum
No I don't think I will be able to step through with a debugger as I only use the compiled jar files not the class files.

Josh Radcliff (AdWords API Team)

unread,
Mar 17, 2016, 10:37:53 AM3/17/16
to AdWords API Forum
Hi,

The compiled class files in the jar files should have debugging info (line numbers, etc.), so I would expect this to work in a debugger. Did you check in your IDE?

Thanks,
Josh, AdWords API Team
Reply all
Reply to author
Forward
0 new messages