11 Replies Latest reply on Oct 7, 2008 10:29 AM by Ashok Sharma

    Generate jboss-esb.xml using XmlBeans

    Mihai Anescu Newbie


      I see nobody posted a question about this, so here we go.

      I tried to generate a jboss-esb.xml file usign the XmlBeans provided in the binaries.

      I have some problems which I suspect come from those XmlBeans.

      For example, I have this part of code:

      FtpProviderDocument ftpProviderDoc = FtpProviderDocument.Factory.newInstance();
       FtpProviderDocument.FtpProvider ftpProvider = FtpProviderDocument.FtpProvider.Factory.newInstance();
      //...add properties on ftpProvider
       FtpBusDocument ftpBusDoc = FtpBusDocument.Factory.newInstance();
       FtpBusDocument.FtpBus ftpBus = FtpBusDocument.FtpBus.Factory.newInstance();
      //...add properties on ftpBus
       FtpMessageFilterDocument.FtpMessageFilter ftpMsgFilter = FtpMessageFilterDocument.FtpMessageFilter.Factory.newInstance();
      //...add properties on ftpMsgFilter

      So, I'm adding specific Ftp* objects. I expected this outcome from the root object:
      <ftp-provider name="gate_Ftp" hostname="ftp.domain.net">
       <ftp-bus busid="gate_Ftp">
       <ftp-message-filter username="user" password="password" passive="false" directory="/"/>

      But instead I get this one:
       <provider name="gate_Ftp" hostname="ftp.domain.net">
       <bus busid="gate_Ftp">
       <ftp-message-filter directory="/" passive="false" password="password" username="user"/>

      The same things happens with JmsBus, JmsProvider, JmsListener, FtpBus, FtpProvider, FtpListener and probably with other object.

      Can anyone shed some light? Am I doing something wrong? Why does the FtpMessageFilter remains ok and the rest do not?

      I noticed that for example the FtpProviderDocument.FtpProvider class does not have specific methods to add a FtpBusDocument.FtpBus bus, only the generic methods inherited from the ProviderDocument.Provider

        • 1. Re: Generate jboss-esb.xml using XmlBeans
          Mihai Anescu Newbie

          Also another thing that poped out.

          In the XSD the property is defined like this:

          <xsd:element name="property">
           <xsd:documentation xml:lang="en">A simple name-value pair.</xsd:documentation>
           <xsd:extension base="xsd:anyType">
           <xsd:attribute name="name" use="required" type="xsd:string"/>
           <xsd:attribute name="value" type="xsd:string"/>

          But in the Message Action Guide we have this section:
          <action name="routeAction?
           <property name="destinations">
           <route-to service-category="ExpressShipping"
           <route-to service-category="NormalShipping"

          Which off course works fine, and guess what, I have to generate exactly this kind of code :(. But I can't, because the Property class only knows about the XSD definition (Name + Value, both String).

          Help! Anybody?

          • 2. Re: Generate jboss-esb.xml using XmlBeans
            Burr Sutter Master

            Unfortunately, I don't have any help/answers for your inquiry but I do have a related question. :-)

            Why are you doing this? Are you building tool to generate a jboss-esb.xml for developers? End-users?


            • 3. Re: Generate jboss-esb.xml using XmlBeans
              Mihai Anescu Newbie


              I am building a tool that will generate an entire jboss-esb.xml file. In fact it will generate later on an entire .esb archive & deploy it on a JBoss Server (that means also some other xml files will need generated...).

              Unfortunatelly I stumbled upon those 2 problems, which so far have no answer.

              One question. Do the jboss-esb.xml you're using for samples & so on pass the validation against the XSD? Since I have found no "route-to" element described in the XSD, my guess would be "no"?

              • 4. Re: Generate jboss-esb.xml using XmlBeans
                Kurt Stam Master

                Hi Anescu,

                1. In fact the entire jbossesb-xml is validated against the xsd.

                2. The action configuration takes properties. That's all what is validated. I mean if you take a look at:

                <property name="destinations">
                 <route-to service-category="ExpressShipping" service-name="ExpressShippingService"/>
                 <route-to service-category="NormalShipping"

                You can see this action only has one property with name "destination". They maker of the action may decide what needs to go IN the property.
                Here we have 2 route-to subelements. The subelements are NOT in the xsd, only the property element is.

                3. an ftp-provider is a provider as defined in the xsd:

                <xsd:element name="ftp-provider" substitutionGroup="jesb:provider">

                So xmlbeans is somewhat right to turn this into a provider. I'm a little surprised though that it wouldn't take the more specific version of the provider (ftp-provider) when it writes out the xml. This may be an xmlbeans bug.

                In our next major release we will likely move to JAXB. So you could try using that, maybe it will give you better results.

                Well hopefully this will help you in the right direction.


                • 5. Re: Generate jboss-esb.xml using XmlBeans
                  Mihai Anescu Newbie

                  Hello Kurt,

                  Yes, I saw that you can put all kind of stuff into the property, which is ok, and we have used it to define some stuff too, my problem is that in the XSD the property element is defined as having 2 attributes: name & value (as i mentioned in a previous post). And that the Property java object (which was generated from the XSD, as far as I know about xmlbeans) contains methods for those two attributes. So, the java code doesn't allow me to add inner XML code to the property. And in fact that is what I would need. So the Property class has to change a bit?

                  About the other objects: The behavior is similar in many of them. I tried for example to "print" each object as it gets populated, and the result differ very much.
                  See here is some code extracted from various objects:
                  This would be the Java code, and below is the result.

                  //jmsBus is a JmsBusDocument.JmsBus object already filled with data
                   JmsBusDocument jmsBusDoc = JmsBusDocument.Factory.newInstance();
                   JmsProviderDocument jmsProviderDoc = JmsProviderDocument.Factory.newInstance();

                  And the result:
                  // -> here the tag is correct (jms-bus)
                  <jms-bus busid="myJmsQueue" xmlns="http://anonsvn.labs.jboss.com/labs/jbossesb/trunk/product/etc/schemas/xml/jbossesb-1.0.1.xsd">
                   <jms-message-filter dest-name="queue/myJmsQueue" dest-type="QUEUE"/>
                  // -> here the tag is no longer correct (bus). But it keeps all the attributes
                  <jms-provider name="myJmsQueue" connection-factory="ConnectionFactory" jndi-context-factory="org.jnp.interfaces.NamingContextFactory" jndi-URL="localhost" jndi-pkg-prefix="" xmlns="http://anonsvn.labs.jboss.com/labs/jbossesb/trunk/product/etc/schemas/xml/jbossesb-1.0.1.xsd">
                   <bus busid="myJmsQueue">
                   <jms-message-filter dest-name="queue/myJmsQueue" dest-type="QUEUE"/>

                  If I extract code from a parent of the JmsProvider then also the jms-provider tag changes into provider. I don't know if it's an xmlbeans bug or is something from inside you're code, I started to play with xmlbeans a few days ago.

                  I'll probably take a look at JAXB, although I can generate the file by using a plain StringBuffer as well.

                  • 6. Re: Generate jboss-esb.xml using XmlBeans
                    Kurt Stam Master

                    I have two comments:

                    1. It's the 'value' that is set in the property tags. If that is not clear in the xsd then we should fix that.

                    2. All the classes (like JmsBusDocument) are generated from the xsd using xmlbeans. So it's not really our code..


                    • 7. Re: Generate jboss-esb.xml using XmlBeans
                      Ole Matzura Novice


                      you can always modify the underlying xml (if you want to add "custom content") by getting the XmlBeans objects' domNode and working from there.. ie

                      Element elm = (Element)jmsBus.getDomNode();
                      .. standard dom manipulation stuff, add attributes, children etc. ...

                      Hope this helps!



                      • 8. Re: Generate jboss-esb.xml using XmlBeans
                        Mihai Anescu Newbie


                        thanks, that helps me with the problem mentioned in the #2 post. I still don't have any solution for the problem mentioned in my #1 post...

                        • 9. Re: Generate jboss-esb.xml using XmlBeans
                          Derek Adams Newbie

                          I was looking at creating a JAXB model for the Eclipse tooling stuff, so we may want to coordinate on this. I know you can feed JAXB an XSD and it will generate an annotated object model. It does handle the xsd:anyType elements pretty well (hands you a generic DOM node if I remember). Anyway, I am supposed to be porting the existing Flex config editor over to Eclipse in the next couple of weeks, so we may be able to share the underlying JAXB model.

                          • 10. Re: Generate jboss-esb.xml using XmlBeans
                            Mark Little Master

                            Thanks Derek. An Eclipse plug-in would be a great way to go with this.

                            • 11. Re: Generate jboss-esb.xml using XmlBeans
                              Ashok Sharma Newbie

                              Hi All,
                              i am new to Jbossesb, i want to create one esb service where i want to read FTP parameters from database whenever there is any change in the ftp parameters (hostname, username, password, diractory etc) in database configuration file jboss-esb.xml should be updated automatically.

                              If any one can provide me sample code to implement this would be very much helpfull for me.

                              Thanks in advance.