How to get complex types in WSDL files with Java?

1.9k Views Asked by At

I have read similar topics and examples, but I have still some problems about getting WSDL schema content with complex types from WSDLs.

I am using WSDL4J, Castor and JDOM libraries.

            org.exolab.castor.xml.schema.Schema castorSchema = null ;
            if(theWSDL.getTypes() !=null &&  theWSDL.getTypes().getExtensibilityElements() !=null){
                for (Object e : theWSDL.getTypes().getExtensibilityElements()) {
                    schema = (Schema)e;
                }
            }

            if (schema != null) {
                DOMBuilder domBuilder = new DOMBuilder();
                Element jdomSchemaElement = domBuilder.build(schema.getElement());
                XMLOutputter outputter = new XMLOutputter();
                String xmlout = outputter.outputString(jdomSchemaElement.getDocument());

                StringReader in2 = new StringReader(xmlout);
                InputSource schemaSource = new InputSource(in2);

                SchemaReader schemaReader;
                try {
                    schemaReader = new SchemaReader(schemaSource);
                    castorSchema= schemaReader.read();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }

This code works for some WSDL files but for some WSDL files, I am getting this error for line "castorSchema= schemaReader.read();":

Exception in thread "main" java.lang.IllegalArgumentException: getComplexType: Namespace prefix not recognized 'tns:cEstado' at org.exolab.castor.xml.schema.Schema.getComplexType(Schema.java:951) at org.exolab.castor.xml.schema.TypeReference.resolveTypeReference(TypeReference.java:122) at org.exolab.castor.xml.schema.TypeReference.getType(TypeReference.java:71) at org.exolab.castor.xml.schema.ElementDecl.getType(ElementDecl.java:349) at org.exolab.castor.xml.schema.ElementDecl.validate(ElementDecl.java:809) at org.exolab.castor.xml.schema.Group.validate(Group.java:463) at org.exolab.castor.xml.schema.ComplexType.validate(ComplexType.java:815) at org.exolab.castor.xml.schema.Schema.validate(Schema.java:2206) at org.exolab.castor.xml.schema.reader.SchemaReader.read(SchemaReader.java:261) at network.WSNetwork.execute(WSNetwork.java:105) at network.WSNetwork.main(WSNetwork.java:61)

The wsdl file part about complex types in schema:

    <s:complexType>

      <s:sequence>

        <s:element minOccurs="0" maxOccurs="1" name="getestadosResult" type="tns:ArrayOfCEstado" />

      </s:sequence>

    </s:complexType>

  </s:element>

  <s:complexType name="ArrayOfCEstado">

    <s:sequence>

      <s:element minOccurs="0" maxOccurs="unbounded" name="cEstado" nillable="true" type="tns:cEstado" />

    </s:sequence>

  </s:complexType>

  <s:complexType name="cEstado">

    <s:sequence>

      <s:element minOccurs="0" maxOccurs="1" name="IdEstado" type="s:string" />

      <s:element minOccurs="0" maxOccurs="1" name="Estado" type="s:string" />

      <s:element minOccurs="0" maxOccurs="1" name="Err" type="s:string" />

    </s:sequence>

  </s:complexType>

Any help will be appreciated..

Thanks

0

There are 0 best solutions below