XFire

Namespace prefix required on inbound complex type

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Won't Fix
  • Affects Version/s: 1.1
  • Fix Version/s: 1.2
  • Component/s: None
  • Labels:
    None
  • Environment:
    Mac OS X Intel 10.4.7, Apache Tomcat 5.5.17, Java 1.5.0_06
  • Number of attachments :
    2

Description

I have a method that takes a complex type as a parameter. If I try to test it by creating a raw SOAP message and posting it (instead of using a generated Java proxy class), I have to repeat the namespace, and use a prefix, on the complex type. For example:

<?xml version='1.0' encoding='UTF-8'?>
<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>
<soap:Body>
<createObject xmlns='http://www.soasta.com/services/repository'>
<rp:oObject xmlns:rp='http://www.soasta.com/services/repository' rp:name="sub" rp:path="/" rp:type="folder" >
<rp:Body>foo</rp:Body>
</rp:oObject>
</createObject>
</soap:Body>
</soap:Envelope>

Notice that the <oObject> element simply reproduces the namespace on the parent <createObject> element, and adds a prefix.

If I leave the namespace out on the <oObject> element, or if I try to repeat it as a default namespace instead of using the "rp" prefix, then the type is not marshaled correctly and I get a null body on the server side.

Lest you think that it is because "Body" is already a SOAP element, I tried with others too and same problem

Activity

Hide
Matt Solnit added a comment -

Attaching the Aegis mapping file for the complex type.

Show
Matt Solnit added a comment - Attaching the Aegis mapping file for the complex type.
Hide
Dan Diephouse added a comment -

I'm kinda surprised that this can happen. I'll have to do some digging. Any chance you have the stax-dev-1.1.x jar on your classpath?

Show
Dan Diephouse added a comment - I'm kinda surprised that this can happen. I'll have to do some digging. Any chance you have the stax-dev-1.1.x jar on your classpath?
Hide
Matt Solnit added a comment -

Hi Dan. Thanks for your response. My current classpath is stax-api-1.0.1.jar and wstx-2.0.6.jar. I also tried with Woodstox 2.9.3 instead of 2.0.6, but the behavior was the same.

Would it help if I provide a complete sample?

Show
Matt Solnit added a comment - Hi Dan. Thanks for your response. My current classpath is stax-api-1.0.1.jar and wstx-2.0.6.jar. I also tried with Woodstox 2.9.3 instead of 2.0.6, but the behavior was the same. Would it help if I provide a complete sample?
Hide
Dan Diephouse added a comment -

Hi Matt, Sorry for the long delay.... A complete sample would definitely help

Show
Dan Diephouse added a comment - Hi Matt, Sorry for the long delay.... A complete sample would definitely help
Hide
Matt Solnit added a comment -

A modified version of the XFire BookService example that demonstrates the problem. Includes an HTML UI for testing.

Show
Matt Solnit added a comment - A modified version of the XFire BookService example that demonstrates the problem. Includes an HTML UI for testing.
Hide
Dan Diephouse added a comment -

Thanks, looking into this now.

Show
Dan Diephouse added a comment - Thanks, looking into this now.
Hide
Matt Solnit added a comment -

I was writing some more information, but looks like you beat me to it . I'll post anyway:

The attached sample is basically a small mod of xfire/examples/book. The changes are:

  • BookService.java includes a new method that tests the contents of a Book passed as an input parameter.
  • TestBookService.html is an HTML UI for testing various SOAP inputs to the service.
  • Book.aegis.xml has been added.

The reason that I added the Aegis file is to control the namespace that Book appears in. If I exclude the mapping file, then the problem does not occur, but Book is not in the same namespace as the actual service.

To reproduce the problem, browse to TestBookService.html and try the following SOAP:

<?xml version='1.0' encoding='UTF-8'?>
<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>
<soap:Body>
<putBook>
<book xmlns='http://demo.xfire.codehaus.org'><author>Dan</author><isbn>123</isbn><title>foo</title></book>
</putBook>
</soap:Body>
</soap:Envelope>

You should get an error that the author is missing.

Show
Matt Solnit added a comment - I was writing some more information, but looks like you beat me to it . I'll post anyway: The attached sample is basically a small mod of xfire/examples/book. The changes are:
  • BookService.java includes a new method that tests the contents of a Book passed as an input parameter.
  • TestBookService.html is an HTML UI for testing various SOAP inputs to the service.
  • Book.aegis.xml has been added.
The reason that I added the Aegis file is to control the namespace that Book appears in. If I exclude the mapping file, then the problem does not occur, but Book is not in the same namespace as the actual service. To reproduce the problem, browse to TestBookService.html and try the following SOAP: <?xml version='1.0' encoding='UTF-8'?> <soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'> <soap:Body> <putBook> <book xmlns='http://demo.xfire.codehaus.org'><author>Dan</author><isbn>123</isbn><title>foo</title></book> </putBook> </soap:Body> </soap:Envelope> You should get an error that the author is missing.
Hide
Dan Diephouse added a comment -

I'm looking at your example. Your namespaces don't match - in the aegis.xml file you say the namespace is "http://xfire.codehaus.org/BookService", but in your example message its "http://demo.xfire.codehaus.org". Also, your putBook element doesn't have a namespace and it should be "http://xfire.codehaus.org/BookService".

