Inject values from application.yaml to XML files

113 views
Skip to first unread message

Kavya BR

unread,
Apr 4, 2024, 6:21:13 AM4/4/24
to jPOS Users
Hi all,

I am trying to inject values of my host and port from application.yaml file to my xml file.
I was planning to use parameter-factory ( org.jpos.q2.iso.ParameterFactory) but not able to find this dependency. Help ?

10_network_channel.xml

<channel-adaptor name=‘my-channel' class="org.jpos.q2.iso.ChannelAdaptor" logger="Q2">
    <channel class="org.jpos.iso.channel.NACChannel"
             packager="org.jpos.iso.packager.GenericPackager"
             type="server"
             logger="Q2"
             realm="my-channel-setup"
             parameter-factory="parameter-factory">
        <property name="host" value="${server.host}"/>
        <property name="port" value="${server.port}"/>
    </channel>
    <in>my-send</in>
    <out>my-receive</out>
    <ready>my-channel.ready</ready>
    <reconnect-delay>10000</reconnect-delay>
</channel-adaptor>


application.yml
server:
  host: localhost
  port: 8080





---
The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material. Any review, re-transmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender, delete the material from any computer and destroy all copies.

Alejandro Revilla

unread,
Apr 4, 2024, 2:42:24 PM4/4/24
to jpos-...@googlegroups.com

You can do that out of the box if you place your YML file in cfg/default.yml.

You can keep your existing cfg/application.yml name if you use the -Eapplication parameter when you call Q2.




--
--
jPOS is licensed under AGPL - free for community usage for your open-source project. Licenses are also available for commercial usage. Please support jPOS, contact: sa...@jpos.org
---
You received this message because you are subscribed to the Google Groups "jPOS Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jpos-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jpos-users/daabbb2b-267c-43d0-a20e-ec2341b521e5n%40googlegroups.com.

Andrés Alcarraz

unread,
Apr 4, 2024, 4:25:41 PM4/4/24
to jpos-...@googlegroups.com

If you are trying to do this for a Spring Boot application, I see two options:

  1. This one is more of a hack, at build time, create a src/dist/cfg/default.yml as a copy of your application.yaml. A symbolic link in the developer environment would also work, or you can maintain the name and use the -Eapplication option that Alejando mentions in the other response.
  2. At the start of your Spring application, set the server.host and server.port system properties from the content of the Spring properties before starting Q2.

Other options may involve something like extracting the application.yaml at runtime and place it in cfg before starting Q2, I wouldn’t recommend this one. Personally, I would go for something like 2, but it’s more of a question of taste.

You could even define an Environment Provider to resolve environment properties from the Spring context, I believe this option could be a good one, but would require more experimentation and deeper jPOS knowledge.

Best regards.

Andrés Alcarraz

Reply all
Reply to author
Forward
0 new messages