On Thu, 8 Apr 2010, Amila Suriarachchi wrote:

On Wed, Apr 7, 2010 at 9:51 PM, Arne Welzel <[email protected]>wrote:

Hi all,

i have a question regarding wsdl2java using JAXBRI as databinding
option. The wsdl is referencing two "somewhat" independent schema files.

I'm describing the problem in general as I'm not allowed to publish the
used files. If needed I can construct an example which should show the
observed problem.

We have the following situation:
 - wsdl containing message definitions which reference elements
  from our first schema.

 - One of the types given in the first schema uses xsd:Any.
  This is where the second schema file comes into play.

 - Every element defined in the second schema may be put where xsd:Any
  is used. (This is the dependency between those schemas). Besides
  the elements given in the second schema everything else might be
  used, those are some "known" elements.

When running wsdl2java, classes for the elements in the second schema
are generated. However using those classes and putting them into the
xsd:Any position ( obj.getAny().add(objectofgeneratedclass) ) leads to a
MarshalException / JAXBException saying "<class>  nor any of its super
class is known to this context".

I was able to solve this by adding the generated classes to the context
initialization code in the ServiceStub.java file.

It would be interesting to know if there is some flag to simply use
every generated class in the context or if the used fix is acceptable.


are you using xsd:anyType or xsd:any ? will you be able to send a simple
sample file to
show the error?

Hi Amila,

thanks for your reply.

We use xsd:any.

I have appended two schema files which have very "dumb" elements and
used in the wsdl. The problem can be observed after generating the necessary
code with wsdl2java -d jaxbri and running the main() in the Driver class.

        Caused by: javax.xml.bind.MarshalException
        - with linked exception:
        [javax.xml.bind.JAXBException: class namespace2.ElementFromSchema2 nor
        any of its super class is known to this context.]

Modifying the JAXBContext initialization around line 430 in the generated
ServiceStub.java file as described above fixes the problem.
Namely adding namespace2.ElementFromSchema2.class to the newInstance()
call.

Hope the problem is clearer with this example...

Thanks,
Arne
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema";
  xmlns="http://namespace1";
  targetNamespace="http://namespace1";>

  <xsd:element name="request" type="RequestType"/>
  <xsd:element name="response" type="ResponseType"/>

  <xsd:complexType name="TypeFromSchema1">
    <xsd:attribute name="name" type="xsd:string" use="required"/>
  </xsd:complexType>

  <xsd:complexType name="ListType">
    <xsd:sequence>
      <xsd:any minOccurs="0" maxOccurs="unbounded"/>
    </xsd:sequence>
  </xsd:complexType>

  <xsd:complexType name="RequestType">
          <xsd:sequence>
                  <xsd:element name="some" type="TypeFromSchema1"/>
                  <xsd:element name="list" type="ListType"/>
          </xsd:sequence>
  </xsd:complexType>

  <xsd:complexType name="ResponseType">
          <xsd:sequence>
                  <xsd:element name="result" type="xsd:string"/>
          </xsd:sequence>
  </xsd:complexType>
  </xsd:schema>
<?xml version="1.0"?>

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema";

  xmlns="http://namespace2";

  targetNamespace="http://namespace2";>

  <xsd:element name="ElementFromSchema2">

          <xsd:complexType>

                  <xsd:attribute name="name" type="xsd:string"/>

          </xsd:complexType>

  </xsd:element>

</xsd:schema>

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions targetNamespace="http://namespacewsdl";
 xmlns:nswsdl="http://namespacewsdl";
 xmlns:http="http://schemas.xmlsoap.org/wsdl/http/";
 xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/";
 xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/";
 xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/";
 xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/";
 xmlns:ns1="http://namespace1";
 xmlns:xsd="http://www.w3.org/2001/XMLSchema"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";>

        <wsdl:types>
                <xsd:schema>
                        <xsd:import namespace="http://namespace1"; 
schemaLocation="schema1.xsd"></xsd:import>
                        <xsd:import namespace="http://namespace2"; 
schemaLocation="schema2.xsd"></xsd:import>
                </xsd:schema>
        </wsdl:types>

    <wsdl:message name="Response">
        <wsdl:part name="response" element="ns1:response"></wsdl:part>
    </wsdl:message>
   
    <wsdl:message name="Request">
        <wsdl:part name="request" element="ns1:request"></wsdl:part>
    </wsdl:message>
    
    <wsdl:portType name="MyPortType">
        <wsdl:operation name="publish">
            <wsdl:input message="nswsdl:Request"></wsdl:input>
            <wsdl:output message="nswsdl:Response"></wsdl:output>
        </wsdl:operation>
    </wsdl:portType>


    <wsdl:binding name="Service" type="nswsdl:MyPortType">
        <soap:binding transport="http://schemas.xmlsoap.org/soap/http"; 
style="document"/>
        <wsdl:operation name="publish">
            <soap:operation soapAction=""/>
            <wsdl:input>
                <soap:body parts="request" use="literal"/>
            </wsdl:input>
            <wsdl:output>
                <soap:body parts="response" use="literal"/>
            </wsdl:output>
        </wsdl:operation>
    </wsdl:binding>
    
    <wsdl:service name="MyService">
        <wsdl:documentation>MyService</wsdl:documentation>
        <wsdl:port name="MyPort" binding="nswsdl:Service">
                <soap:address 
location="https://172.17.1.6:8443/axis2/services/MyService"/>
        </wsdl:port>
    </wsdl:service>
</wsdl:definitions>
import namespace1.ListType;
import namespace1.RequestType;
import namespace1.TypeFromSchema1;
import namespace2.ElementFromSchema2;
import namespacewsdl.MyServiceStub;

public class Driver {
        
        public static void main(String[] args) throws Exception {
                MyServiceStub mss = new 
MyServiceStub("https://10.3.1.116:8444";);
                
                RequestType rt = new RequestType();
                
                TypeFromSchema1 schema1type = new TypeFromSchema1();
                schema1type.setName("Schema1");
        

                
                ElementFromSchema2 schema2element = new ElementFromSchema2();
                schema2element.setName("Schema2");
                
                ListType lt = new ListType();
                
                lt.getAny().add(schema2element); /* schema2element to xsd:any 
list */
                
                rt.setSome(schema1type);
                rt.setList(lt);
                
                mss.publish(rt);
        }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to