Hello guys,
I am using the AxisService2WSDL11 class to generate a WSDL for an
AxisService.
The service was populated from a WSDL and contains policy references on the
service and some of the bindings.
When the addPolicyAsExtElement(..) method is being executed (no matter on
which subject), the corresponding policy references should be added to the
resulting OMElement.
However the PolicyUtil.getPolicyComponentAsOMElement(..) fails to serialize
the PolicyReference component with the following exception:
Caused by: org.apache.axiom.om.OMException:
com.ctc.wstx.exc.WstxParsingException: Undeclared namespace prefix "wsp"
at [row,col {unknown-source}]: [1,56]
at org.apache.axiom.om.impl.builder.StAXOMBuilder.next(
StAXOMBuilder.java:239)
at org.apache.axiom.om.impl.llom.OMDocumentImpl.getOMDocumentElement
(OMDocumentImpl.java:130)
at org.apache.axiom.om.impl.builder.StAXOMBuilder.getDocumentElement
(StAXOMBuilder.java:359)
at org.apache.axis2.util.XMLUtils.toOM(XMLUtils.java:568)
at org.apache.axis2.util.PolicyUtil.getPolicyComponentAsOMElement(
PolicyUtil.java:119)
at
org.apache.axis2.description.AxisService2WSDL11.addPolicyAsExtElement(
AxisService2WSDL11.java:1007)
at org.apache.axis2.description.AxisService2WSDL11.generateService(
AxisService2WSDL11.java:477)
at org.apache.axis2.description.AxisService2WSDL11.generateOM(
AxisService2WSDL11.java:229)
I spent some time trying to find the reason for this and it seems that the
problem is inside the Woodstox Stax API.
It happens that the writer that is created using the XMLOutputFactory does
not add schema declarations to the underlying output stream.
So if the original PolicyReference is:
<wsp:PolicyReference xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy"
URI="#My_Reliable_Messaging_Policy"/>
after writing it to the ByteArrayOutputStream it becomes:
<wsp:PolicyReference URI="#My_Reliable_Messaging_Policy"/>
I am using wstx-asl-3.2.1.jar, but I've also tried with newer and older
version and the result was the same.
The underlying writer that is returned by the Wstx XMLOutpuFactory is
SimpleNsStreamWriter, I noticed if I use the RepairingNsStreamWriter,
it correctly adds the schema declarations and I get no exception (this can
be forced by setting the XMLOutputFactory.IS_REPAIRING_NAMESPACES property
to the factory).
Has anyone experienced the same problem. Is there something that I miss
here, or there is a problem in the Woodstox API (which I seriously doubt)?
Thanks in advance for any help.
Regards,
Detelin