Using XML as config-property value

35 Views Asked by At

I'm working on a resource adapter that listens for incoming UDP requests. The configuration I'm using right now is hostname and port and it's been working for me so far

<resource-adapter id="barrier-ra" statistics-enabled="true">
    <module slot="main" id="..."/>
    <transaction-support>NoTransaction</transaction-support>

    <config-property name="hostname">0.0.0.0</config-property>
    <config-property name="port">9870</config-property>
    
    <connection-definitions>
        <connection-definition class-name="..." jndi-name="..." connectable="false" tracking="true" pool-name="Barrier" enlistment="false" enlistment-trace="false"/>
    </connection-definitions>
</resource-adapter>

However, now I need to add the ability to start multiple worker threads listening for a well-defined address and port. This in turn requires the introduction of an interface for configuring a list of address/port pairs.

I was thinking something like this to get as a String in the resource adapter and then parse manually:

<resource-adapter id="barrier-ra" statistics-enabled="true">
    <module slot="main" id="..."/>
    <transaction-support>NoTransaction</transaction-support>
    
    <config-property name="hosts">
        <host name="host 1">
            <address>192.168.40.1</address>
            <port>9870</port>
        </host>
        <host name="host 2">
            <address>192.168.40.2</address>
            <port>9870</port>
        </host>
        <host name="host 3">
            <address>192.168.40.3</address>
            <port>9870</port>
        </host>
    </config-property>
    
    <connection-definitions>
        <connection-definition class-name="..." jndi-name="..." connectable="false" tracking="true" pool-name="Barrier" enlistment="false" enlistment-trace="false"/>
    </connection-definitions>
</resource-adapter>

But apparently config-property only accepts strings and I get a config parsing error when trying to start the server.

Message: elementGetText() function expects text only elment but START_ELEMENT was encountered.

Of course, I have the option of using an external configuration file, but I would like to have all the resource adapter configuration in one place.

I'm using wildfly-26 so I'm looking for a solution specifically for that (or a newer version)


Edit: I found a solution how to pass the xml as a plain string.
<resource-adapter id="barrier-ra" statistics-enabled="true">
    <module slot="main" id="..."/>
    <transaction-support>NoTransaction</transaction-support>
    
    <config-property name="hosts">
        <![CDATA[
            <host name="host 1">
                <address>192.168.40.1</address>
                <port>9870</port>
            </host>
            <host name="host 2">
                <address>192.168.40.2</address>
                <port>9870</port>
            </host>
            <host name="host 3">
                <address>192.168.40.3</address>
                <port>9870</port>
            </host>
        ]]>
    </config-property>
    
    <connection-definitions>
        <connection-definition class-name="..." jndi-name="..." connectable="false" tracking="true" pool-name="Barrier" enlistment="false" enlistment-trace="false"/>
    </connection-definitions>
</resource-adapter>
0

There are 0 best solutions below