Skip to main content
Inspiring
May 3, 2016
Question

Change to javacast or json in CF2016?

  • May 3, 2016
  • 2 replies
  • 1388 views

We were running CF8 and the following code worked.

<cfset attributes.email = "manual2016@2016.com">
<cfset attributes.bday = "05-04">
<cfset attributes.name = "test">
<!--- <cfparam name="attributes.email" default="#form.email#">
<cfparam name="attributes.bday" default="#form.month#-#form.year#-1900">
<cfparam name="attributes.name" default="#form.name#"> --->

<cfset attributes.sdk.addContactStruct = structNew()/>
<cfset attributes.sdk.addContactStruct["Email"] = JavaCast("string", "#attributes.email#") />
<cfset attributes.sdk.addContactStruct["Birthday"] = JavaCast("string", "#attributes.bday#") />
<cfset attributes.sdk.addContactStruct["FirstName"] = JavaCast("string", "#attributes.name#") />
<cfset variables.optinreason = JavaCast("string", "Store newsletter form") />

<cfset contactId = application.sdk.addWithDupCheck(attributes.sdk.addContactStruct, "Email", variables.optinreason) />

<cfset TagcontactId = application.sdk.addToGroup(contactId, 178)/>

We did an upgrade to CF2016 and part of this code no longer works. Specifically:

<cfset TagcontactId = application.sdk.addToGroup(contactId, 178)/>

Did something in the newer versions of CF change how we need to cast variables like this when they are being past to Java?

I've tried to get error messages with CFTRY back but only get

Diagnostics: null null
The error occurred on line -1.

This topic has been closed for replies.

2 replies

BKBK
Community Expert
Community Expert
May 4, 2016

I would dump or log contactId and take a look.

Inspiring
May 4, 2016

The first part of the code still works where a call to Infusionsoft creates a contact and generates an id.

The problem is this second piece that sends back the contactID and an integer representing a category tag.

sdk.addtogroup is a function

<cfargument name="contactId" required="true" type="numeric" />

<cfargument name="groupId" required="true" type="numeric" />

<cfset var loc = StructNew() />

<cfset loc.array = ArrayNew(1) />

<cfset ArrayAppend(loc.array, JavaCast("int", arguments.contactId)) />

<cfset ArrayAppend(loc.array, JavaCast("int", arguments.groupId)) />

<cfreturn this.call("ContactService.addToGroup", loc.array) />

<cffunction name="addToGroup" output="false" access="public" returntype="boolean" hint="http://developers.infusionsoft.com/classes/contact/##addToGroup"> <cfargument name="contactId" required="true" type="numeric" /> <cfargument name="groupId" required="true" type="numeric" /> <cfset var loc = StructNew() /> <cfset loc.array = ArrayNew(1) /> <cfset ArrayAppend(loc.array, JavaCast("int", arguments.contactId)) /> <cfset ArrayAppend(loc.array, JavaCast("int", arguments.groupId)) /> <cfreturn this.call("ContactService.addToGroup", loc.array) /> </cffunction>

BKBK
Community Expert
Community Expert
May 4, 2016

athanasiusrc wrote:

<cfreturn this.call("ContactService.addToGroup", loc.array) />

That line raises questions:

1) What is ContactService.addToGroup?

2) If, as you say, addToGroup is a function, then what is the string "ContactService.addToGroup" doing there as argument of a function?

3) Assuming you can justify the use of "ContactService.addToGroup", then why not just <cfreturn call("ContactService.addToGroup", loc.array)>?

Carl Von Stetten
Legend
May 3, 2016

What, specifically is application.sdk.addToGroup()?  Is that a Java object method?

If so, is that Java object compatible with the JVM version that ColdFusion 2016 runs on (Java 8)?  ColdFusion 8 ran on a much older version of Java and the object may not be compatible with Java 8.

Inspiring
May 4, 2016

These are the java objects created:

<cfscript>
this.setApiKey(arguments.apiKey);
try
{
variables.url = CreateObject("java", "java.net.URL").init("https://#arguments.subdomain#.infusionsoft.com/api/xmlrpc");
variables.configImpl = CreateObject("java", "org.apache.xmlrpc.client.XmlRpcClientConfigImpl");
variables.configImpl.setServerURL(variables.url);
variables.configImpl.setConnectionTimeout(arguments.timeout * 1000);
// create the client object
variables.client = CreateObject("java", "org.apache.xmlrpc.client.XmlRpcClient");
variables.client.setConfig(variables.configImpl);
variables.client.setTransportFactory(CreateObject("java", "org.apache.xmlrpc.client.XmlRpcCommonsTransportFactory").init(variables.client));
}
catch (any e)
{
variables.javaLib = false;
variables.client = CreateObject("component", "com.liquifusion.xmlrpc.Client").init(ssl=true, host=arguments.subdomain & ".infusionsoft.com", path="/api/xmlrpc", timeout=arguments.timeout);
variables.transform = CreateObject("component", "com.liquifusion.xmlrpc.Transform").init();
}
return this;
</cfscript>
Carl Von Stetten
Legend
May 4, 2016

Once again, is that Java object compatible with Java 8?  Just because one or more methods in the object work on Java 8 doesn't mean all of them will.  You can't see the Java dependencies that are inside the Java classes, so you don't know if they are relying on an older dependency class signature or a deprecated/removed class.  And the limited error message you are getting seems to indicate the problem is with Java, not ColdFusion.