Pete Freitag Pete Freitag

Using Java Web Services with CFMX

coldfusionjava

JWS files are nothing more than a Java class with a .jws extension. But when placed on a web server with Axis installed (such as ColdFusion MX), you can expose that class as a web service. This works just like CFC's do in ColdFusion. Here's an example JWS we will call CaseService.jws:

public class CaseService
{
	public String toUpper(String str)
	{
		return str.toUpperCase();
	}
	public String toLower(String str)
	{
		return str.toLowerCase();
	}
}

If we add a ?wsdl to the url, it displays the WSDL for the service just like in CFMX. Let's try to invoke it in CFML:

<cfset case = CreateObject("webservice", "http://localhost:8500/CaseService.jws?wsdl")>
<cfset result = case.toUpper("Case Me uP!")>
<cfoutput>#result#</cfoutput>

It should display CASE ME UP!

This may be a better way to go than CFC's if your exposing Java classes as web services in CFMX. JWS files appear to work on both Pro and Enterprise versions of CFMX.


Like this? Follow me ↯

Using Java Web Services with CFMX was first published on January 21, 2004.

If you like reading about coldfusion, jws, or web services then you might also like:

FuseGuard Web App Firewall for ColdFusion

The FuseGuard Web Application Firewall for ColdFusion & CFML is a high performance, customizable engine that blocks various attacks against your ColdFusion applications.

Comments

By the way, this is a function of the underlying JRUN J2EE server, and is not supported on other J2EE platforms. It realy has nothing to do with CFMX. I just through I should share. Really cool, though. One more way to leverage Java within CF--without having to deploy JAR files!
by Paul Kenney on 01/22/2004 at 2:07:30 PM UTC
This is actually part of Apache AXIS, so if you set things up properly you can use it with any Servlet container (I have it working well with tomcat).
by Pete Freitag on 01/23/2004 at 4:33:52 PM UTC
Can this webservice be on a different server and app server (ie., Oracle 9iAS).
by Patrick Whittingham on 04/07/2004 at 3:46:59 PM UTC
Patrick, yes the web service can be on any server with JSP support (ie tomcat, any j2ee server). You just need to download apache axis, and add the jar files to your lib directory, and setup a servlet mapping for .jws files to point to the Axis servlet.
by Pete Freitag on 04/08/2004 at 2:52:09 PM UTC
k, that's seem to work, despite of Coldfusion. How about returning more complex objects, such as custom classes?
by hjubal on 05/20/2005 at 5:49:50 AM UTC
I started out answering a column metadata question and got this interesting little program to work. Its a way to dynamically load classes from source code using JWS and classloaders http://www.cfide.org/getColumnLength.html
by dan on 03/15/2006 at 6:12:15 PM UTC