Show
Dan Diephouse added a comment - I'm looking at your example. Your namespaces don't match - in the aegis.xml file you say the namespace is "http://xfire.codehaus.org/BookService", but in your example message its "http://demo.xfire.codehaus.org". Also, your putBook element doesn't have a namespace and it should be "http://xfire.codehaus.org/BookService".
Hide
Matt Solnit added a comment -

Arg, could I have confused myself while creating this sample? It's the classic problem of "can't share my corporate code, and of course the little sample works just fine". I'll try again . Thanks for bearing with me so far.

Show
Matt Solnit added a comment - Arg, could I have confused myself while creating this sample? It's the classic problem of "can't share my corporate code, and of course the little sample works just fine". I'll try again . Thanks for bearing with me so far.
Hide
Matt Solnit added a comment -

OK, I think I know what's going on. I appreciate your help and I apologize for leading you in the wrong direction before.

The problem, as far as I can tell, only shows up when using attributes. So if you put the following in the Aegis file:
<property name="author" style="attribute" />

and use the following SOAP message:

<?xml version='1.0' encoding='UTF-8'?>
<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>
<soap:Body>
<putBook xmlns='http://xfire.codehaus.org/BookService'>
<book xmlns='http://xfire.codehaus.org/BookService' author='Dan'><isbn>123</isbn><title>foo</title></book>
</putBook>
</soap:Body>
</soap:Envelope>

then you get the error. However, if you prefix-qualify the namespace, as shown below:

<?xml version='1.0' encoding='UTF-8'?>
<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>
<soap:Body>
<putBook>
<b:book xmlns:b='http://xfire.codehaus.org/BookService' b:author='bob'><b:isbn>123</b:isbn><b:title>foo</b:title></b:book>
</putBook>
</soap:Body>
</soap:Envelope>

then it works. I hope this helps.

Show
Matt Solnit added a comment - OK, I think I know what's going on. I appreciate your help and I apologize for leading you in the wrong direction before. The problem, as far as I can tell, only shows up when using attributes. So if you put the following in the Aegis file: <property name="author" style="attribute" /> and use the following SOAP message: <?xml version='1.0' encoding='UTF-8'?> <soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'> <soap:Body> <putBook xmlns='http://xfire.codehaus.org/BookService'> <book xmlns='http://xfire.codehaus.org/BookService' author='Dan'><isbn>123</isbn><title>foo</title></book> </putBook> </soap:Body> </soap:Envelope> then you get the error. However, if you prefix-qualify the namespace, as shown below: <?xml version='1.0' encoding='UTF-8'?> <soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'> <soap:Body> <putBook> <b:book xmlns:b='http://xfire.codehaus.org/BookService' b:author='bob'><b:isbn>123</b:isbn><b:title>foo</b:title></b:book> </putBook> </soap:Body> </soap:Envelope> then it works. I hope this helps.
Hide
Dan Diephouse added a comment -

Hi Matt,
Your XML is wrong. The author in this example is not associated with any namespace:

<book xmlns='http://xfire.codehaus.org/BookService' author='Dan'>

The XML Namespace specification says:

A default namespace declaration applies to all unprefixed element names within its scope. Default namespace declarations do not apply directly to attribute names; the interpretation of unprefixed attributes is determined by the element on which they appear. ... The namespace name for an unprefixed attribute name always has no value.

So a correct version with book having an empty prefix would be:

<book xmlns='http://xfire.codehaus.org/BookService' xmlns:b="xmlns='http://xfire.codehaus.org/BookService'" b:author='Dan'>

Show
Dan Diephouse added a comment - Hi Matt, Your XML is wrong. The author in this example is not associated with any namespace: <book xmlns='http://xfire.codehaus.org/BookService' author='Dan'> The XML Namespace specification says: A default namespace declaration applies to all unprefixed element names within its scope. Default namespace declarations do not apply directly to attribute names; the interpretation of unprefixed attributes is determined by the element on which they appear. ... The namespace name for an unprefixed attribute name always has no value. So a correct version with book having an empty prefix would be: <book xmlns='http://xfire.codehaus.org/BookService' xmlns:b="xmlns='http://xfire.codehaus.org/BookService'" b:author='Dan'>
Hide
Matt Solnit added a comment -

Hi Dan. I read the spec and it looks like you're right. Thanks for checking this out.

The XML Schema Primer backs this up:
"In fact, attributes that are required to be qualified must be explicitly prefixed because the Namespaces in XML specification does not provide a mechanism for defaulting the namespaces of attributes."

However, the Xerces XSD validator will allow un-prefixed attributes. This is how I got confused. Maybe Xerces is wrong.

Show
Matt Solnit added a comment - Hi Dan. I read the spec and it looks like you're right. Thanks for checking this out. The XML Schema Primer backs this up: "In fact, attributes that are required to be qualified must be explicitly prefixed because the Namespaces in XML specification does not provide a mechanism for defaulting the namespaces of attributes." However, the Xerces XSD validator will allow un-prefixed attributes. This is how I got confused. Maybe Xerces is wrong.

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: