views:

205

answers:

1

I’m new to XMLBeans and have been trying to use it to create an XML document as part of an axis2 web service. When I run my code as a standard Java application or as a standard servlet, the XML is correctly generated:

<?xml version="1.0" encoding="UTF-8"?>
<c:BroadsoftDocument protocol="OCI" xmlns:c="C">
<sessionId>000000001</sessionId>
<command xsi:type="AuthenticationRequest" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;
<userId>admin</userId></command>
</c:BroadsoftDocument>

However, when the exact same code is run under Axis2 & Tomcat in a servlet I get:

<?xml version="1.0" encoding="UTF-8"?>
<c:BroadsoftDocument protocol="OCI" xmlns:c="C">
<sessionId>000000001</sessionId>
<command>
<userId>admin</userId></command>
</c:BroadsoftDocument>

This of course isn’t valid – the xsi:type of the “command” element is stripped when the code is run under Tomcat.

Does anyone have any suggestions of what I could be doing wrong that would cause this type of issue only when running under Axis2? At first I thought it was a Tomcat issue, but after creating a generic servlet and running the exact same code I don't have any issues. I've tried playing with the XMLOptions for XMLBeans, but couldn't seem to resolve the problem. The options I'm currently using are:

xmlOptions = new XmlOptions();
xmlOptions.setCharacterEncoding("UTF-8");
xmlOptions.setUseDefaultNamespace();
xmlOptions.setSaveAggressiveNamespaces();
xmlOptions.setSavePrettyPrint();
A: 

It turn out the issue is with the class loader order that Axis2 uses. This was patched and the functionality is described here:

http://marc2.theaimsgroup.com/?l=axis-cvs&amp;m=115946726426905&amp;w=3

Long story short, to resolve this issue you need to edit the "services.xml" for your Axis2 project and add:

<parameter name="ServiceTCCL">composite</parameter>
Matthew Gamble