views:

281

answers:

2

I have a Java class I have to run, my current web host (shared) will not allow Java. I need to host it on another server. I was told I can't call Java from ColdFusion on a separate server, but what if I call a CF function on the 2nd server then have that function call the Java class, return the data to CF then that function go back to the original? Sorry if that sounds kludgy, but I can't think of any other solutions.

Anyone? Ideas?

+4  A: 

I would setup a web service using coldfusion on your second server to call the java class and then just have the site on your web host consume that web service.

Jeremy Reagan
+10  A: 

If you've got access to a server that can run Java, can you not run the whole thing on there anyway?

Otherwise, as you've figured, you can just create a component with a remote function and have that do the work, along the lines of:

<cfcomponent output="false">

 <cffunction name="runMyJava" returntype="String" output="false" access="remote">
  <cfargument name="MyArg" type="String" />

  <cfset var MyObj = createObject('java','whatever') />

  <cfreturn MyObj.doJavaMagic( Arguments.MyArg ) />
 </cffunction>

</cfcomponent>


Then on your other server, you'd have something like...

<cfset MyWebService = createObject('webservice','https://myotherserver/mycomponent.cfc?wsdl')/&gt;

<cfset MyString = MyWebService.runMyJava( MyString ) />


Note that this example uses https - since you'd presumably want to protect the data from flying over the Internet in plain text.

It may also be sensible to IP-restrict the server so only you can connect to it, or use other appropriate methods to secure it.

Peter Boughton