Return-Path: Delivered-To: apmail-ws-axis-dev-archive@www.apache.org Received: (qmail 86730 invoked from network); 29 Jun 2007 03:54:34 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 29 Jun 2007 03:54:34 -0000 Received: (qmail 26896 invoked by uid 500); 29 Jun 2007 03:54:33 -0000 Delivered-To: apmail-ws-axis-dev-archive@ws.apache.org Received: (qmail 26842 invoked by uid 500); 29 Jun 2007 03:54:33 -0000 Mailing-List: contact axis-dev-help@ws.apache.org; run by ezmlm Precedence: bulk Reply-To: axis-dev@ws.apache.org list-help: list-unsubscribe: List-Post: List-Id: Delivered-To: mailing list axis-dev@ws.apache.org Received: (qmail 26736 invoked by uid 99); 29 Jun 2007 03:54:32 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 28 Jun 2007 20:54:32 -0700 X-ASF-Spam-Status: No, hits=-100.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO brutus.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 28 Jun 2007 20:54:27 -0700 Received: from brutus (localhost [127.0.0.1]) by brutus.apache.org (Postfix) with ESMTP id 527E97141E3 for ; Thu, 28 Jun 2007 20:54:07 -0700 (PDT) Message-ID: <3611887.1183089247330.JavaMail.jira@brutus> Date: Thu, 28 Jun 2007 20:54:07 -0700 (PDT) From: "Davanum Srinivas (JIRA)" To: axis-dev@ws.apache.org Subject: [jira] Commented: (AXIS2-1938) [axis2] WSDL2JAVA with XMLBean binding does not create instance of the derived type or ignore xsi:type in the xml In-Reply-To: <8262114.1167963987864.JavaMail.jira@brutus> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org [ https://issues.apache.org/jira/browse/AXIS2-1938?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12509000 ] Davanum Srinivas commented on AXIS2-1938: ----------------------------------------- All issues in this scenario have been fixed. Please check latest nightly and report back if you see any other issues. -- dims > [axis2] WSDL2JAVA with XMLBean binding does not create instance of the derived type or ignore xsi:type in the xml > ----------------------------------------------------------------------------------------------------------------- > > Key: AXIS2-1938 > URL: https://issues.apache.org/jira/browse/AXIS2-1938 > Project: Axis 2.0 (Axis2) > Issue Type: Bug > Components: databinding > Affects Versions: 1.1 > Environment: Windows XP, tomcat 5.5, Axis2 1.1 > Reporter: Bo Xie > Assignee: Amila Chinthaka Suriarachchi > Attachments: StockQuoteServiceSkeleton.java, XMLBeanBinding.zip > > > There are basically two issues. > 1. The java objects created does not use the xsi:type in the XML. In my case, the xsi:type is for derived type, but the object created is still of base type. > 2. The XML string generated from the client side has the xsi:type for Address object, so the service see it but did not generate the derived type according to the xsi:type(this is the issue reported above). But the server side generated XML string does not have the xsi:type for the objects, so the object XML string does not have xsi:type when the message received on the client side. Why the xsi:type is missing in this case? In both cases, I used types derived from the Address type. The client and service code are based on the XMLBean quickstart sample. > Attached are > 1. the WSDL file. > 2.The build file that you can check if the WSDL2JAVA is proper for my case. > 3. The client code > 4. The server code. > Below are the email exchange with Ajith Ranabahu. > Subject: [axis2] WSDL2JAVA with XMLBean binding does not create instance of the derived type > ------------------------ > From: Bo Xie > To: axis-user@ws.apache.org > Date: Tue, Jan 2, 2007 at 7:45 PM > Hi there, > I am new to axis2 with XMLBean data binding, please help me with the following issue. > I modified the quickstart sample XMLBean program to try a WSDL with the following types. The type US-Address is a derived from type Address. I would like to create a service operation updateAddresses to change addresses of a company based on a symbol. The addresses is an array that can take either Address or USAddress instances. > > > > > > > > > > > > > > > > > > > > > > > > > > > I used WSDL2JAVA with XMLBean data binding to generate the skeleton and stub code. All looks great and the SOAP exchange looks fine too. > In the client code, I created one instance if USAddress and one instance of Address and put them into the addresses list. In the SOAP request message, the instances are as shown as follows below. Note, xsi-type for the instance indicate the correct types which is nice. > > > > XYZ > > company name > Sunnyvale > CA > 94087 > > > company name > Hong Kong > > > > The problem is when the XML object mapped into java object on the service side, all the XML address object passed to the skeleton are all of Address type. I would expect one instance be Address type, another be USAddress type. Since xsi-type in the SOAP message has the right type, why the XMLBean object is not created as the derived type? Is there any option in WSDL2JAVA to make this work? > From the XMLBean Address java object, how can I access the xsi-type attribute that was available in the XML string? > If I am not heading the right direction, can anyone suggest some alternatives? > Thanks for your time! > -Bo > > -------- > From: Ajith Ranabahu > Reply-To: axis-user@ws.apache.org > To: axis-user@ws.apache.org > Date: Wed, Jan 3, 2007 at 5:16 AM > Hi, > The reason here is that you have set the type of the addresses element > to be 'Address' rather than USAddress (the code generator would put > the reference for the Address rather than the USAddress). However > since the xsi:type attribute is present the deserializer should create > the right object and you can just use a type cast to get to the right > object. > HTH > Ajith > [Quoted text hidden] > -- > Ajith Ranabahu > --------------------------------------------------------------------- > To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org > For additional commands, e-mail: axis-user-help@ws.apache.org > -------- > From: Bo Xie > Reply-To: axis-user@ws.apache.org > To: axis-user@ws.apache.org > Date: Wed, Jan 3, 2007 at 7:55 AM > Thanks Ajith for the quick response. > I have tried to use the instanceof to test if the instance is USAddress, > but the test returns false. Without that, the type cast is not safe as > the Address list can have items of either Address or USAddress. My > question here is should the java instance created from XML be of type > USAddress even though the signature is Address. Is there anyway to make > this happen? > Thanks, > -Bo > [Quoted text hidden] > [Quoted text hidden] > -------- > From: Ajith Ranabahu > Reply-To: axis-user@ws.apache.org > To: axis-user@ws.apache.org > Date: Wed, Jan 3, 2007 at 8:20 AM > Hi, > Since the xsi:type attribute is present and points to the USAddress, > the generated object should be of type USAddress. Perhaps the problem > is the way you check the instanceof. I mean XMLBeans should have > generated a getAddresses method to updateAddress ? (It's a little bit > weird how XMLBeans treats these schemas but I'm guessing) > If you can use a debugger and go through the object hierarchy at > runtime you should be able to figure this out > Ajith > [Quoted text hidden] > -- > Ajith Ranabahu > [Quoted text hidden] > -------- > From: Bo Xie > To: axis-user@ws.apache.org > Date: Wed, Jan 3, 2007 at 10:19 AM > Thanks Ajith. Could you be more specific on how to figure out the right type of the instance? Here is the code snippet and the output on the service side. > The getAddressArray indeed returns Address[] which is good. But the instanceof always returns Address even for USAddress instance. The interesting thing is the toString output of the addr variable. It includes the correct xsi-type for each instance. So how can I do the correct instanceof to figure the right type to cast in this case? > Thanks, > -Bo > ----Code snippet---- > public void updateAddresses(samples.quickstart.service.xmlbeans.xsd.UpdateAddressesDocument param3) > { > //Todo fill this with the necessary business logic > String symbol = param3.getUpdateAddresses().getSymbol(); > System.err.println(getCurrentTime()+"- Update Symbol:" + symbol); > > Address[] addrs = param3.getUpdateAddresses ().getAddressesArray(); > for (int i = 0; i < addrs.length; i++) { > Address addr = addrs[i]; > if(addr instanceof USAddress) System.err.println("USAddress instance"); > if(addr instanceof Address) System.err.println("Address instance"); > System.err.println(addr.getClass().getName()+":"+addr); > } > ...} > ----Output from the code ---- > Address instance > samples.quickstart.service.xmlbeans.xsd.impl.AddressImpl: > company name > Sunnyvale > CA > 94087 > > Address instance > samples.quickstart.service.xmlbeans.xsd.impl.AddressImpl: > company > Hong Kong > > [Quoted text hidden] > -------- > From: Ajith Ranabahu > Reply-To: axis-user@ws.apache.org > To: axis-user@ws.apache.org > Date: Wed, Jan 3, 2007 at 5:16 PM > Hi, > It seems to me that you have to go one level deep. See whether there > is a getAddress method in the Address class. > XMLBeans generates a lot of classes and things are a bit confusing > specially when types and elements have similar names. AFAIK XMLBeans > generates a class per type and element. So there would be a class > generated for the address type and also for the address element. My > guess is you have to check the address type object instead of the > address element object. > Ajith > [Quoted text hidden] > -- > [Quoted text hidden] > -------- > From: Ramesh Gurunathan > Reply-To: axis-user@ws.apache.org > To: axis-user@ws.apache.org > Date: Wed, Jan 3, 2007 at 8:32 PM > Hi, > What you are trying to achieve is the value inheritance in XML. I > think, unfortunately, the web services / XML / SOAP community is > paying less attention to this topic. I encountered the same issue with > XMLBeans binding. It forced me to change the XML schema. I introduced > a new complex type with a 'choice' > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > If you generate XML beans types with above changes, it will generate a > Address type object which will have methods to check whether USAddress > is set or the Other Address. No need of instanceof check. Do take a > look at the generated method signatures of the Address XML type > object, it should give you an idea to play with it. > That said, this is just an another way of handling inheritance. I > would like to see XML beans to inherantly support the polymorphism. > Ramesh > [Quoted text hidden] > -------- > From: Bo Xie > To: axis-user@ws.apache.org > Date: Wed, Jan 3, 2007 at 10:50 PM > Hi Ajith, > The Address class only has getter and setter for name, city etc. No getAddress. Do you see this ignoring of xsi:type in creating instance as a bug? > Besides using choice option as Ramesh suggested, do we run out of luck here? I am a little hesitate to use choice as in my case, the choice list changes quite fast. Keeping track of the exhaustive list of all the choices is a challenge. > Thanks, > -Bo > [Quoted text hidden] > -------- > From: Ajith Ranabahu > Reply-To: axis-user@ws.apache.org > To: axis-user@ws.apache.org > Date: Thu, Jan 4, 2007 at 5:08 AM > Hi, > > Hi Ajith, > > > > The Address class only has getter and setter for name, city etc. No > > getAddress. Do you see this ignoring of xsi:type in creating instance as a > > bug? > Yep. It is a bug. But AFAIK it was reported to be working. In any case > you can file a Jira with your schema. > Ajith -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online. --------------------------------------------------------------------- To unsubscribe, e-mail: axis-dev-unsubscribe@ws.apache.org For additional commands, e-mail: axis-dev-help@ws.apache.org