Skip navigation
Currently Being Moderated

"java.lang.ClassNotFoundException" when creating a CFC instance inside a webservice

Apr 11, 2012 2:29 AM

Tags: #wsdl #component #coldfusion #cfc #webservices

This question is also up on stack overflow: http://stackoverflow.com/questions/10089962/coldfusion-web-service-fai ling-to-see-component

 

I've got a CFC that I'm going to access with ?wsdl as a SOAP webservice.

If I call the CFC directly in a browser, my results render fine:

 

    http://server/webservice/calc.cfc?method=doStuff&foo=bar

 

If I try to access it as a web service:

 

    ws = CreateObject("webservice", 'http://server/webservice/calc.cfc?wsdl');

    result = ws.doStuff('bar');

 

I get an error:

 

Cannot perform web service invocation doStuff.

The fault returned when invoking the web service operation is:
AxisFault
faultCode
: {http://schemas.xmlsoap.org/soap/envelope/}Server.userException
faultSubcode
:
faultString
: coldfusion.xml.rpc.CFCInvocationException:
[coldfusion.xml.rpc.CFCInvocationException : [java.lang.ClassNotFoundException :
com
.calculations.calc][java.lang.NullPointerException : null]]
faultActor
:
faultNode
:
faultDetail
:
   
{http://xml.apache.org/axis/}stackTrace:coldfusion.xml.rpc.CFCInvocationException:          [coldfusion.xml.rpc.CFCInvocationException : [java.lang.ClassNotFoundException :    
com
.calculations.calc][java.lang.NullPointerException : null]]
    at     coldfusion
.xml.rpc.CFComponentSkeleton.__createCFCInvocationException(CFComponentSkeleton.java:733)
    at coldfusion
.xml.rpc.CFComponentSkeleton.__convertOut(CFComponentSkeleton.java:359)
    at webservice
.calc.doStuff(/var/www/vhosts/server/httpdocs/webservice/calc.cfc)
at sun
.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun
.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun
.r... ''

 

The problem is because the doStuff function is declaring an instance of a CFC inside it:

 

remote struct function doStuff(foo) {
 
var objReturn = {};
    objReturn
.msg = 'A message';

   
// do a calculation
   
var objCalc = new com.calculations.calc(foo);
    objReturn
.calc = objCalc;

 
return objReturn;
}

 

So my CFC that I'm using as a webservice has got another CFC being declared inside a function. Browsing directly to my webservice CFC works fine, but trying to call it using the CreateObject/webservice route fails, as it can't create an instance of the **com.calculations.calc** component.

 

It doesn't error, wierdly, if I comment out the objReturn.calc = objCalc line. So it seems I can create the instance, but the error isn't thrown till I assign it to my return struct.

 

Also I've found, If I refresh the page a few times, sometimes the error changes to:

AxisFault
faultCode
: {http://schemas.xmlsoap.org/soap/envelope/}Server.userException
faultSubcode
:
faultString
: coldfusion.xml.rpc.CFCInvocationException:
   
[coldfusion.xml.rpc.CFCInvocationException : [java.lang.ClassNotFoundException :    
    com
.calculations.calc][coldfusion.xml.rpc.CFCInvocationException :
    returnType must     be
defined for remote CFC functions.]]
     faultActor
:
     faultNode
:
     faultDetail
:
   
{http://xml.apache.org/axis/}stackTrace:coldfusion.xml.rpc.CFCInvocationException:
   
[coldfusion.xml.rpc.CFCInvocationException : [java.lang.ClassNotFoundException :
    com
.calculations.calc][coldfusion.xml.rpc.CFCInvocationException :
    returnType must be
defined for remote CFC functions.]]
    at coldfusion
.xml.rpc.CFComponentSkeleton.__createCFCInvocationException(CFComponentSkeleton.java:733)
at coldfusion
.xml.rpc.CFComponentSkeleton.__convertOut(CFComponentSkeleton.java:359)
at webservices
.TaxCalc.feed.getTaxCalc(/var/www/vhosts/server/httpdocs/webservice/calc.cfc)
at sun
.reflect.Nat... ''

 

Message was edited by: PeteComcar - impvoed code formatting and added returntype update

 
Replies
  • Currently Being Moderated
    Apr 11, 2012 4:31 AM   in reply to PeteComcar

    PeteComcar wrote:


    Instead of using this code:

     

    objReturn.calc = objCalc;

     

    I've used this instead:

     

    objReturn.calc.arrOne = objCalc.getArrOne();

    objReturn.calc.arrTwo = objCalc.getArrTwo();

     

    And it's working fine.

    I think ColdFusion is trying to tell you something. The first alternative suggests objCalc is a simple value, array or struct, which you attempt to store in a struct. The second suggests objCalc is an instance of a component.

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 11, 2012 5:07 AM   in reply to PeteComcar

    objCalc is an instance of a component. I've solved it by using accessors to get the data I need instead of returning the instance, whcih just seems wrong now I think about it anyway.

     

    Which version of CF are you running?

     

    --

    Adam

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points