I am building an application (deployed on Wildfly) that needs to create virtual-hosts based on how customers signup for the service. For e.g. the default application/service runs on a host called main.exampledomain.com. When customer A signs up for the service, then I need to create a virtual host A.exampledomain.com and A.exampledomain.com needs to serve exactly the same WAR/Web Content as main.exampledomain.com.
I can do this with the "host" configuration in standalone.xml --> subsystem undertow, with additional virtual-host configuration in jboss-web.xml (for all the WARs that are to be deployed).
Is there a programmatic/dynamic way to do this? Is this possible and should I do this with undertow APIs? OR Is this possible and should I use Wildfly Management APIs?
I searched through some the topics related to this, and only found discussions and answers around configuration, but not a programmatic way to do this.
Thanks and Best Regards, GPN
There are two way on doing what you need.
1) Go with management api, which can be invoked via native CLI api, REST, java ManagementClient. That would by far be the easiest as all you would need to do is call few commands to configure extra hosts and its configuration.
2) Go with custom extension / ServiceActivator This way your code would be running as a subsystem inside WildFly, with that approach you can inject UndertowService (top level undertow service) into your MSC Service and just call methods for creating servers/hosts/listeners, ... on it.
If your customization just goes and configures few extra things in undertow subsystem than probably management api way would be the simplest. However if you want to do bit deeper integration and have more power over what is customized and how I would go with custom subsystem. This would allow you to do even more interesting things like maybe modify deployment during its deployment or change some parameters for running apps etc etc...