ColdFusion Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreColdFusion Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old August 16th, 2004, 11:06 AM
overcrow overcrow is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 5 overcrow User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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>

Reply With Quote
  #2  
Old August 16th, 2004, 12:51 PM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,648 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 12 h 8 m 20 sec
Reputation Power: 53
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

Reply With Quote
  #3  
Old August 16th, 2004, 02:01 PM
overcrow overcrow is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 5 overcrow User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.

Reply With Quote
  #4  
Old August 16th, 2004, 02:43 PM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,648 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 12 h 8 m 20 sec
Reputation Power: 53
Please post the code that you are using to invoke the web service.

Reply With Quote
  #5  
Old August 16th, 2004, 03:08 PM
overcrow overcrow is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 5 overcrow User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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>

Reply With Quote
  #6  
Old August 16th, 2004, 03:12 PM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,648 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 12 h 8 m 20 sec
Reputation Power: 53
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

Reply With Quote
  #7  
Old August 16th, 2004, 03:22 PM
overcrow overcrow is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 5 overcrow User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
<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....

Reply With Quote
  #8  
Old August 16th, 2004, 03:30 PM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,648 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 12 h 8 m 20 sec
Reputation Power: 53
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 ?

Reply With Quote
  #9  
Old August 16th, 2004, 03:32 PM
overcrow overcrow is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 5 overcrow User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanks for the help! I fixed



But thanks anyway!

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreColdFusion Development > Web Service using JAVA objects - Problem


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway