Description
ReflectionServiceFactoryBean has the public property anonymousWrapperTypes controlling whether the type (XSD) of a message is represented as standalone, named type in the WSDL, or an anonymous, inline type (the default is false -> standalone, named). Setting it to true effectuates producing the inline, anonymous type, but this is, however, present also on top-level, as standalone one, making the WSDL invalid (top-level types must have a name):
<wsdl:definitions> <wsdl:types> <xsd:schema> <xsd:element name="m"> <xsd:complexType> <xsd:sequence> <xsd:element name="x" type="xsd:int"/> </xsd:sequence> </xsd:complexType> </xsd:element> <xsd:complexType> <xsd:sequence> <xsd:element name="x" type="xsd:int"/> </xsd:sequence> </xsd:complexType> ... </xsd:schema> ... </wsdl:types> ... <wsdl:definitions>
Correctly:
<wsdl:definitions> <wsdl:types> <xsd:schema> <xsd:element name="m"> <xsd:complexType> <xsd:sequence> <xsd:element name="x" type="xsd:int"/> </xsd:sequence> </xsd:complexType> </xsd:element> ... </xsd:schema> ... </wsdl:types> ... <wsdl:definitions>
Fix-proposal: use new XmlSchemaComplexType(schema, !isAnonymousWrapperTypes()) in the line 1300 instead of new XmlSchemaComplexType(schema, true).
rt/wsdl/src/main/java/org/apache/cxf/wsdl/service/factory/ReflectionServiceFactoryBean.java
1289 private void createWrappedMessageSchema(ServiceInfo serviceInfo, AbstractMessageContainer wrappedMessage, 1290 AbstractMessageContainer unwrappedMessage, SchemaInfo info, 1291 QName wrapperName) { 1292 1293 XmlSchema schema = info.getSchema(); 1294 info.setElement(null); // the cached schema will be no good 1295 XmlSchemaElement el = new XmlSchemaElement(schema, true); 1296 el.setName(wrapperName.getLocalPart()); 1297 1298 wrappedMessage.getFirstMessagePart().setXmlSchema(el); 1299 1300 XmlSchemaComplexType ct = new XmlSchemaComplexType(schema, true); 1301 1302 if (!isAnonymousWrapperTypes()) { 1303 ct.setName(wrapperName.getLocalPart()); 1304 el.setSchemaTypeName(wrapperName); 1305 } 1306 el.setSchemaType(ct);