I have had no response to the below.
Would you like me to raise a JIRA issue since I don't think castor can be
used as an unmarshaller in web services without given someone the ability to
bring down your service unless you create a new XMLContext for each and
every request.
P
From: Paul French [mailto:[email protected]]
Sent: 29 January 2010 10:18
To: '[email protected]'
Cc: 'Lukas Lang'; 'Ben Hope'
Subject: RE: [castor-user] RE: Very Strange Problem
My problem appears to be this reported issue:
http://jira.springframework.org/browse/SWS-565
To be clear, I am using castor 1.3.1 and java 6
Okay I can reproduce the problem standalone in the program given below. Note
that xml docs unmarshalled fine are no longer unmarshalled successfully once
an incorrect XML doc is provided unless a namespace is also specified which
is not the case in a SOAP request where the namespace is declared in the
SOAP envelope.
Does anyone know if this been raised as a problem in Castor? Take a look at
the output after TEST 4 starts. You can see that the LoginDescriptor gets
loaded again due to an incorrect element being supplied. This is the root of
my problem.
I need a quick and dirty fix. Maybe I can set the namespace explicitly on
the DOM node before it is unmarshalled by Castor?
public class TestCastor
{
/**
* @param args
*/
public static void main(String[] args) throws Exception
{
XMLContext context = new XMLContext();
context.addPackages(new
String[]{"com.kirona.mitie.model.web.server.concept"});
Unmarshaller unMarshaller = context.createUnmarshaller();
LoginRequest loginRequest = null;
try
{
System.out.println("TEST 1 - NO NAMESPACE (WORKS FINE)");
loginRequest = (LoginRequest) unMarshaller.unmarshal(new
StringReader("<LoginRequest>\n"+
"<username>paul</username>\n"+
"<password>password</password>\n"+
"</LoginRequest>"));
System.out.println("TEST 2 - NAMESPACE as specified in XSD (WORKS
FINE)");
loginRequest = (LoginRequest) unMarshaller.unmarshal(new
StringReader("<sch:LoginRequest
xmlns:sch=\"http://kirona.com/2009/12/Concept/schema/\">\n"+
"<sch:username>paul</sch:username>\n"+
"<sch:password>password</sch:password>\n"+
"</sch:LoginRequest>"));
System.out.println("TEST 3 - NO NAMESPACE (STILL WORKS FINE)");
loginRequest = (LoginRequest) unMarshaller.unmarshal(new
StringReader("<LoginRequest>\n"+
"<username>paul</username>\n"+
"<password>password</password>\n"+
"</LoginRequest>"));
System.out.println("TEST 4 - NAMESPACE BUT INCORRECT XML (WILL FAIL) -
but also loads package descriptors again!!!");
loginRequest = (LoginRequest) unMarshaller.unmarshal(new
StringReader("<sch:LoginRequest
xmlns:sch=\"http://kirona.com/2009/12/Concept/schema/\">\n"+
"<sch:usernameWRONG>paul</sch:usernameWRONG>\n"+
"<sch:password>password</sch:password>\n"+
"</sch:LoginRequest>"));
}
catch (Exception e)
{
System.out.println("TEST 4 FAILS AS EXPECTED!");
e.printStackTrace();
}
try
{
System.out.println("TEST 5 - NAMESPACE as specified in XSD (STILL
WORKS FINE) - can find unique descriptor for LoginRequest due to namespace
being specified");
loginRequest = (LoginRequest) unMarshaller.unmarshal(new
StringReader("<sch:LoginRequest
xmlns:sch=\"http://kirona.com/2009/12/Concept/schema/\">\n"+
"<sch:username>paul</sch:username>\n"+
"<sch:password>password</sch:password>\n"+
"</sch:LoginRequest>"));
System.out.println("TEST 6 - NO NAMESPACE (FAILS due to multiple
descriptors loaded for LoginRequest) - cannot find unique descriptor
match");
loginRequest = (LoginRequest) unMarshaller.unmarshal(new
StringReader("<LoginRequest>\n"+
"<username>paul</username>\n"+
"<password>password</password>\n"+
"</LoginRequest>"));
}
catch (Exception e)
{
System.out.println("TEST 6 - BUG! FAILS due to multiple descriptors
loaded for LoginRequest");
e.printStackTrace();
}
}
}
For completeness:
The XSD required to generate the LoginRequest class is:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified"
targetNamespace="http://kirona.com/2009/12/Concept/schema/"
xmlns:schema="http://kirona.com/2009/12/Concept/schema/">
<xs:element name="LoginRequest">
<xs:complexType>
<xs:sequence>
<xs:element name="username" type="xs:string"/>
<xs:element name="password" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Command used to build POJO + descriptors used:
java.exe org.exolab.castor.builder.SourceGeneratorMain -i xsd/<above>.xsd}
-package com.kirona.mitie.model.web.server.concept -dest src -nomarshall -f
-types j2 -generateImportedSchemas true
Output...........
2010-01-29 10:04:13,296 DEBUG [org.castor.core.util.AbstractProperties] -
Properties loaded from classpath: /org/castor/core/castor.core.properties
2010-01-29 10:04:13,312 DEBUG [org.castor.core.util.AbstractProperties] -
Properties loaded from classpath: /org/castor/xml/castor.xml.properties
2010-01-29 10:04:13,312 DEBUG [org.castor.core.util.AbstractProperties] -
Properties loaded from classpath: /castor.properties
2010-01-29 10:04:13,312 DEBUG
[org.exolab.castor.xml.util.XMLClassDescriptorResolverImpl$DescriptorCacheIm
pl] - New instance!
2010-01-29 10:04:13,343 DEBUG
[org.exolab.castor.xml.util.resolvers.CastorXMLStrategy] - Setting property:
org.exolab.castor.xml.util.ResolverStrategy.LoadPackageMappings to value:
true
2010-01-29 10:04:13,343 DEBUG
[org.exolab.castor.xml.util.resolvers.CastorXMLStrategy] - Setting property:
org.exolab.castor.xml.util.ResolverStrategy.useIntrospection to value: true
2010-01-29 10:04:13,343 DEBUG
[org.exolab.castor.xml.util.resolvers.CastorXMLStrategy] - Setting property:
org.exolab.castor.xml.util.ResolverStrategy.MappingLoader to value: null
2010-01-29 10:04:13,343 DEBUG
[org.exolab.castor.xml.util.resolvers.CastorXMLStrategy] - Setting property:
org.exolab.castor.xml.util.ResolverStrategy.Introspector to value:
org.exolab.castor.xml.introspec...@15fea60
2010-01-29 10:04:13,343 DEBUG
[org.exolab.castor.xml.util.resolvers.AbstractResolverPackageCommand] - Now
in resolve method: org.exolab.castor.xml.util.resolvers.ByCDR resolving:
com.kirona.mitie.model.web.server.concept
2010-01-29 10:04:13,343 DEBUG
[org.exolab.castor.xml.util.resolvers.AbstractResolverPackageCommand] - No
domain class loader set, taking it from class.getClassLoader().
2010-01-29 10:04:13,343 DEBUG [org.exolab.castor.xml.util.resolvers.ByCDR] -
Found descriptor: class
com.kirona.mitie.model.web.server.concept.descriptors.LoginRequestDescriptor
2010-01-29 10:04:13,359 DEBUG
[org.exolab.castor.xml.util.XMLClassDescriptorResolverImpl$DescriptorCacheIm
pl] - Adding descriptor class for:
com.kirona.mitie.model.web.server.concept.LoginRequest descriptor:
com.kirona.mitie.model.web.server.concept.descriptors.LoginRequestDescriptor
@53c015; descriptor for class: [null]; xml name: null
2010-01-29 10:04:13,359 DEBUG
[org.exolab.castor.xml.util.resolvers.AbstractResolverPackageCommand] - Now
in resolve method: org.exolab.castor.xml.util.resolvers.ByPackageMapping
resolving: com.kirona.mitie.model.web.server.concept
2010-01-29 10:04:13,359 DEBUG
[org.exolab.castor.xml.util.resolvers.AbstractResolverPackageCommand] - No
domain class loader set, taking it from class.getClassLoader().
2010-01-29 10:04:13,375 DEBUG
[org.exolab.castor.xml.util.XMLClassDescriptorResolverImpl$DescriptorCacheIm
pl] - Called addAllDescriptors with null or empty descriptor map
2010-01-29 10:04:13,375 DEBUG [org.exolab.castor.xml.XMLContext] - Creating
new Unmarshaller instance.
TEST 1 - NO NAMESPACE (WORKS FINE)
2010-01-29 10:04:13,390 DEBUG [org.exolab.castor.xml.util.XMLParserUtils] -
Successfully instantiated
com.sun.org.apache.xerces.internal.parsers.SAXParser
2010-01-29 10:04:13,421 DEBUG
[org.exolab.castor.xml.util.XMLClassDescriptorResolverImpl$DescriptorCacheIm
pl] - Get descriptor for:
com.kirona.mitie.model.web.server.concept.LoginRequest found:
com.kirona.mitie.model.web.server.concept.descriptors.LoginRequestDescriptor
@53c015; descriptor for class: [null]; xml name: null
2010-01-29 10:04:13,421 DEBUG
[org.exolab.castor.xml.util.XMLClassDescriptorResolverImpl$DescriptorCacheIm
pl] - Get descriptor for:
com.kirona.mitie.model.web.server.concept.LoginRequest found:
com.kirona.mitie.model.web.server.concept.descriptors.LoginRequestDescriptor
@53c015; descriptor for class: [null]; xml name: null
TEST 2 - NAMESPACE as specified in XSD (WORKS FINE)
2010-01-29 10:04:13,421 DEBUG [org.exolab.castor.xml.util.XMLParserUtils] -
Successfully instantiated
com.sun.org.apache.xerces.internal.parsers.SAXParser
2010-01-29 10:04:13,437 DEBUG
[org.exolab.castor.xml.util.XMLClassDescriptorResolverImpl$DescriptorCacheIm
pl] - Get descriptor for:
com.kirona.mitie.model.web.server.concept.LoginRequest found:
com.kirona.mitie.model.web.server.concept.descriptors.LoginRequestDescriptor
@53c015; descriptor for class: [null]; xml name: null
2010-01-29 10:04:13,437 DEBUG
[org.exolab.castor.xml.util.XMLClassDescriptorResolverImpl$DescriptorCacheIm
pl] - Get descriptor for:
com.kirona.mitie.model.web.server.concept.LoginRequest found:
com.kirona.mitie.model.web.server.concept.descriptors.LoginRequestDescriptor
@53c015; descriptor for class: [null]; xml name: null
TEST 3 - NO NAMESPACE (STILL WORKS FINE)
2010-01-29 10:04:13,437 DEBUG [org.exolab.castor.xml.util.XMLParserUtils] -
Successfully instantiated
com.sun.org.apache.xerces.internal.parsers.SAXParser
2010-01-29 10:04:13,437 DEBUG
[org.exolab.castor.xml.util.XMLClassDescriptorResolverImpl$DescriptorCacheIm
pl] - Get descriptor for:
com.kirona.mitie.model.web.server.concept.LoginRequest found:
com.kirona.mitie.model.web.server.concept.descriptors.LoginRequestDescriptor
@53c015; descriptor for class: [null]; xml name: null
2010-01-29 10:04:13,437 DEBUG
[org.exolab.castor.xml.util.XMLClassDescriptorResolverImpl$DescriptorCacheIm
pl] - Get descriptor for:
com.kirona.mitie.model.web.server.concept.LoginRequest found:
com.kirona.mitie.model.web.server.concept.descriptors.LoginRequestDescriptor
@53c015; descriptor for class: [null]; xml name: null
TEST 4 - NAMESPACE BUT INCORRECT XML (WILL FAIL) - but also loads package
descriptors again!!!
2010-01-29 10:04:13,437 DEBUG [org.exolab.castor.xml.util.XMLParserUtils] -
Successfully instantiated
com.sun.org.apache.xerces.internal.parsers.SAXParser
2010-01-29 10:04:13,437 DEBUG
[org.exolab.castor.xml.util.XMLClassDescriptorResolverImpl$DescriptorCacheIm
pl] - Get descriptor for:
com.kirona.mitie.model.web.server.concept.UsernameWRONG found: null
2010-01-29 10:04:13,437 DEBUG
[org.exolab.castor.xml.util.resolvers.CastorXMLStrategy] - Setting property:
org.exolab.castor.xml.util.ResolverStrategy.LoadPackageMappings to value:
true
2010-01-29 10:04:13,437 DEBUG
[org.exolab.castor.xml.util.resolvers.CastorXMLStrategy] - Setting property:
org.exolab.castor.xml.util.ResolverStrategy.useIntrospection to value: true
2010-01-29 10:04:13,437 DEBUG
[org.exolab.castor.xml.util.resolvers.CastorXMLStrategy] - Setting property:
org.exolab.castor.xml.util.ResolverStrategy.MappingLoader to value: null
2010-01-29 10:04:13,437 DEBUG
[org.exolab.castor.xml.util.resolvers.CastorXMLStrategy] - Setting property:
org.exolab.castor.xml.util.ResolverStrategy.Introspector to value:
org.exolab.castor.xml.introspec...@15fea60
2010-01-29 10:04:13,437 DEBUG
[org.exolab.castor.xml.util.resolvers.CastorXMLStrategy] - Setting property:
org.exolab.castor.xml.util.ResolverStrategy.ClassLoader to value:
sun.misc.launcher$appclassloa...@11b86e7
2010-01-29 10:04:13,437 DEBUG
[org.exolab.castor.xml.util.resolvers.CastorXMLStrategy] - Setting property:
org.exolab.castor.xml.util.ResolverStrategy.LoadPackageMappings to value:
true
2010-01-29 10:04:13,437 DEBUG
[org.exolab.castor.xml.util.resolvers.CastorXMLStrategy] - Setting property:
org.exolab.castor.xml.util.ResolverStrategy.useIntrospection to value: true
2010-01-29 10:04:13,437 DEBUG
[org.exolab.castor.xml.util.resolvers.CastorXMLStrategy] - Setting property:
org.exolab.castor.xml.util.ResolverStrategy.MappingLoader to value: null
2010-01-29 10:04:13,437 DEBUG
[org.exolab.castor.xml.util.resolvers.CastorXMLStrategy] - Setting property:
org.exolab.castor.xml.util.ResolverStrategy.Introspector to value:
org.exolab.castor.xml.introspec...@15fea60
2010-01-29 10:04:13,437 DEBUG
[org.exolab.castor.xml.util.XMLClassDescriptorResolverImpl$DescriptorCacheIm
pl] - Get descriptor for:
com.kirona.mitie.model.web.server.concept.UsernameWRONG found: null
2010-01-29 10:04:13,437 DEBUG
[org.exolab.castor.xml.util.resolvers.AbstractResolverClassCommand] - Now in
method: org.exolab.castor.xml.util.resolvers.ByMappingLoader resolving:
com.kirona.mitie.model.web.server.concept.UsernameWRONG
2010-01-29 10:04:13,437 DEBUG
[org.exolab.castor.xml.util.resolvers.ByMappingLoader] - No mapping loader
specified
2010-01-29 10:04:13,437 DEBUG
[org.exolab.castor.xml.util.XMLClassDescriptorResolverImpl$DescriptorCacheIm
pl] - Called addAllDescriptors with null or empty descriptor map
2010-01-29 10:04:13,437 DEBUG
[org.exolab.castor.xml.util.XMLClassDescriptorResolverImpl$DescriptorCacheIm
pl] - Get descriptor for:
com.kirona.mitie.model.web.server.concept.UsernameWRONG found: null
2010-01-29 10:04:13,437 DEBUG
[org.exolab.castor.xml.util.resolvers.AbstractResolverPackageCommand] - Now
in resolve method: org.exolab.castor.xml.util.resolvers.ByCDR resolving:
com.kirona.mitie.model.web.server.concept
2010-01-29 10:04:13,437 DEBUG [org.exolab.castor.xml.util.resolvers.ByCDR] -
Found descriptor: class
com.kirona.mitie.model.web.server.concept.descriptors.LoginRequestDescriptor
2010-01-29 10:04:13,437 DEBUG
[org.exolab.castor.xml.util.XMLClassDescriptorResolverImpl$DescriptorCacheIm
pl] - Adding descriptor class for:
com.kirona.mitie.model.web.server.concept.LoginRequest descriptor:
com.kirona.mitie.model.web.server.concept.descriptors.LoginRequestDescriptor
@1cfb549; descriptor for class: [null]; xml name: null
2010-01-29 10:04:13,437 DEBUG
[org.exolab.castor.xml.util.resolvers.AbstractResolverPackageCommand] - Now
in resolve method: org.exolab.castor.xml.util.resolvers.ByPackageMapping
resolving: com.kirona.mitie.model.web.server.concept
2010-01-29 10:04:13,437 DEBUG
[org.exolab.castor.xml.util.XMLClassDescriptorResolverImpl$DescriptorCacheIm
pl] - Called addAllDescriptors with null or empty descriptor map
2010-01-29 10:04:13,437 DEBUG
[org.exolab.castor.xml.util.XMLClassDescriptorResolverImpl$DescriptorCacheIm
pl] - Get descriptor for:
com.kirona.mitie.model.web.server.concept.UsernameWRONG found: null
2010-01-29 10:04:13,437 DEBUG
[org.exolab.castor.xml.util.resolvers.AbstractResolverClassCommand] - Now in
method: org.exolab.castor.xml.util.resolvers.ByDescriptorClass resolving:
com.kirona.mitie.model.web.server.concept.UsernameWRONG
2010-01-29 10:04:13,437 DEBUG
[org.exolab.castor.xml.util.resolvers.ResolveHelpers] - Ignored problem at
loading class:
com.kirona.mitie.model.web.server.concept.UsernameWRONGDescriptor through
class loader: sun.misc.launcher$appclassloa...@11b86e7, exception:
java.lang.ClassNotFoundException:
com.kirona.mitie.model.web.server.concept.UsernameWRONGDescriptor
2010-01-29 10:04:13,437 DEBUG
[org.exolab.castor.xml.util.resolvers.ResolveHelpers] - Ignored problem at
loading class:
com.kirona.mitie.model.web.server.concept.descriptors.UsernameWRONGDescripto
r through class loader: sun.misc.launcher$appclassloa...@11b86e7, exception:
java.lang.ClassNotFoundException:
com.kirona.mitie.model.web.server.concept.descriptors.UsernameWRONGDescripto
r
2010-01-29 10:04:13,437 DEBUG
[org.exolab.castor.xml.util.XMLClassDescriptorResolverImpl$DescriptorCacheIm
pl] - Called addAllDescriptors with null or empty descriptor map
2010-01-29 10:04:13,437 DEBUG
[org.exolab.castor.xml.util.XMLClassDescriptorResolverImpl$DescriptorCacheIm
pl] - Get descriptor for:
com.kirona.mitie.model.web.server.concept.UsernameWRONG found: null
2010-01-29 10:04:13,437 DEBUG
[org.exolab.castor.xml.util.resolvers.AbstractResolverClassCommand] - Now in
method: org.exolab.castor.xml.util.resolvers.ByIntrospection resolving:
com.kirona.mitie.model.web.server.concept.UsernameWRONG
2010-01-29 10:04:13,437 DEBUG
[org.exolab.castor.xml.util.resolvers.ResolveHelpers] - Ignored problem at
loading class: com.kirona.mitie.model.web.server.concept.UsernameWRONG
through class loader: sun.misc.launcher$appclassloa...@11b86e7, exception:
java.lang.ClassNotFoundException:
com.kirona.mitie.model.web.server.concept.UsernameWRONG
2010-01-29 10:04:13,437 DEBUG
[org.exolab.castor.xml.util.XMLClassDescriptorResolverImpl$DescriptorCacheIm
pl] - Called addAllDescriptors with null or empty descriptor map
2010-01-29 10:04:13,437 DEBUG
[org.exolab.castor.xml.util.XMLClassDescriptorResolverImpl$DescriptorCacheIm
pl] - Get descriptor for:
com.kirona.mitie.model.web.server.concept.UsernameWRONG found: null
2010-01-29 10:04:13,437 DEBUG
[org.exolab.castor.xml.util.XMLClassDescriptorResolverImpl$DescriptorCacheIm
pl] - Adding class name to missing classes:
com.kirona.mitie.model.web.server.concept.UsernameWRONG
2010-01-29 10:04:13,437 DEBUG [org.exolab.castor.xml.UnmarshalHandler] -
unable to find FieldDescriptor for 'usernameWRONG' in ClassDescriptor of
LoginRequest - ignoring extra element.
TEST 4 FAILS AS EXPECTED!
org.exolab.castor.xml.MarshalException: Element with name password passed to
type LoginRequest in incorrect order; expected element with name 'username'
or any other optional element declared prior to it.{File: [not available];
line: 3; column: 15}
at
org.exolab.castor.xml.Unmarshaller.convertSAXExceptionToMarshalException(Unm
arshaller.java:794)
at org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:760)
at org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:626)
at test.castor.TestCastor.main(TestCastor.java:47)
Caused by: ValidationException: Element with name password passed to type
LoginRequest in incorrect order; expected element with name 'username' or
any other optional element declared prior to it.
at
org.exolab.castor.xml.util.XMLClassDescriptorImpl.checkDescriptorForCorrectO
rderWithinSequence(XMLClassDescriptorImpl.java:349)
at
org.exolab.castor.xml.UnmarshalHandler.startElement(UnmarshalHandler.java:19
59)
at
org.exolab.castor.xml.UnmarshalHandler.startElement(UnmarshalHandler.java:14
36)
at
com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(Ab
stractSAXParser.java:501)
at
com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartEl
ement(XMLNSDocumentScannerImpl.java:400)
at
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$Fragm
entContentDriver.next(XMLDocumentFragmentScannerImpl.java:2747)
at
com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocum
entScannerImpl.java:648)
at
com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSD
ocumentScannerImpl.java:140)
at
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanD
ocument(XMLDocumentFragmentScannerImpl.java:510)
at
com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Con
figuration.java:807)
at
com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Con
figuration.java:737)
at
com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:10
7)
at
com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractS
AXParser.java:1205)
at org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:748)
... 2 more
TEST 5 - NAMESPACE as specified in XSD (STILL WORKS FINE) - can find unique
descriptor for LoginRequest due to namespace being specified
2010-01-29 10:04:13,453 DEBUG [org.exolab.castor.xml.util.XMLParserUtils] -
Successfully instantiated
com.sun.org.apache.xerces.internal.parsers.SAXParser
2010-01-29 10:04:13,453 DEBUG
[org.exolab.castor.xml.util.XMLClassDescriptorResolverImpl$DescriptorCacheIm
pl] - Get descriptor for:
com.kirona.mitie.model.web.server.concept.LoginRequest found:
com.kirona.mitie.model.web.server.concept.descriptors.LoginRequestDescriptor
@1cfb549; descriptor for class: [null]; xml name: null
2010-01-29 10:04:13,453 DEBUG
[org.exolab.castor.xml.util.XMLClassDescriptorResolverImpl$DescriptorCacheIm
pl] - Get descriptor for:
com.kirona.mitie.model.web.server.concept.LoginRequest found:
com.kirona.mitie.model.web.server.concept.descriptors.LoginRequestDescriptor
@1cfb549; descriptor for class: [null]; xml name: null
TEST 6 - NO NAMESPACE (FAILS due to multiple descriptors loaded for
LoginRequest) - cannot find unique descriptor match
2010-01-29 10:04:13,453 DEBUG [org.exolab.castor.xml.util.XMLParserUtils] -
Successfully instantiated
com.sun.org.apache.xerces.internal.parsers.SAXParser
2010-01-29 10:04:13,453 DEBUG
[org.exolab.castor.xml.util.XMLClassDescriptorResolverImpl$DescriptorCacheIm
pl] - Get descriptor for: LoginRequest found: null
2010-01-29 10:04:13,453 DEBUG
[org.exolab.castor.xml.util.resolvers.CastorXMLStrategy] - Setting property:
org.exolab.castor.xml.util.ResolverStrategy.LoadPackageMappings to value:
true
2010-01-29 10:04:13,453 DEBUG
[org.exolab.castor.xml.util.resolvers.CastorXMLStrategy] - Setting property:
org.exolab.castor.xml.util.ResolverStrategy.useIntrospection to value: true
2010-01-29 10:04:13,453 DEBUG
[org.exolab.castor.xml.util.resolvers.CastorXMLStrategy] - Setting property:
org.exolab.castor.xml.util.ResolverStrategy.MappingLoader to value: null
2010-01-29 10:04:13,453 DEBUG
[org.exolab.castor.xml.util.resolvers.CastorXMLStrategy] - Setting property:
org.exolab.castor.xml.util.ResolverStrategy.Introspector to value:
org.exolab.castor.xml.introspec...@15fea60
2010-01-29 10:04:13,453 DEBUG
[org.exolab.castor.xml.util.resolvers.CastorXMLStrategy] - Setting property:
org.exolab.castor.xml.util.ResolverStrategy.ClassLoader to value:
sun.misc.launcher$appclassloa...@11b86e7
2010-01-29 10:04:13,453 DEBUG
[org.exolab.castor.xml.util.resolvers.CastorXMLStrategy] - Setting property:
org.exolab.castor.xml.util.ResolverStrategy.LoadPackageMappings to value:
true
2010-01-29 10:04:13,453 DEBUG
[org.exolab.castor.xml.util.resolvers.CastorXMLStrategy] - Setting property:
org.exolab.castor.xml.util.ResolverStrategy.useIntrospection to value: true
2010-01-29 10:04:13,453 DEBUG
[org.exolab.castor.xml.util.resolvers.CastorXMLStrategy] - Setting property:
org.exolab.castor.xml.util.ResolverStrategy.MappingLoader to value: null
2010-01-29 10:04:13,453 DEBUG
[org.exolab.castor.xml.util.resolvers.CastorXMLStrategy] - Setting property:
org.exolab.castor.xml.util.ResolverStrategy.Introspector to value:
org.exolab.castor.xml.introspec...@15fea60
2010-01-29 10:04:13,453 DEBUG
[org.exolab.castor.xml.util.XMLClassDescriptorResolverImpl$DescriptorCacheIm
pl] - Get descriptor for: LoginRequest found: null
2010-01-29 10:04:13,453 DEBUG
[org.exolab.castor.xml.util.resolvers.AbstractResolverClassCommand] - Now in
method: org.exolab.castor.xml.util.resolvers.ByMappingLoader resolving:
LoginRequest
2010-01-29 10:04:13,453 DEBUG
[org.exolab.castor.xml.util.resolvers.ByMappingLoader] - No mapping loader
specified
2010-01-29 10:04:13,453 DEBUG
[org.exolab.castor.xml.util.XMLClassDescriptorResolverImpl$DescriptorCacheIm
pl] - Called addAllDescriptors with null or empty descriptor map
2010-01-29 10:04:13,453 DEBUG
[org.exolab.castor.xml.util.XMLClassDescriptorResolverImpl$DescriptorCacheIm
pl] - Get descriptor for: LoginRequest found: null
2010-01-29 10:04:13,453 DEBUG
[org.exolab.castor.xml.util.resolvers.AbstractResolverPackageCommand] -
Package name is empty! Anyhow, giving it a try...
2010-01-29 10:04:13,453 DEBUG
[org.exolab.castor.xml.util.resolvers.AbstractResolverPackageCommand] - Now
in resolve method: org.exolab.castor.xml.util.resolvers.ByCDR resolving:
2010-01-29 10:04:13,453 DEBUG
[org.exolab.castor.xml.util.XMLClassDescriptorResolverImpl$DescriptorCacheIm
pl] - Called addAllDescriptors with null or empty descriptor map
2010-01-29 10:04:13,453 DEBUG
[org.exolab.castor.xml.util.resolvers.AbstractResolverPackageCommand] -
Package name is empty! Anyhow, giving it a try...
2010-01-29 10:04:13,453 DEBUG
[org.exolab.castor.xml.util.resolvers.AbstractResolverPackageCommand] - Now
in resolve method: org.exolab.castor.xml.util.resolvers.ByPackageMapping
resolving:
2010-01-29 10:04:13,453 DEBUG
[org.exolab.castor.xml.util.XMLClassDescriptorResolverImpl$DescriptorCacheIm
pl] - Called addAllDescriptors with null or empty descriptor map
2010-01-29 10:04:13,453 DEBUG
[org.exolab.castor.xml.util.XMLClassDescriptorResolverImpl$DescriptorCacheIm
pl] - Get descriptor for: LoginRequest found: null
2010-01-29 10:04:13,453 DEBUG
[org.exolab.castor.xml.util.resolvers.AbstractResolverClassCommand] - Now in
method: org.exolab.castor.xml.util.resolvers.ByDescriptorClass resolving:
LoginRequest
2010-01-29 10:04:13,453 DEBUG
[org.exolab.castor.xml.util.resolvers.ResolveHelpers] - Ignored problem at
loading class: LoginRequestDescriptor through class loader:
sun.misc.launcher$appclassloa...@11b86e7, exception:
java.lang.ClassNotFoundException: LoginRequestDescriptor
2010-01-29 10:04:13,453 DEBUG
[org.exolab.castor.xml.util.XMLClassDescriptorResolverImpl$DescriptorCacheIm
pl] - Called addAllDescriptors with null or empty descriptor map
2010-01-29 10:04:13,453 DEBUG
[org.exolab.castor.xml.util.XMLClassDescriptorResolverImpl$DescriptorCacheIm
pl] - Get descriptor for: LoginRequest found: null
2010-01-29 10:04:13,453 DEBUG
[org.exolab.castor.xml.util.resolvers.AbstractResolverClassCommand] - Now in
method: org.exolab.castor.xml.util.resolvers.ByIntrospection resolving:
LoginRequest
2010-01-29 10:04:13,468 DEBUG
[org.exolab.castor.xml.util.resolvers.ResolveHelpers] - Ignored problem at
loading class: LoginRequest through class loader:
sun.misc.launcher$appclassloa...@11b86e7, exception:
java.lang.ClassNotFoundException: LoginRequest
2010-01-29 10:04:13,468 DEBUG
[org.exolab.castor.xml.util.XMLClassDescriptorResolverImpl$DescriptorCacheIm
pl] - Called addAllDescriptors with null or empty descriptor map
2010-01-29 10:04:13,468 DEBUG
[org.exolab.castor.xml.util.XMLClassDescriptorResolverImpl$DescriptorCacheIm
pl] - Get descriptor for: LoginRequest found: null
2010-01-29 10:04:13,468 DEBUG
[org.exolab.castor.xml.util.XMLClassDescriptorResolverImpl$DescriptorCacheIm
pl] - Adding class name to missing classes: LoginRequest
2010-01-29 10:04:13,468 DEBUG [org.exolab.castor.xml.UnmarshalHandler] -
unable to find or create a ClassDescriptor for class: LoginRequest
TEST 6 - BUG! FAILS due to multiple descriptors loaded for LoginRequest
org.exolab.castor.xml.MarshalException: The class for the root element
'LoginRequest' could not be found.{File: [not available]; line: 1; column:
15}
at
org.exolab.castor.xml.Unmarshaller.convertSAXExceptionToMarshalException(Unm
arshaller.java:794)
at org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:760)
at org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:626)
at test.castor.TestCastor.main(TestCastor.java:65)
Caused by: org.xml.sax.SAXException: The class for the root element
'LoginRequest' could not be found.
at
org.exolab.castor.xml.UnmarshalHandler.startElement(UnmarshalHandler.java:16
07)
at
org.exolab.castor.xml.UnmarshalHandler.startElement(UnmarshalHandler.java:14
36)
at
com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(Ab
stractSAXParser.java:501)
at
com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartEl
ement(XMLNSDocumentScannerImpl.java:400)
at
com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl$NSContentDr
iver.scanRootElementHook(XMLNSDocumentScannerImpl.java:626)
at
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$Fragm
entContentDriver.next(XMLDocumentFragmentScannerImpl.java:3095)
at
com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.
next(XMLDocumentScannerImpl.java:922)
at
com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocum
entScannerImpl.java:648)
at
com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSD
ocumentScannerImpl.java:140)
at
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanD
ocument(XMLDocumentFragmentScannerImpl.java:510)
at
com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Con
figuration.java:807)
at
com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Con
figuration.java:737)
at
com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:10
7)
at
com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractS
AXParser.java:1205)
at org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:748)
... 2 more
Thanks
Paul
-----Original Message-----
From: Paul French [mailto:[email protected]]
Sent: 28 January 2010 22:41
To: [email protected]
Cc: 'Lukas Lang'
Subject: RE: [castor-user] RE: Very Strange Problem
Okay dokey,
I used the latest Spring 3.0 code with Spring WS 1.5.8 (just
spring-ws-core-1.5.8.jar and spring-xml-1.5.8.jar) and I get the same
problem as before.
I used the latest CastorMarshaller where you can use the targetPackages
property to set the packages that have descriptors for them.
I think it is a Castor bug.
More help would be really appreciated.
Thanks
Paul
-----Original Message-----
From: Paul French [mailto:[email protected]]
Sent: 28 January 2010 21:47
To: [email protected]
Cc: 'Lukas Lang'
Subject: RE: [castor-user] RE: Very Strange Problem
Thanks Lukas and Werner for your input.
Do you agree there is a bug in Castor? Why would it reload all package
descriptors for a package when an element is not found specified in the SOAP
request? If this did not happen everything would be fine for me!!
Any chance you have a reference to the fix in Spring 3.0 so I could have a
quick read. I am not clear on where the problem is?
I'll download Spring 3.0 in the meantime and take a look at the new and
improved Castor Marshaller.
Many thanks,
Paul
-----Original Message-----
From: Werner Guttmann [mailto:[email protected]]
Sent: 28 January 2010 20:53
To: [email protected]
Cc: Lukas Lang
Subject: Re: [castor-user] RE: Very Strange Problem
Hi Paul, Hi Lukas,
on top of what Lukas just said, let me just add that this has been
reported with the Spring folks, and a patch has been committed to the
Spring 3.0 code base where the Spring OXM code has been moved to. In
other words, within Spring 3.0 and its (new) Spring OXM package, the
CastorMarshaller should now be sophisticated enough.
Having said that, a few of us are currently investigating whether the
new Spring OXM (as part of Spring 3.0) can be used with spring-ws in its
1.5.x incarnations.
I hope this adds a bit more light to what's going on in this context.
Regards
Werner
On 28.01.2010 21:02, Lukas Lang wrote:
Hello Paul,
unfortunately, Spring WS does not provide sophisticated configuration and
customization methods of the integrated Castor marshaller/unmarshaller, to
be more specific: a setter for the XMLContext. We have experienced this
issue in a professional environment several times and I recommend proceeding
as follows
1. extend Spring's CastorMarshaller
2. hook your Castor configuration into the lifecycle
You can find a small example attached.
To deal with your second problem, I'd recommend generating all types using
Castor (e.g. the Castor Maven plugin[1]) from a separated XML schema (have a
look at the Spring WS documentation for automatically creating a WSDL in
case you aren't familiar). Don't forget to map XML namespaces to packages
properly as specified in [2] before code generation. Class descriptors
should then be aware of the proper namespaces.
Hope that helps.
Regards,
Lukas
PS: It would be awesome if you would provide us or the Spring team with a
patch!
[1] http://mojo.codehaus.org/castor-maven-plugin/
[2]
http://www.castor.org/srcgen-properties.html#Mapping-XML-namespaces-to-Java-
packages
--------------
public class WsCastorMarshaller extends CastorMarshaller {
private String[] packages = {};
private Log log = LogFactory.getLog(WsCastorMarshaller.class);
@Override
protected void customizeMarshaller(Marshaller marshaller) {
XMLClassDescriptorResolver resolver = configureResolver();
marshaller.setResolver(resolver);
}
@Override
protected void customizeUnmarshaller(Unmarshaller unmarshaller) {
XMLClassDescriptorResolver resolver = configureResolver();
unmarshaller.setResolver(resolver);
}
private XMLClassDescriptorResolver configureResolver() {
XMLClassDescriptorResolver resolver = (XMLClassDescriptorResolver)
ClassDescriptorResolverFactory
.createClassDescriptorResolver(BindingType.XML);
Introspector introspector = new Introspector();
introspector.setInternalContext(marshaller.getInternalContext());
resolver.setIntrospector(introspector);
try {
resolver.addPackages(this.packages);
} catch (ResolverException e) {
log.error("Error while customizing Castor
marshaller/unmarshaller.", e);
}
return resolver;
}
public void setPackages(String[] packages) {
this.packages = packages;
}
}
--------------
Am 28.01.2010 um 20:11 schrieb Paul French:
Hello,
Okay made some progress for the below.
I've written a simple main method to test Castor in isolation and even
though it works there looks like a bug to me which obviously causes a
problem when passing a fragment of XML to Castor to unmarshall.
The test program is shown below.
What happens is when the<usernameWRONG> element is processed castor
cannot find a descriptor for it. However before the tag<usernameWRONG>
castor has found the descriptor for<LoginRequest> as you would expect. What
I don't expect is that when Castor fails to find a descriptor for
usernameWRONG it adds all the descriptors it found for the package where the
LoginRequest lives all over again. So you end up with the same descriptor
twice for some classes in the descriptor cache.
Hence on subsequent calls with a valid XML doc when
XMLClassDescriptorResolverImpl.resolveByXMLName(final String xmlName, final
String namespaceURI, finalClassLoader loader) is called it finds 2 possible
matches for a descriptor. In the standalone program it manages to resolve to
one of these since the namespace is set explicitly. When used from within
Spring Web Services it cannot resolve a descriptor from the 2 possible
matches since I assume the namespace is not set explicitly in the XML doc
since the namespace declaration is defined in SOAP header.
Any ideas how to progress this? Someone can bring the whole web service
down by simply sending a slightly incorrect SOAP request.
Thanks
Paul
public static void main(String[] args) throws Exception
{
XMLContext context = new XMLContext();
context.addPackages(new
String[]{"com.kirona.mitie.model.web.server.concept","com.kirona.mitie.model
.web.server.concept.types"});
Unmarshaller unMarshaller = context.createUnmarshaller();
try
{
System.out.println("TEST 1 - this will fail due to incorrect XML
tag usernameWRONG");
LoginRequest loginRequest = (LoginRequest)
unMarshaller.unmarshal(new StringReader("<sch:LoginRequest
xmlns:sch=\"http://kirona.com/2009/12/Concept/schema/\">\n"+
"<sch:usernameWRONG>paul</sch:usernameWRONG>\n"+
"<sch:password>password</sch:password>\n"+
"</sch:LoginRequest>"));
System.out.println("TEST 1 OK");
}
catch (Exception e)
{
e.printStackTrace();
}
System.out.println("\n\n****************************************************
*************\n\n");
try
{
System.out.println("TEST 2");
LoginRequest loginRequest = (LoginRequest)
unMarshaller.unmarshal(new StringReader("<sch:LoginRequest
xmlns:sch=\"http://kirona.com/2009/12/Concept/schema/\">\n"+
"<sch:username>paul</sch:username>\n"+
"<sch:password>arsenal</sch:password>\n"+
"</sch:LoginRequest>"));
System.out.println("TEST 2 OK");
}
catch (Exception e)
{
e.printStackTrace();
}
System.out.println("\n\n****************************************************
*************\n\n");
}
From: Paul French [mailto:[email protected]]
Sent: 28 January 2010 13:11
To: '[email protected]'
Subject: Very Strange Problem
Hello, we use Spring-WS and castor 1.3.1 for unmarshalling and
marshalling. Spring-WS provides a class CastorMarshaller to handle the
unmarshalling and marshalling for you. We have had to override one method in
this class since it does not support adding descriptors to the XMLContext.
So we have a bunch of model objects (as well as the .castor.cdr files)
and a bunch of descriptors which are registered with the XMLContext using
the addPackage(packageDescriptor) method
When we make a call like:
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:sch="http://kirona.com/2009/12/Concept/schema/">
<soapenv:Header/>
<soapenv:Body>
<sch:LoginRequest>
<sch:username>username</sch:username>
<sch:password>password</sch:password>
</sch:LoginRequest>
</soapenv:Body>
</soapenv:Envelope>
.the request is marshalled fine.
If we then make a mistake in the SOAP request e.g.
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:sch="http://kirona.com/2009/12/Concept/schema/">
<soapenv:Header/>
<soapenv:Body>
<sch:LoginRequest>
<sch:usernameWRONG>xxxx</sch:usernameWRONG>
<sch:password>xxxxxx</sch:password>
</sch:LoginRequest>
</soapenv:Body>
</soapenv:Envelope>
.we get the error (in the SOAP fault respone)
"Castor unmarshalling exception: unable to find FieldDescriptor for
'usernameWRONG' in ClassDescriptor of LoginRequest; nested exception is
org.exolab.castor.xml.MarshalException: unable to find FieldDescriptor for
'usernameWRONG' in ClassDescriptor of LoginRequest"
.which makes sense. However if I repeat the incorrect SOAP request I
get......
"Castor unmarshalling exception: The class for the root element
'LoginRequest' could not be found.; nested exception is
org.exolab.castor.xml.MarshalException: The class for the root element
'LoginRequest' could not be found."
..it seems to no longer know what the element LoginRequest is anymore??
If I correct the SOAP request it still does not work, I still get the
previous error.
I can get things to work again by re-structuring the SOAP request as
follows (by moving the namespace declaration):
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header/>
<soapenv:Body>
<sch:LoginRequest
xmlns:sch="http://kirona.com/2009/12/Concept/schema/">
<sch:username>username</sch:username>
<sch:password>password</sch:password>
</sch:LoginRequest>
</soapenv:Body>
</soapenv:Envelope>
.and from this point onwards this is the only way it will work.
I know this is a bit SOAP related but it is the marshalling layer that is
failing. Any ideas?
P
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email
__________ NOD32 4815 (20100128) Information __________
This message was checked by NOD32 antivirus system.
http://www.eset.com
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email
__________ NOD32 4815 (20100128) Information __________
This message was checked by NOD32 antivirus system.
http://www.eset.com
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email
__________ NOD32 4817 (20100129) Information __________
This message was checked by NOD32 antivirus system.
http://www.eset.com