WSO2Con 2013 CFP Banner

How do I access resources that I put into my service/module archive file?

Q: How do I access resources that I put into my service/module archive file?

Date: Mon, 29th May, 2006
Level:
Reads: 3987
Discuss this article on Stack Overflow View | Add
admin's picture

A: Axis2 has the notion of service isolation where each service or module gets its own class loader. Using this class loader you can access any resource that you put into your service archive file. You may want to access your resources from different locations.

For example,

1. A third party module wants to access your resources, then the scenario is as follows:

   AxisService myService =
messageContext.getAxisConfiguration().getAxisService("serviceName");
or
AxisService myService = msgCtx.getAxisService();
Then you can ask for service class loader, using which you can access its resources
   ClassLoader clsLoader = myService.getServiceClassLoader();
clsLoader.getResourceAsStream("myResource");
2. To initialize service implementation class at the MessageReceiver level the following steps need to be taken
   AxisService service = msgCtx.getAxisService();   ClassLoader clsLoader = service.getServiceClassLoader();
Class.forName("serviceName",clsLoader,true);
Note : Axis2 default MessageReceiver uses the same technique to initialize service implementations 3. If you want to load your resources at the service implementation class then the scenario is as follows
   getClass().getClassLoader().getResourceAsStream("myResource");