'Webservice using Apache axis, problem with generated xml (complex types)
We are given an wsdl file and he have to serve it a webservice using tomcat. We use axis1, applied wsdl2java, generated java classes and wsdd file. We can browse the wsdl on our tomcat. The problem is, when we try to consume the wsdl using the soapui tool it gives the error message
Error: A simpleContent extension must define a base type
The reason is the wsdl uses a complex type: org.w3.www._2005._05.xmlmime.Base64Binary
The generated wsdl by axis is as the following:
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.w3.org/2005/05/xmlmime">
<import namespace="http://../>
<complexType name="base64Binary">
<simpleContent>
<extension/>
</simpleContent>
</complexType>
</schema>
To overcome the problem, I tried extending the serializer classes and override the writeSchema method in the generated java classes (Base64Binary.java) by the wsdl2java,
/**
* Get Custom Serializer
*/
public static org.apache.axis.encoding.Serializer getSerializer(java.lang.String mechType,
java.lang.Class _javaType, javax.xml.namespace.QName _xmlType) {
System.out.println("Base64Binary.getSerializer()>>" + mechType + " " + _javaType + " " + _xmlType + " "
+ typeDesc.hashCode());
return new MySerializer(_javaType, _xmlType, typeDesc);
}
class MySerializer extends org.apache.axis.encoding.ser.SimpleSerializer {
public MySerializer(Class javaType, QName xmlType, TypeDesc typeDesc) {
super(javaType, xmlType, typeDesc);
System.out.println("MySerializer.MySerializer() constructor");
}
public Element writeSchema(Class javaType, Types types) throws Exception {
..
Element e = types.createElement("complexType"); // a custom element
//set desired attributes of e
types.writeSchemaElement("http://www.w3.org/2005/05/xmlmime", e);
}
By overriding the writeSchema, we can add custom schemes, but the problem is we have to remove existing schema which contains the simpleContent without base definiton.
The original wsdl contains the correct format and can be imported into SoapUI without problems:
<xs:schema xmlns:tns="http://www.w3.org/2005/05/xmlmime" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.w3.org/2005/05/xmlmime" version="1.0">
<xs:complexType name="base64Binary">
<xs:simpleContent>
<xs:extension base="xs:base64Binary">
<xs:attribute ref="tns:contentType"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
Question: How can we remove the schema which contains by modifiying the java classes so we can add our custom Elements which contains base defintion attributes for the simpleContent?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
