1 2 Previous Next 15 Replies Latest reply on Dec 4, 2007 9:16 AM by marius costa

    Webservice - SOAP - JAXB Introductions

    Tom Fennelly Master

      Check out the Webservice/SOAP components for the 4.2 release here. I also added a blog for this.

      There's a blog for the JAXB Annotation Introduction work we've done in the pipeline - will post it in the morning.

        • 1. Re: Webservice - SOAP - JAXB Introductions
          Tom Fennelly Master

          Just posted a bog on the JAXB Annotation Introductions work we've done recently.

          • 2. Re: Webservice - SOAP - JAXB Introductions
            Rex Sheridan Newbie

            I've been looking for something like this for a long time. Great work.

            • 3. Re: Webservice - SOAP - JAXB Introductions
              Sylvia Isler Newbie

              I think this is a great idea also. But I am having trouble getting it to work.
              I wrote the following class:

              public class UnitPrice {
               public double value;
               UnitPrice(double value){
               this.value=value;
               }
               UnitPrice()
               {
              
               }
               public double getValue()
               {
               return this.value;
               }
              
              }


              with the following config file: (note I've tried the XmlAttribute and the commented out XmlElement for presenting a UnitPrice and its value.)
              <?xml version = "1.0" encoding = "UTF-8"?>
              <jaxb-intros xmlns="http://www.jboss.org/xsd/jaxb/intros">
               <Class name="junit.prices.UnitPrice">
               <XmlType name = "UnitPrice"/>
               <Field name="value">
               <!-- XmlElement name="value" nillable="true" /-->
               <XmlAttribute name="value" required="true" />
               </Field>
               </Class>
              </jaxb-intros>
              


              and the following xml file for unmarshalling:

              <?xml version="1.0" encoding="UTF-8"?>
              <UnitPrice value="40.0" xsi:noNamespaceSchemaLocation="C:\UnitPrice.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
              


              I then used the following code to test the unmarshalling of the above XML.
              JaxbIntros config = IntroductionsConfigParser.parseConfig(getClass().getResourceAsStream("UnitConfig.xml"));
              
              
               ClassIntroConfig classIntroConfig = config.getClazz().get(0);
               assertEquals(UnitPrice.class.getName(), classIntroConfig.getName());
               IntroductionsAnnotationReader reader = new IntroductionsAnnotationReader(config);
              
               Map<String, Object> jaxbConfig= new HashMap<String, Object>();
               jaxbConfig.put(JAXBRIContext.ANNOTATION_READER, reader);
               JAXBContext jaxbContext = JAXBContext.newInstance(new Class[] {UnitPrice.class}, jaxbConfig);
              
               Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
               JAXBElement jbe = null;
               UnitPrice order =null;
              
               StreamSource ss = new StreamSource(getClass().getResourceAsStream("UsdUnitPrice1.xml"));
              
               jbe = unmarshaller.unmarshal(ss, UnitPrice.class);
              
               order =(UnitPrice)jbe.getValue();
               try{
               assertEquals("get double value error", 40.0, order.getValue());
               } catch (Exception e) {
               fail(e.getMessage());
              }
              


              a UnitPrice instance is instantiated. However, the above test code fails because the value attribute of the unmarshalled UnitPrice instance is 0.0 instead of 40.0.

              Does anyone see any problems with the JAXB Intros config file above that would cause JAXB to fail to properly unmarshall the above XML file?



              Thanks,


              Sylvia



              • 4. Re: Webservice - SOAP - JAXB Introductions
                Tom Fennelly Master

                Some things for you to try...

                1. Add a setter method on your UnitPrice bean (if you can). Not sure if this is your problem. I see that you have it public, but I'm not sure how JAXB handles this normally
                2. Change to using a Method config (Vs Field), just to see what happens. I've noticed JAXB do some unexplainable things that were resolved by doing this.
                3. In test/parallel code, annotate your UnitPrice bean and try using JAXB directly. Find out what works and work back from there.

                • 5. Re: Webservice - SOAP - JAXB Introductions
                  Sylvia Isler Newbie

                  Thanks for the response and the very useful debugging suggestions. I ended up getting the UnitPrice class implementation below to work in example to work in JAXB-proper.

                  without the @XmlTransient tag on getValue() I observed an illegal annotations error indicating that the attribute value and the method getValue() are somehow duplicating eachother as far as JAXB is concerned.

                  Now, I am wondering whether XmlRootElement and XmlTransient are necessary annotations in JaxbIntros to make this sort of example work?

                  @XmlRootElement(name="UnitPrice")
                  public class UnitPrice {
                  
                   @XmlAttribute private double value;
                   UnitPrice(double value){
                   this.value=value;
                   }
                   UnitPrice()
                   {
                  
                   }
                  
                   @XmlTransient
                   public double getValue()
                   {
                   return this.value;
                   }
                   public void setValue(double v){
                   this.value = v;
                   }
                  }
                  


                  • 6. Re: Webservice - SOAP - JAXB Introductions
                    Sylvia Isler Newbie

                    One other question:
                    Is it a true statement that the JAXB Intros config:

                    <Field name="value">
                     <XmlAttribute name="value" required="true" />
                     </Field>


                    should be equivalent to the use of the @XmlAttribute tag annotation in the code as follows?
                    @XmlAttribute private double value;


                    If not what is the proper way to reproduce the effects of using the @XmlAttribute in a JaxbIntros config file?
                    Thanks again,
                    Sylvia


                    • 7. Re: Webservice - SOAP - JAXB Introductions
                      Tom Fennelly Master

                      It should be equivalent to:

                      @XmlAttribute(required=true) private double value;
                      



                      without the @XmlTransient tag on getValue() I observed an illegal annotations error indicating that the attribute value and the method getValue() are somehow duplicating eachother as far as JAXB is concerned.


                      Right, this is what I meant by "some unexplainable things" in my last post. I found that this exact issue could be got around by placing the annotation on the method Vs the field. So in JAXB Intros config....

                      <?xml version = "1.0" encoding = "UTF-8"?>
                      <jaxb-intros xmlns="http://www.jboss.org/xsd/jaxb/intros">
                       <Class name="junit.prices.UnitPrice">
                       <XmlType name = "UnitPrice"/>
                       <Method name="getValue">
                       <XmlAttribute name="value" required="true" />
                       </Method>
                       </Class>
                      </jaxb-intros>
                      


                      Have you tried this?

                      • 8. Re: Webservice - SOAP - JAXB Introductions
                        Sylvia Isler Newbie

                        I had tried a config file just like the config file illustrated in your last message. I just tried it again to double check my initial result.

                        While it is true that the illegal annotations error is avoided by using the Method construct, it is still the case that the unmarshalling of the example xml file:

                        <?xml version="1.0" encoding="UTF-8"?>
                        <UnitPrice value="40.0" xsi:noNamespaceSchemaLocation="C:\UnitPrice.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                        



                        appears to fail with JAXBIntros with the error:
                        junit.framework.AssertionFailedError: get double value error expected:<40.0> but was:<0.0>


                        Works fine with JAXB Proper, however.

                        I'm continuing to investigate because jaxb-intros will be invaluable for my project if I can get it to work.

                        If there exists a working example of similar (i.e. very simple) complexity can someone post it?

                        Regards,
                        Sylvia


                        • 9. Re: Webservice - SOAP - JAXB Introductions
                          Sylvia Isler Newbie

                          Okay, I got my simple Jaxb-Intros example to work by modifying the schema in the following fashion:

                          I changed the schema from the original:

                          <?xml version="1.0" encoding="UTF-8"?>
                          <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
                           <xs:element name="UnitPrice">
                           <xs:complexType>
                           <xs:attribute name="value" type="xs:double" use="required"/>
                           </xs:complexType>
                           </xs:element>
                          </xs:schema>



                          to
                          <?xml version="1.0" encoding="UTF-8"?>
                          <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
                           <xs:element name="UnitPrice">
                          
                           <xs:complexType>
                           <xs:sequence>
                           <xs:element name="value" type="xs:decimal" maxOccurs="1" minOccurs="0"/>
                           </xs:sequence>
                           </xs:complexType>
                          
                           </xs:element>
                          
                          </xs:schema>


                          the XML file to be unmarshalled is now:
                          <?xml version="1.0" encoding="UTF-8"?>
                          <UnitPrice xsi:noNamespaceSchemaLocation="C:\UnitPriceNew.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
                           <value>40.0</value>
                          </UnitPrice>
                          


                          The working jaxb-intros config file now looks like this:
                          <?xml version = "1.0" encoding = "UTF-8"?>
                          <jaxb-intros xmlns="http://www.jboss.org/xsd/jaxb/intros">
                           <Class name="junit.prices.UnitPrice">
                           <XmlType name = "UnitPrice"/>
                           <Field name="value">
                           <XmlElement name="value" />
                           </Field>
                           </Class>
                          </jaxb-intros>
                          


                          Again, thanks for your suggestions and thanks for Jaxb-intros.
                          Regards,
                          Sylvia


                          • 10. Re: Webservice - SOAP - JAXB Introductions
                            Tom Fennelly Master

                            OK Sylvia, this sounds like a bug in JAXB Intros re how it supports @XmlAttribute.

                            Would you mind creating a JIRA for this and attaching your original artifacts so I can have a look at it.

                            Re examples etc... if you haven't done it already, check out the unit tests.

                            Thanks for trying this stuff out and giving some feedback :-)

                            Regards,

                            T.

                            • 11. Re: Webservice - SOAP - JAXB Introductions
                              Sylvia Isler Newbie

                              Not a problem, Tom. I will do that today.
                              Regards,
                              Sylvia

                              • 12. Re: Webservice - SOAP - JAXB Introductions
                                Sylvia Isler Newbie

                                JSESB-815 has now been reported on JIRA: http://jira.jboss.com/jira/browse/JBESB-815

                                My understanding is that in JAXB there is a tight coupling between the generated schema and the annotations because the annotations can be used to generate schema from Java classes.

                                Has anyone tried directing schemagen to use jaxb-intros annotations by supplying the IntroductionsAnnotationsReader to schemagen?

                                Thanks,
                                Sylvia

                                • 13. Re: Webservice - SOAP - JAXB Introductions
                                  marius costa Newbie

                                  Hello,

                                  I want to use the JBoss JAXB implementation. Could someone be so nice to tell me where I can find a step by step tutorial?
                                  My need is to generate java classes from xml nodes.
                                  I found many tools that can do that, but I need to implement a sort of Unmarshaller in my application, that can dynamically generate java classes.

                                  Thanks in advance,
                                  grungeman

                                  • 14. Re: Webservice - SOAP - JAXB Introductions
                                    Tom Fennelly Master

                                     

                                    "marius.costa" wrote:

                                    My need is to generate java classes from xml nodes.
                                    I found many tools that can do that, but I need to implement a sort of Unmarshaller in my application, that can dynamically generate java classes.


                                    Sorry Marius... based on those comments, I'm not sure JAXB Intros is what you need. What do you expect JAXB Intros will do for you in the above scenario?

                                    As far as docs/examples, all we have at present is what's on the wiki and what's in the ESB Quickstarts:
                                    1. Wiki
                                    2. Check out the webservice_bpel quickstart. It needs to use JAXB Intros to bind a SOAP message to some EJB defined (unannotated) Java types via JBossWS.

                                    BTW... the ESB User Forum is the best place to get answers on User related questions. Thanks.

                                    1 2 Previous Next