Using Java Web Services with CFMX

January 21, 2004

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!")>

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 ↯

You might also like:

4 people found this page useful, what do you think?


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!
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).
Can this webservice be on a different server and app server (ie., Oracle 9iAS).
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.
k, that's seem to work, despite of Coldfusion. How about returning more complex objects, such as custom classes?
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

Foundeo Inc.