The mapping.xml needs to be in the classpath.

If the mapping file is located at WEB-INF/classes/BalancesMapping.xml then
you can use the
application.getResource("/BalancesMapping.xml")  to load the file.

This can also be put in a jar file under "WEB-INF/lib" and it should be able
to load.

Steve






----- Original Message -----
From: "Tim Holloway" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, December 12, 2002 10:30 PM
Subject: [castor-dev] Mapping for Tomcat in a WAR


> I'm trying to marshal out a collection of JavaBeans to XML using Castor
> from a
> JSP in a WAR being served up from Tomcat.
>
> I tried the easy way out first - just passed the object (a
> java.util.List) to the static marshalling method. This, alas, simply
> results in a NullPointerException when Castor invokes the
> org.apache.xml.serialize.Printer.
>
> After about 3 hours of trying to figure out NullPointerException, I
> set up a mapping, having finally realized that even had the
> serialization not failed, there was no obvious place to name the extra
> XML tags needed to do the job decently. Got that working in a standalone
> app, output XML and was ready for the Big Time - making the XML come out
> from within a JSP.
>
> Now comes the question: How do I get the mapping applied to the
> marshalling process when the mapping is no longer in a discrete file,
> but rather
> in a subfile of a WAR? I did a:
>
> out.println("URL for mapping='" +
> application.getResource("/WEB-INF/BalancesMapping.xml") + "' <br>");
> out.println("Mapping is " + mapping );
>
> and got:
>
> URL for mapping='jndi:/localhost/mywebapp/WEB-INF/BalancesMapping.xml'
> Mapping is org.exolab.castor.mapping.Mapping@fbbbc
>
> Feeding that URL to construct a mapping throws no exceptions, but when I
> apply the mapping to a constructed marshaller, like so:
>
>       Marshaller marshaller = new Marshaller( out );
>       marshaller.setMapping( mapping );
>       marshaller.marshal( list );
>
> I get the same NullPointerException stacktrace as if I had set no
> mapping at all.
>
> Can someone tell me how to do this properly?
>
>   Thanks!
>
>     Tim Holloway
>
> -----------------------------------------------------------
> If you wish to unsubscribe from this mailing, send mail to
> [EMAIL PROTECTED] with a subject of:
> unsubscribe castor-dev
>
>

----------------------------------------------------------- 
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
        unsubscribe castor-dev

Reply via email to