I'm working on a WSDL file that contains circular reference.  In particular:

For example:

Market (1) --> (1) CollectionOfSegment (1) --> (*) Segment

However, the Segment contains a reference to Market so it can refer to it.

I tried to use the WSDL2Java tool to generate the Java code.  It all seems to work.  
However, when I write a unit test that does the following for example (notes the 
Market contains :

    private CollectionOfSegment getSegments(Market m)
    {
        CollectionOfSegment cos = new CollectionOfSegment();
        Segment[] segs = new Segment[SEGSIZE];
        for (int i = 0; i < SEGSIZE; i++)
        {
            Segment s1 = new Segment();
            // Note here I'm setting in the reference
            s1.setMarket(m);
            s1.setName("Segment " + i);
            s1.setSettings(getTradeSettings());
            s1.setSecurities(getSecurities(s1, i));
            segs[i] = s1;
        }
        cos.setSegment(segs);
        return cos;
    }

Essentially, the Market object contains a reference to the CollectionOfSegment, then 
each Segment contains a reference to same Market object.

I ended up with a stack overflow problem when I run this code with a unit test.  If I 
do not have the line for s1.setMarket(m), it seems to run fine.  I'm pretty new to 
SOAP and this is somewhat frustrating.  Is it actually ok to have circular reference 
in SOAP?  It seems like Axis just runs in an infinite loop when this happens.  Is 
there any way I can resolve this?

If you're wondering, here's the full WSDL file that I'm using.  I use the ant task to 
produce the code on the server side.  BTW, there's a bug when Axis generates the 
namespace with "\".  It does not pad it when WSDL2Java includes the namespace in the 
java code quoted with ".  I need to fix this myself.

Oh well, this is for a class assignment and who in the world would use "\" in the 
namspace??

<?xml version="1.0" encoding="utf-8" ?>
<definitions targetNamespace="urn:LibraryDemo\srvcGeneral\srvcdoc" 
xmlns="http://schemas.xmlsoap.org/wsdl/"; 
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"; 
xmlns:ns="urn:LibraryDemo\srvcGeneral\srvcdoc">
        <types>
                <schema targetNamespace="urn:LibraryDemo\srvcGeneral\srvcdoc" 
elementFormDefault="qualified" xmlns="http://www.w3.org/2001/XMLSchema"; 
xmlns:ns="urn:LibraryDemo\srvcGeneral\srvcdoc" 
xmlns:xsd="http://www.w3.org/2001/XMLSchema";>
                        <complexType name="CollectionOfOrder">
                                <sequence>
                                        <element name="Order" minOccurs="0" 
maxOccurs="unbounded" type="ns:Order"/>
                                </sequence>
                        </complexType>
                        <complexType name="Market">
                                <sequence>
                                        <element name="settings" minOccurs="1" 
maxOccurs="1" type="ns:TradingSettings"/>
                                        <element name="segments" minOccurs="1" 
maxOccurs="1" type="ns:CollectionOfSegment"/>
                                </sequence>
                        </complexType>
                        <complexType name="CollectionOfSegment">
                                <sequence>
                                        <element name="Segment" minOccurs="0" 
maxOccurs="unbounded" type="ns:Segment"/>
                                </sequence>
                        </complexType>
                        <complexType name="TradingSettings">
                                <sequence>
                                        <element name="stateCycleSpec" minOccurs="0" 
maxOccurs="1" type="xsd:string"/>
                                        <element name="stopTradingRange" minOccurs="0" 
maxOccurs="1" type="xsd:double"/>
                                        <element name="priceIncrement" minOccurs="1" 
maxOccurs="1" type="xsd:double"/>
                                </sequence>
                        </complexType>
                        <complexType name="Segment">
                                <sequence>
                                        <element name="name" minOccurs="1" 
maxOccurs="1" type="xsd:string"/>
                                        <element name="settings" minOccurs="1" 
maxOccurs="1" type="ns:TradingSettings"/>
                                        <element name="securities" minOccurs="1" 
maxOccurs="1" type="ns:CollectionOfSecurity"/>
                                        <element name="market" minOccurs="1" 
maxOccurs="1" type="ns:Market"/>
                                </sequence>
                        </complexType>
                        <complexType name="CollectionOfSecurity">
                                <sequence>
                                        <element name="Security" minOccurs="0" 
maxOccurs="unbounded" type="ns:Security"/>
                                </sequence>
                        </complexType>
                        <complexType name="Security">
                                <sequence>
                                        <element name="name" minOccurs="1" 
maxOccurs="1" type="xsd:string"/>
                <element name="settings" minOccurs="1" maxOccurs="1" 
type="ns:TradingSettings"/>
                                        <element name="segment" minOccurs="1" 
maxOccurs="1" type="ns:Segment"/>
                                </sequence>
                        </complexType>
                        <complexType name="OrderStatus">
                                <sequence>
                                        <element name="matchingShares" minOccurs="1" 
maxOccurs="1" type="xsd:int"/>
                                        <element name="order" minOccurs="1" 
maxOccurs="1" type="ns:Order"/>
                                        <element name="matchingPrice" minOccurs="1" 
maxOccurs="1" type="xsd:double"/>
                                        <element name="identification" minOccurs="1" 
maxOccurs="1" type="xsd:string"/>
                                        <element name="matchingParty" minOccurs="1" 
maxOccurs="1" type="ns:Party"/>
                                        <element name="status" minOccurs="1" 
maxOccurs="1" type="xsd:string"/>
                                </sequence>
                        </complexType>
                        <complexType name="Order">
                                <sequence>
                                        <element name="numberOfShares" minOccurs="1" 
maxOccurs="1" type="xsd:int"/>
                                        <element name="nominalPrice" minOccurs="0" 
maxOccurs="1" type="xsd:double"/>
                                        <element name="party" minOccurs="1" 
maxOccurs="1" type="ns:Party"/>
                                        <element name="instrument" minOccurs="1" 
maxOccurs="1" type="xsd:string"/>
                                </sequence>
                        </complexType>
                        <complexType name="Party">
                                <sequence>
                                        <element name="name" minOccurs="1" 
maxOccurs="1" type="xsd:string"/>
                                        <element name="identification" minOccurs="1" 
maxOccurs="1" type="xsd:string"/>
                                </sequence>
                        </complexType>
                        <element name="x_GetOutstandingOrders" 
type="ns:GetOutstandingOrders"/>
                        <complexType name="GetOutstandingOrders">
                                <sequence>
                                        <element name="PrderIdentification" 
minOccurs="1" maxOccurs="1" type="xsd:int"/>
                                </sequence>
                        </complexType>
                        <element name="x_GetOutstandingOrdersResponse" 
type="ns:CollectionOfOrder"/>
                        <element name="x_CreateMarket" type="ns:CreateMarket"/>
                        <complexType name="CreateMarket">
                                <sequence>
                                        <element name="Market" minOccurs="1" 
maxOccurs="1" type="ns:Market"/>
                                </sequence>
                        </complexType>
                        <element name="x_CreateMarketResponse" type="xsd:boolean"/>
                        <element name="x_GetOrderStatus" type="ns:GetOrderStatus"/>
                        <complexType name="GetOrderStatus">
                                <sequence>
                                        <element name="OrderIdentification" 
minOccurs="1" maxOccurs="1" type="xsd:int"/>
                                </sequence>
                        </complexType>
                        <element name="x_GetOrderStatusResponse" 
type="ns:OrderStatus"/>
                        <element name="x_AddSellOrder" type="ns:AddSellOrder"/>
                        <complexType name="AddSellOrder">
                                <sequence>
                                        <element name="Order" minOccurs="1" 
maxOccurs="1" type="ns:Order"/>
                                </sequence>
                        </complexType>
                        <element name="x_AddSellOrderResponse" type="ns:OrderStatus"/>
                        <element name="x_AddBuyOrder" type="ns:AddBuyOrder"/>
                        <complexType name="AddBuyOrder">
                                <sequence>
                                        <element name="Order" minOccurs="1" 
maxOccurs="1" type="ns:Order"/>
                                </sequence>
                        </complexType>
                        <element name="x_AddBuyOrderResponse" type="ns:OrderStatus"/>
                </schema>
        </types>
        <message name="GetOutstandingOrders">
                <part name="parameter" element="ns:x_GetOutstandingOrders"/>
        </message>
        <message name="GetOutstandingOrdersResponse">
                <part name="return" element="ns:x_GetOutstandingOrdersResponse"/>
        </message>
        <message name="CreateMarket">
                <part name="parameter" element="ns:x_CreateMarket"/>
        </message>
        <message name="CreateMarketResponse">
                <part name="return" element="ns:x_CreateMarketResponse"/>
        </message>
        <message name="GetOrderStatus">
                <part name="parameter" element="ns:x_GetOrderStatus"/>
        </message>
        <message name="GetOrderStatusResponse">
                <part name="return" element="ns:x_GetOrderStatusResponse"/>
        </message>
        <message name="AddSellOrder">
                <part name="parameter" element="ns:x_AddSellOrder"/>
        </message>
        <message name="AddSellOrderResponse">
                <part name="return" element="ns:x_AddSellOrderResponse"/>
        </message>
        <message name="AddBuyOrder">
                <part name="parameter" element="ns:x_AddBuyOrder"/>
        </message>
        <message name="AddBuyOrderResponse">
                <part name="return" element="ns:x_AddBuyOrderResponse"/>
        </message>
        <portType name="ElectronicMarket">
                <operation name="GetOutstandingOrders">
                        <documentation>It returns all the orders placed by a party 
that didn't match any other.</documentation>
                        <input message="ns:GetOutstandingOrders"/>
                        <output message="ns:GetOutstandingOrdersResponse"/>
                </operation>
                <operation name="CreateMarket">
                        <documentation>It creates a market with segments, securities 
and parties</documentation>
                        <input message="ns:CreateMarket"/>
                        <output message="ns:CreateMarketResponse"/>
                </operation>
                <operation name="GetOrderStatus">
                        <documentation>It returns the status of an order posted 
before</documentation>
                        <input message="ns:GetOrderStatus"/>
                        <output message="ns:GetOrderStatusResponse"/>
                </operation>
                <operation name="AddSellOrder">
                        <documentation>It adds an order for selling the instrument 
spedified by anOrder</documentation>
                        <input message="ns:AddSellOrder"/>
                        <output message="ns:AddSellOrderResponse"/>
                </operation>
                <operation name="AddBuyOrder">
                        <documentation>It adds an order for buying the instrument 
spedified by anOrder</documentation>
                        <input message="ns:AddBuyOrder"/>
                        <output message="ns:AddBuyOrderResponse"/>
                </operation>
        </portType>
        <binding name="ElectronicMarket" type="ns:ElectronicMarket">
                <soap:binding style="document" 
transport="http://schemas.xmlsoap.org/soap/http/"/>
                <operation name="GetOutstandingOrders" 
selector="getOutstandingOrders:">
                        <soap:operation soapAction=""/>
                        <input>
                                <soap:body use="literal" 
namespace="urn:LibraryDemo\srvcGeneral\srvcdoc"/>
                        </input>
                        <output>
                                <soap:body use="literal" 
namespace="urn:LibraryDemo\srvcGeneral\srvcdoc"/>
                        </output>
                </operation>
                <operation name="CreateMarket" selector="createMarket:">
                        <soap:operation soapAction=""/>
                        <input>
                                <soap:body use="literal" 
namespace="urn:LibraryDemo\srvcGeneral\srvcdoc"/>
                        </input>
                        <output>
                                <soap:body use="literal" 
namespace="urn:LibraryDemo\srvcGeneral\srvcdoc"/>
                        </output>
                </operation>
                <operation name="GetOrderStatus" selector="getOrderStatus:">
                        <soap:operation soapAction=""/>
                        <input>
                                <soap:body use="literal" 
namespace="urn:LibraryDemo\srvcGeneral\srvcdoc"/>
                        </input>
                        <output>
                                <soap:body use="literal" 
namespace="urn:LibraryDemo\srvcGeneral\srvcdoc"/>
                        </output>
                </operation>
                <operation name="AddSellOrder" selector="addSellOrder:">
                        <soap:operation soapAction=""/>
                        <input>
                                <soap:body use="literal" 
namespace="urn:LibraryDemo\srvcGeneral\srvcdoc"/>
                        </input>
                        <output>
                                <soap:body use="literal" 
namespace="urn:LibraryDemo\srvcGeneral\srvcdoc"/>
                        </output>
                </operation>
                <operation name="AddBuyOrder" selector="addBuyOrder:">
                        <soap:operation soapAction=""/>
                        <input>
                                <soap:body use="literal" 
namespace="urn:LibraryDemo\srvcGeneral\srvcdoc"/>
                        </input>
                        <output>
                                <soap:body use="literal" 
namespace="urn:LibraryDemo\srvcGeneral\srvcdoc"/>
                        </output>
                </operation>
        </binding>
          <service name="ElectronicMarketService">
    <port name="ElectronicMarket" binding="ns:ElectronicMarket">
      <soap:address 
location="http://localhost:8080/jboss-net/services/ElectronicMarket"/>
    </port>
  </service>
</definitions>

--
William (Will) Lee 
Email: [EMAIL PROTECTED]
Computer Science, University of Illinois at Urbana-Champaign

Reply via email to