Location
Dave
::
Blog
Home
Amphlett Links
Dave
Debra
Joseph
Eric
Judy
Genealogy
Submit a Link
Twitter
follow damphlett at http://twitter.com
Archive
Archive
<
August 2010
>
Sun
Mon
Tue
Wed
Thu
Fri
Sat
25
26
27
28
29
30
31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
1
2
3
4
Monthly
October, 2009
May, 2009
November, 2008
October, 2008
September, 2008
June, 2008
April, 2008
March, 2008
February, 2008
June, 2007
March, 2007
February, 2007
January, 2007
December, 2006
October, 2006
July 31, 2010
Register
|
Login
Tomcat and Castor for returning XML from java servlets
Location:
Blogs
Dave Amphlett's Personal Blog
Software Development
Posted by:
Dave Amphlett
Wednesday, June 04, 2008
I've been working on exposing one of my client's existing Java and C# API's via various 'web services'. The combination of Tomcat and Castor has a niggly issue that google didn't provide an instant answer for...
I hit a knarly problem in using Castor to return the XML dump of an object. I just keep getting empty results, and on inspecting the castor debugging log stuff in detail I can't get much sense out of it. googling and even stepping through the castor code which is quite laborious to do still didn't yield any useful insights in a reasonable amount of time. Finally after some early morning 'deep' googling and doggedly trying many many many combinations I finally established the fundamental problem:
By default, within Tomcat, Castor can't "see" the classes deployed under the WEB-INF directory. Not even the class making the call to castor! A class def not found exception would have helped diagnose this, but it was being caught and rethrown as something different :|
So here's an order of calling the Marshaller that I've found that DOES work...
import
org.exolab.castor.xml.Marshaller;
Marshaller marshaller =
new
Marshaller(pw);
marshaller.setValidation(
false
);
marshaller.setSuppressNamespaces(
true
);
marshaller.setRootElement(
"results"
);
marshaller.getResolver().setClassLoader(Thread.currentThread().getContextClassLoader());
marshaller.marshal(oArray);
The setClassLoader line is the magic. Now if only I could get the mapping functionality to work I'd be really happy - I'll keep working on that for now!
Permalink
|
Trackback
Comments (0)
Add Comment
Your name:
Title:
Comment:
Add Comment
Cancel
Copyright 2006-2010 David Amphlett
Amphlett.Net
|
Terms Of Use
|
Privacy Statement