2 Replies - 348 Views - Last Post: 21 November 2017 - 11:28 AM Rate Topic: -----

#1 midasxl  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 207
  • Joined: 03-December 08

When ColdFusion creates java object does it automatically run it?

Posted 02 November 2017 - 07:52 AM

Greetings and thanks for reading,

I am creating a java object in Coldfusion from an existing .jar file on the CF Server. My question is, should the main method within the .jar file run when the object is created, or do I need to do something else to kick it off?

The .jar file contents (abridged):

package a.b.c.xmlupload;

import org.apache.commons.codec.binary.Base64;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocketFactory;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import java.io.*;
import java.net.MalformedURLException;
import java.net.ProtocolException;
import java.net.URL;
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.security.*;
import java.security.cert.CertificateException;
import java.util.Properties;

import org.apache.commons.lang3.StringUtils;

public class Main { 

        private static final Logger log = LogManager.getLogger(Main.class);

	private static volatile JAXBContext jaxbContext;

	private enum Status {
		SUCCESS, ERROR
	}

	private Main() {
		initialize();
	}

	public static void main(String[] args) { 

	        log.info("Starting XML Upload Tool");

		Properties properties = new Properties(); 
		// Creates a properties object by using an empty constructor

		try {
			File jarPath = new File(Main.class.getProtectionDomain().getCodeSource().getLocation().getPath());
			String propertiesPath = jarPath.getParent();
			log.info(" propertiesPath=" + propertiesPath);
			properties.load(new FileInputStream(propertiesPath + "/xml-upload.properties"));

		} catch (IOException ioe) {
			log.error("Error: failed to load properties file", ioe);
		}

		try {
			new Main().run(properties);
		} catch (IOException ioe) {
			log.error("Error: failed Main().run", ioe);
		}

	}



The Coldfusion:

<cfset obj = createObject("java", "a.b.c.xmlupload.Main") />
<cfdump var="#obj#"/>



Am I to understand that when creating the object it will also run it? Will the Java interpreter look for the Main class and then begin execution at the main method within? When I dump the java object (#obj#) it shows me that the object was created, but I'm not certain it is actually running it.

Thanks for any insight you may be able to provide!

Cheers,
Mark

Is This A Good Question/Topic? 0
  • +

Replies To: When ColdFusion creates java object does it automatically run it?

#2 Craig328  Icon User is offline

  • I make this look good
  • member icon

Reputation: 2024
  • View blog
  • Posts: 3,609
  • Joined: 13-January 08

Re: When ColdFusion creates java object does it automatically run it?

Posted 03 November 2017 - 08:41 AM

I don't know Java so I'm not qualified to render an opinion. That said, the createObject tag creates a Java object...and it appears that your Java code has events where it drops an update to the log if it runs.

My understanding has always been that creating the object and invoking it were two different things. Try calling your OBJ variable as the value to a CFSET variable and then dump the value of that resulting variable. Or, check the whatever log it is that Java is writing to. Or both.

Good luck!

This post has been edited by Craig328: 03 November 2017 - 08:42 AM

Was This Post Helpful? 0
  • +
  • -

#3 midasxl  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 207
  • Joined: 03-December 08

Re: When ColdFusion creates java object does it automatically run it?

Posted 21 November 2017 - 11:28 AM

Thanks for the response! I was under the impression it only created the object as well, not actually kicked it off. I'll have one of the admins check the log when I run the page to see what happens. Thanks!!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1