|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Web Service using JAVA objects - Problem
Hi, I'm trying to create a web service that will validate an xml string against a specified schema. I got my code already working by itself (in regular cfm page). It works fine. But know I'm trying to apply that code as a web service. So everyone at my work can use the web service to validate their xml files. The problem is that I’m getting an error when I’m trying to browse my component. This error:
Unable to complete CFML to Java translation I don’t know what is going on, this is my first web service that I’m doing, so I’m kind of newbie. I hope somebody can help me out here. Here is my code: <cfcomponent> <cffunction name="validateSchema" access="public" returntype="boolean" output="false"> <cfargument name="xmlString" type="any" > <cfargument name="noNamespaceXsdUri" type="string"> <cfargument name="namespaceXsdUri" type="string"> <cfargument name="parseError" type="struct"> <!-- Creating Java Objects --> <cfset reader = CreateObject("java","java.io.StringReader").init(xmlString)/> <cfset inputSource = CreateObject("java","org.xml.sax.InputSource").init(reader)/> <cfset parser = CreateObject("java","org.apache.xerces.parsers.SAXParser")/> <cfset eHandler = CreateObject("java","org.apache.xml.utils.DefaultErrorHandler")/> <cfset err = structNew() /> <cfset success = True /> <cfset apFeat = "http://apache.org/xml/features/" /> <cfset apProp = "http://apache.org/xml/properties/" /> <cfscript> function makeUriFromPath(path) { var uri = path; // make all backslashes into slashes uri = replace(uri, "\", "/", "all"); if (left(uri,1) is "/") { uri = right(uri, len(uri) - 1); } uri = "file:///" & uri; return uri; } noNamespaceXsdUri = makeUriFromPath(expandPath(noNamespaceXsdUri)); eHandler.init(); if (structKeyExists(arguments, "parseError")) { err = arguments.parseError; } try { parser.setErrorHandler(eHandler); parser.setFeature( "http://xml.org/sax/features/validation",true); parser.setFeature(apFeat & "validation/schema",true); parser.setFeature(apFeat & "validation/schema-full-checking",true); if (structKeyExists(arguments, "noNamespaceXsdUri") and arguments.noNamespaceXsdUri neq "") { parser.setProperty(apProp & "schema/external-noNamespaceSchemaLocation", arguments.noNamespaceXsdUri ); } if (structKeyExists(arguments, "namespaceXsdUri") and arguments.namespaceXsdUri neq "") { parser.setProperty(apProp & "schema/external-schemaLocation",arguments.namespaceXsdUri ); } parser.parse(arguments.xmlString); } catch (Any ex) { structAppend(err, ex, true); success = false; } </cfscript> <cfreturn success> </cffunction> </cfcomponent> |
|
#2
|
|||
|
|||
|
It would have been helpful for you to post the actual error that you are getting. But the first thing I notice is that you must have access="remote" in order for the method to be available as a web service.
__________________
Ask if you have a question, but also help answer questions that you have knowledge of! Thanks, Brian. How to Post a Question in the Forums |
|
#3
|
|||
|
|||
|
New Code!
I got my component work( not working, but at least visible at the component browser).
My component (web service) is: <cfcomponent> <cffunction name="validateSchema" returnType = "any" access="remote" output="false"> <cfargument name="xmlString" type="string" required="true" > <cfargument name="noNamespaceXsdUri" type="string" > <cfargument name="namespaceXsdUri" type="string"> <!-- Creating Java Objects --> <cfset reader = CreateObject("java","java.io.StringReader").init(xmlDisplay) > <cfset inputSource = CreateObject("java","org.xml.sax.InputSource").init(reader) > <cfset parser = CreateObject("java","org.apache.xerces.parsers.SAXParser") > <cfset arguments.xmlString=inputSource> <cfset Handler = createObject("java","org.apache.xml.utils.DefaultErrorHandler" )> <cfset err = structNew() > <cfset success = True > <cfset apFeat = "http://apache.org/xml/features/" > <cfset apProp = "http://apache.org/xml/properties/" > <cfscript> eHandler.init(); if (structKeyExists(arguments, "parseError")) { err = arguments.parseError; } try { parser.setErrorHandler(eHandler); parser.setFeature( "http://xml.org/sax/features/validation", true); parser.setFeature( apFeat & "validation/schema", true); parser.setFeature( apFeat & "validation/schema-full-checking", true); if (structKeyExists(arguments, "noNamespaceXsdUri") and arguments.noNamespaceXsdUri neq "") { parser.setProperty( apProp & "schema/external-noNamespaceSchemaLocation", arguments.noNamespaceXsdUri ); } if (structKeyExists(arguments, "namespaceXsdUri") and arguments.namespaceXsdUri neq "") { parser.setProperty( apProp & "schema/external-schemaLocation", arguments.namespaceXsdUri ); } parser.parse(arguments.xmlString); } catch (Any ex) { structAppend(err, ex, true); success = false; } </cfscript> <cfif success EQ True> <cfreturn success> <cfelse> <cfreturn "#err#"> </cfif> </cffunction> </cfcomponent> And my Error is: Web service operation "validateSchema" with parameters {namespaceXsdUri={},xmlString={My_XML_String here },noNamespaceXsdUri={},} could not be found. The error occurred in C:\Inetpub\wwwroot\LRNCHARTS\webTest.cfm: line 53 51 : <cfinvokeargument name="xmlString" value="<graph>bla bla bla bla </graph"/> 52 : <cfinvokeargument name="noNamespaceXsdUri" value=""/> 53 : <cfinvokeargument name="namespaceXsdUri" value=""/>54 : </cfinvoke> 55 : I don't know why I'm getting the error point to the line 53. It does not make any sense. It is suppose to work! If I run my function do validate in CFM page , it works perfectly, but I'm not being able to apply this to a web service. Can you help me? Thanks. Julio. |
|
#4
|
|||
|
|||
|
Please post the code that you are using to invoke the web service.
|
|
#5
|
|||
|
|||
|
Code for invoke
Here is my code:
<html> <body> <cfsavecontent variable="xmlSource" > <graph xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://julioli/lrncharts/chart1.xsd"> <categories> <category name="2001"/> <category name="2002"/> <category name="2003"/> </categories> <dataset seriesname="DIV" color="3f1790" showValue="0" lineThickness="1"> <set value="41.0"/> <set value="46.0"/> <set value="51.0"/> </dataset> </graph> </cfsavecontent> <cfinvoke webservice="http://julioli/lrncharts/schemaValidation.cfc?WSDL" method="validateSchema" returnvariable="result"> <cfinvokeargument name="xmlString" value="#xmlSource#"/> <cfinvokeargument name="noNamespaceXsdUri" value=""/> <cfinvokeargument name="namespaceXsdUri" value=""/> </cfinvoke> <cfdump var="#result#" > </body> </html> |
|
#6
|
|||
|
|||
|
I'd use lower case for the wsdl, even though I don't think it matters. When you go to this URL in your web browser do you see the WSDL output?
http://julioli/lrncharts/schemaValidation.cfc?wsdl |
|
#7
|
|||
|
|||
|
<wsdl:definitions targetNamespace="http://lrncharts" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="http://lrncharts" xmlns:intf="http://lrncharts" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns1="http://rpc.xml.coldfusion" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
- <wsdl:types> - <schema targetNamespace="http://rpc.xml.coldfusion" xmlns="http://www.w3.org/2001/XMLSchema"> <import namespace="http://schemas.xmlsoap.org/soap/encoding/" /> - <complexType name="CFCInvocationException"> <sequence /> </complexType> </schema> etc etc etc.... |
|
#8
|
|||
|
|||
|
Then what is probably happening is that there is an error occuring inside the CFC. Does the EXACT same code also fail when you try to call it as a CFC instead of as a web service? ie change the cfinvoke to call it as a CFC instead of as a web service, but keep everything else (the arguments, etc.) the same ?
|
|
#9
|
|||
|
|||
|
Thanks for the help! I fixed
![]() ![]() But thanks anyway! |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ColdFusion Development > Web Service using JAVA objects - Problem |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|