cancel
Showing results for 
Search instead for 
Did you mean: 

XML parsing using Commons Digester in Netweaver

Former Member
0 Kudos

Hi,

I am trying to parse an XML file using commons-digester and on parsing I get SAPClassNotFoundException for the class file "com.rim.eselling.web.navigation.NavigationRule" that i defined in the mapping-rules.xml for the digester. The test runs fine locally as a java application but throws this exception when running on a web environment??

Any idea why its unable to load the class file "com.rim.eselling.web.navigation.NavigationRule"?

<b>

SAPClassNotFoundException

inNegativeCache= true

</b>

with message saying:

<i>

com.rim.eselling.web.navigation.NavigationRule

Found in negative cache

-


Loader Info -


ClassLoader name: [library:apache.org~jakartaCommon]

Parent loader name: [Frame ClassLoader]

No references !

Resources:

F:\usr\sap\J2E\JC00\j2ee\cluster\server0\bin\ext\apache.org~jakartaCommon\commons-collections-3.1.jar

F:\usr\sap\J2E\JC00\j2ee\cluster\server0\bin\ext\apache.org~jakartaCommon\commons-lang-2.1.jar

F:\usr\sap\J2E\JC00\j2ee\cluster\server0\bin\ext\apache.org~jakartaCommon\commons-beanutils-1.7.0.jar

F:\usr\sap\J2E\JC00\j2ee\cluster\server0\bin\ext\apache.org~jakartaCommon\commons-digester-1.7.jar

F:\usr\sap\J2E\JC00\j2ee\cluster\server0\bin\ext\apache.org~jakartaCommon\commons-discovery-0.2.jar

F:\usr\sap\J2E\JC00\j2ee\cluster\server0\bin\ext\apache.org~jakartaCommon\commons-logging-1.0.4.jar

Loading model: {parent,local,references}

-


</i>

<b>Digester rules file is defined as under:</b>


<digester-rules>
  <pattern value="navigation/navigation-rule">
    <object-create-rule classname="<b>com.rim.eselling.web.navigation.NavigationRule</b>"/>
    <set-next-rule methodname="add" paramtype="java.lang.Object"/>
    <set-properties-rule/>
    <bean-property-setter-rule pattern="logged-in" propertyname="loggedIn"/>
    <bean-property-setter-rule pattern="account-just-created" propertyname="accountJustCreated"/>
    <bean-property-setter-rule pattern="role" propertyname="role"/>
    <bean-property-setter-rule pattern="from-url" propertyname="fromURL"/>
    <bean-property-setter-rule pattern="error" propertyname="error"/>
    <bean-property-setter-rule pattern="nav-code" propertyname="navCode"/>
    <bean-property-setter-rule pattern="user-action" propertyname="userAction"/>
    <bean-property-setter-rule pattern="current-page" propertyname="currentPage"/>
    <bean-property-setter-rule pattern="next-page" propertyname="nextPage"/>
  </pattern>
</digester-rules>

<b>Error causing code:</b>


URL rules = NavigationHandler.class.getResource(MAPPING_RULES_FILE_NAME);
Digester digester = DigesterLoader.createDigester(rules);

// Push empty List onto Digester's Stack
navRules = new ArrayList();
digester.push( navRules );

digester.setValidating(true);

// Parse the XML document
InputStream xmlfile = NavigationHandler.class.getResourceAsStream(XML_FILE_NAME);
navRules = (ArrayList)digester.parse(xmlfile);<b><---------- ERROR</b>

Accepted Solutions (1)

Accepted Solutions (1)

detlev_beutner
Active Contributor
0 Kudos

Hi Faraz,

I don't know the internal classloader use of Digester, but at a first glance, I would interpret the situation as follows:

You have deployed apache.orgjakartaCommon as a central server library. If you call <i>parse</i>, Digester gets called and reads the rules XML which you directly passed over to Digester through <i>createDigester</i>. Now Digester parses the rules and realises to have to look out for the NavigationRule class. And this happens from Digester internally without having gotten some classloader to use; in this case I expect Digester to use it's own classloader as stated in the message: [library:apache.orgjakartaCommon]. From this classloader hierarchy on (means: upwards), your NavigationRule cannot be found.

A short look into the Digester API shows the <i>load</i> methods to which you can pass a classloader. Try to make use of one of these, passing your own application classloader, which also references the NavigationRule class in question. See http://jakarta.apache.org/commons/digester/commons-digester-1.7/docs/api/org/apache/commons/digester... for details.

Alternatively, before calling <i>parse</i> call <i>setClassLoader</i> on the Digester instance itself or call <i>setUseContextClassLoader(true)</i> and just before that, set the context classloader on the thread.

Hope it helps

Detlev

Former Member
0 Kudos

Thanks Detlev, this solved my problem. Your help is much appreciated.

Faraz

Answers (0)