Search code examples
javaweb-servicesdeploymentapache-axis

Deploying Axis2 service groups with generic service names many times


I currently have an Axis2 web service with only one, unnamed service, for which Axis2 generates a service name using the name of the .aar file or service directory, depending on if I deploy the service exploded or not, automatically. This way I can deploy the same service with some different configuration files under different service folders in the services-directory of Axis2 without the need to configure different service names or else. Something like the following:

  • [...]axis2\WEB-INF\services\service1\META-INF\service.xml
  • [...]axis2\WEB-INF\services\service2\META-INF\service.xml
  • [...]axis2\WEB-INF\services\service3\META-INF\service.xml

In this example I would have deployed the same service three times with only different configuration files in their folder, meaning service.xml is equal for all services. If I would have provided a service name, this wouldn't work because the service names need to be unique throughout all Axis2 services.

No I want to add a second service in the above provided services, meaning each service consists of a service group with at least two services. In this case Axis2 requires a name of the service, which I would like to be something generic and the same throughout all services because I don't want to change service.xml for each deployed service. I would like to call my services something like "Upload", "Download" etc.

Axis2 can't deploy three services with the same named services by default, but what I can do is implement the interface ServiceLifeCycle and change the service name in the startUp method to something unique, e.g. by generating a random UUID or whatever. This way the service names are non-deterministic anymore, therefore I would prefer something like a naming scheme of the service deployment folder prepended to the service name configured in service.xml. Something like the following:

  • service1.Upload
  • service1.Download
  • service2.Upload
  • service2.Download [...]

It seems that I'm unable to get the deployment folder of the service during it's startUp method call, therefore do you know any other ways of deploying a service consisting of a service group with generic named services? Remember that the overall goal is convention over configuration, I simply don't want to change service.xml for each deployed service, but only deploy the services into different, unique folders.

Thanks!


Solution

  • One can use AxisService.getClassLoader().getResource() to access files in the service folder and get an absolute path to the service folder. Depending on the file one accessed you are able to simply determine the deployment folder of the service by getting parents of the accessed file and some conventions. If you have the deployment folder you can use it's name and the configured service name in the service group to set it as the new service name in the startUp method of the lifecycle class. As deployment folders already need to be unique throughout the services folder of Axis2 you have something unique for all services and can use any convention you would like for naming the deployment folders using this naming convention for the web service clients to access the service.

    The important parts are only to change the service name in the startUp method of the lifecycle class, because service names only need to be unique afterwards, and using the class loader to get a absolute path to ones service directory.

    Thanks to Kenster for using the class loader.