Using Java Web Services with CFMX

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.
Tweet
Related Entries
- ColdFusion SOAP Web Services and onRequestStart - November 19, 2009
Trackbacks
Trackback Address: 104/2E21DF3D27CDBE3E7B9E9E267C6DC322
Comments
On 01/22/2004 at 7:14:31 AM EST Steve Ringo wrote:
1
Wow! What a discovery. This opens up a whole new set of options for developing web services. How did you find this out? I wonder if this is officially "supported" by the Macromedia crew.
Thanks
Steve
On 01/22/2004 at 11:19:53 AM EST dave ross wrote:
2
just for fun, I tried this out. I have no java experience whatsoever, but I do have eclipse installed so I gave it a go. I made a simple hello world class, compiled it, and then moved the .class into my web root and renamed it with a .jws extension. When I try to get the wsdl, AXIS throws: ---------------------------------------- Sorry, something seems to have gone wrong... here are the details:
Fault - Error while compiling: C:\CFusionMX\wwwroot\WEB-INF/jwsClasses\helloWorld.java AxisFault faultCode: {http://xml.apache.org/axis/}Server.compileError faultSubcode: faultString: Error while compiling: C:\CFusionMX\wwwroot\WEB-INF/jwsClasses\helloWorld.java faultActor: faultNode: faultDetail: {}Errors: Error compiling C:\CFusionMX\wwwroot\WEB-INF/jwsClasses\helloWorld.java: Line 0, column 0: Please ensure that you have your JDK's rt.jar listed in your classpath. Jikes needs it to operate. Line 0, column 0: Please ensure that you have your JDK's rt.jar listed in your classpath. Jikes needs it to operate. Line 0, column 0: Please ensure that you have your JDK's rt.jar listed in your classpath. Jikes needs it to operate. -------------------------------------
I went into cf administrator and added a direct classpath to rt.jar but that didn't help. Any suggestions (it's probably something simple... but this really is "hello world" in java for me).
On 01/22/2004 at 12:52:36 PM EST dave ross wrote:
3
never mind, I figured it out (need to rename the .java to .jws, not the compiled class).
Cool!
btw- seems you may be having the cfqueryparam double quote bug on this blog. Test's.
On 01/22/2004 at 2:10:50 PM EST Patrick Whittingham wrote:
4
Can cfmx invoke this web service if is on a different web server?
On 01/22/2004 at 4:07:30 PM EST Paul Kenney wrote:
5
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!
On 01/23/2004 at 6:33:52 PM EST Pete Freitag wrote:
6
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).
On 04/07/2004 at 5:46:59 PM EDT Patrick Whittingham wrote:
7
Can this webservice be on a different server and app server (ie., Oracle 9iAS).
On 04/08/2004 at 4:52:09 PM EDT Pete Freitag wrote:
8
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.
On 05/10/2005 at 12:52:18 PM EDT cfdev_bd wrote:
9
This is really cool thing. I have tried it. but getting an error. it might be something problem in my CFMX7.0 setting. here I am giving the error. Do you have any idea about this. Could not generate stub objects for web service invocation. Name: http://w049228/_com/CaseService.jws?wsdl. WSDL: http://w049228/_com/CaseService.jws?wsdl. org.xml.sax.SAXException: Fatal Error: URI=null Line=1: Content is not allowed in prolog. It is recommended that you use a web browser to retrieve and examine the requested WSDL document for correctness. If the requested WSDL document can't be retrieved or it is dynamically generated, it is likely that the target web service has programming errors. The error occurred in D:\WEBSPACE\BEHRINGER\raffle_stat\invoke.cfm: line 27 25 : ----> 26 : 27 : <cfset case = CreateObject("webservice", "http://w049228/_com/CaseService.jws?wsdl")> 28 : <cfset result = case.toUpper("Case Me uP!")> 29 : <cfoutput>#result#</cfoutput>
On 05/17/2005 at 10:39:25 AM EDT paul wrote:
10
I've tried Using Java Web Services with CFMX as with the examples here but, get "Could not generate stub objects for web service invocation" is there anything I need to do (setting, etc) before this will work with CFMX and/or Java? Thanks in advance Paul
On 05/20/2005 at 7:49:50 AM EDT hjubal wrote:
11
k, that's seem to work, despite of Coldfusion. How about returning more complex objects, such as custom classes?
On 11/02/2005 at 8:24:34 PM EST Dan Plesse wrote:
12
I don't believe this process can reply with anything but String data. Can anyone test this out and send me an email? Dan
On 03/15/2006 at 8:12:15 PM EST dan wrote:
13
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
Post a Comment
Recent Entries
- Howto Install and Run the Android Emulator
- jQuery UI Autocomple IE 6 Select List z-Index Issues
- Path Traversal Vulnerability Security Hotfix for ColdFusion Released
- Using AntiSamy with ColdFusion
- Writing Secure CFML Slides from CFUnited 2010
- Locking Down ColdFusion Presentation Slides
- Cross Domain Data Theft using CSS
- Using jQuery UI Autocomplete with Hidden ID's
Thanks
Steve
Fault - Error while compiling: C:\CFusionMX\wwwroot\WEB-INF/jwsClasses\helloWorld.java AxisFault faultCode: {http://xml.apache.org/axis/}Server.compileError faultSubcode: faultString: Error while compiling: C:\CFusionMX\wwwroot\WEB-INF/jwsClasses\helloWorld.java faultActor: faultNode: faultDetail: {}Errors: Error compiling C:\CFusionMX\wwwroot\WEB-INF/jwsClasses\helloWorld.java: Line 0, column 0: Please ensure that you have your JDK's rt.jar listed in your classpath. Jikes needs it to operate. Line 0, column 0: Please ensure that you have your JDK's rt.jar listed in your classpath. Jikes needs it to operate. Line 0, column 0: Please ensure that you have your JDK's rt.jar listed in your classpath. Jikes needs it to operate. -------------------------------------
I went into cf administrator and added a direct classpath to rt.jar but that didn't help. Any suggestions (it's probably something simple... but this really is "hello world" in java for me).
Cool!
btw- seems you may be having the cfqueryparam double quote bug on this blog. Test's.
http://www.cfide.org/getColumnLength.html


add to del.icio.us




