Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 387
  • Last Modified:

Java ArrayList inside of CFSCRIPT

I was given some sample java code to use to pass information back to a web service.   We are using ColdFusion and I need to be able to put the ArrayList code inside of the CFSCRIPT to send it back.

List<CheckoutRecord> list = new ArrayList<CheckoutRecord>();
CheckoutRecord record = new CheckoutRecord();
record.setCustomerID=("000123123")
list.add(record);

Open in new window


I get the error message A script statement must end with ";" so I know I am missing something really easy...
0
digitalwise
Asked:
digitalwise
  • 6
  • 5
  • 3
  • +2
1 Solution
 
rjohnsonjrCommented:
line 3 is missing a ; at the end.
0
 
CEHJCommented:
List<CheckoutRecord> list = new ArrayList<CheckoutRecord>();
CheckoutRecord record = new CheckoutRecord();
record.setCustomerID("000123123");
list.add(record);
                                  

Open in new window

Not only that - i think it should read as above
0
 
digitalwiseAuthor Commented:
Good catch both of you.   But I am getting the error on the first line - List<CheckoutRecord> list = new ArrayList<CheckoutRecord>();

<cfscript>

	List<CheckoutRecord> list = new ArrayList<CheckoutRecord>();
CheckoutRecord record = new CheckoutRecord();
record.setCustomerID("000123123");
list.add(record);
	
  

</cfscript>

Open in new window

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
krakatoaCommented:
Check whether its an AWT or Util List - or you have made the right library import.
0
 
digitalwiseAuthor Commented:
So I wasn't creating an object (because clearly I am out of my depth with this).   This isn't working yet but I need to start with that createObject piece - not calling it all correctly though.

myArray = createObject("java", "java.util.ArrayList<CheckoutRecord>").init();
CheckoutRecord record = new CheckoutRecord();
record.setCustomerID("6190");

Open in new window

0
 
krakatoaCommented:
Prob because you are missing the syntax in line 1 of CEHJ's comment.
0
 
digitalwiseAuthor Commented:
Yep - but I don't know how to write it - that's why it isn't there.   This is way out of what I normally do so I am looking for some help.   I was trying to use what I wrote instead.
0
 
_agx_Commented:
@digitalwise

These guys are right about the java syntax, but the CF translation is a bit different.

List<CheckoutRecord> list = new ....

a) CF is typeless, so you don't need to declare the variable type as you do in java. It's just:

<cfscript>      
    list = ...something...;
</cfscript>      

Open in new window



b) In CF you must use createObject() to create an instance of an object. Then invoke the psuedo-constructor init() instead of using the keyword new.

c) CF is typeless and doesn't use the java generics syntax.

So get rid of the type declaration, generics, and create the ArrayList like this:

<cfscript>
    list = createObject("java", "java.util.ArrayList").init();
    // you can now add ANY type of object to the list
    // but as a simple test use a string like "foo"
    list.add( "foo" );
</cfscript>

Open in new window



  CheckoutRecord record = new CheckoutRecord();


What type of object CheckoutRecord: CFC, custom java class, ...?
0
 
CEHJCommented:
You probably need to invoke createObject on CheckoutRecord too
0
 
_agx_Commented:
Probably. Is CheckoutRecord a class from a custom java jar? If yes

1) Did you add it to the CF class path?
2) What's the full path to that class? ie The full path for ArrayList is java.util.ArrayList
0
 
digitalwiseAuthor Commented:
CheckoutRecord is a class from a custom java jar - we are connected to a webservice

 ws = CreateObject("webservice",
"website?wsdl");
    ws.AnotherCustomClass("username", "password", "systemID");
    req = GetSOAPResponse(ws);

Open in new window


then I am supposed to generate the list of variables to send back to them.
0
 
digitalwiseAuthor Commented:
this is what I am trying to send back:

ws.subscribeNotification("systemid","client trans id", "token", list);

Open in new window


And list is supposed to be all of the variables that I am trying to set with this array.
0
 
_agx_Commented:
I'm confused. I though you were trying to connect to the web service w/just java, but it looks like you're actually using createObject("webservice").  Did you already try using just CF ... and something didn't work? For lists, you can usually just create a CF array.  Append structures to it (which CF should convert to instances of the custom class). Then pass the list into the subscribeNotification() method.

Did you try that and it didn't work?
0
 
_agx_Commented:
Also, is there a public wsdl we can check out?
0
 
digitalwiseAuthor Commented:
No public WSDL.   I am connecting to their web service, getting a key, and then sending information back to them that is supposed to be a list of variables.  

So connect.

ws = CreateObject("webservice",
"website?wsdl");
    ws.AnotherCustomClass("username", "password", "systemID");
    req = GetSOAPResponse(ws);

Open in new window


Get Key

Make my List

They sent me the sample code to create the list

List<CheckoutRecord> list = new ArrayList<CheckoutRecord>();
CheckoutRecord record = new CheckoutRecord();
record.setCustomerID("00000123132");
record.setProductID("09123");
list.add(record);

Open in new window




Send List back to them.

ws.subscribeNotification("systemid","client trans id", "token", list);

Open in new window


Somewhere I am not doing something properly...
0
 
CEHJCommented:
Please start posting error output - there's got to be some ..?
0
 
_agx_Commented:
The reason I ask is that java does things differently, so the code you'd use there is often different than what you'd need in CF.

Typically when you use createObject("webservice") you are only work with simple values like strings, dates, arrays (ie what java calls a List) and structures (a Map in java). Java uses classes like "CheckoutRecord".to represent complex objects in WSDL. Whereas CF uses structures to represent complex objects - not classes.  

Translated that means you normally create a structure with the right properties to represent "CheckoutRecord" instead of using createObject("java", "CheckoutRecord"). Then append the structures to your "list".  In cfscript something like this.  

Note - I'm just guessing at the property names.  As mentioned, we need to see error messages - and the WSDL snippet for the CheckoutRecord to be more specific.

         // create a new structure
         record = {};
         // create a structure to represent the CheckoutRecord
         record.customerID = "00000123132";
         record.productID = "09123";
         // append the record to your list
         list = [ record ];

         // create the web service
        ws = createObject("webservice", "the url here....");
        ws.subscribeNotification("systemid","client trans id", "token", list);

Open in new window


Did you try something like that?


> createObject("java", "CheckoutRecord").

In order to create an instance of the java class "CheckoutRecord" you need it's full package path, not just the name ie Like "java.util.ArrayList" not just "ArrayList". Also, the jar containing that class needs to be in your class path.  I don't if you even have a separate jar containing that class...  Honestly I'd try the pure CF approach first..
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

  • 6
  • 5
  • 3
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now