Starting an axis2 service programmatically

谁说胖子不能爱 提交于 2019-12-10 21:46:35

问题


I'm programmatically starting a service in Axis 2 (1.5), like this:

ConfigurationContext context = ConfigurationContextFactory.createConfigurationContextFromFileSystem(null, null);

AxisConfiguration cfg = context.getAxisConfiguration();
Map<String, MessageReceiver> mrMap = new HashMap<String, MessageReceiver>();
mrMap.put("http://www.w3.org/ns/wsdl/in-only", RPCInOnlyMessageReceiver.class.newInstance());
mrMap.put("http://www.w3.org/ns/wsdl/in-out", RPCMessageReceiver.class.newInstance());

AxisService service = AxisService.createService(MonitorWebService.class.getName(), cfg, mrMap, "", "http://samples", MonitorWebService.class.getClassLoader());
service.setScope("application");
cfg.addService(service);
SimpleHTTPServer server = new SimpleHTTPServer(context, 8080);
server.start();

With this set up, the service is only created when the first operation request arrives - how can I force axis to construct the service immediately?

Update: I've tried using deployService(), rather than cfg.addService(), and this starts the service up immediately. However, another instance of the service is created when the first request comes in, so that's no good either.


回答1:


A cheesy way to do it would be to have the code call the service immediately after you start the service.




回答2:


You can let one of your services implement org.apache.axis2.engine.ServiceLifeCycle. It seems you also need to announce that in the services.xml configuration, like that

<service name="MyService" scope="application" class="com.example.MyService">
...
</service>

where com.example.MyService is the class implementing ServiceLifeCycle. This class will be notified on service deployment, which usually takes place on container startup. You can hook your code to start other services (programatically) there.



来源:https://stackoverflow.com/questions/1491438/starting-an-axis2-service-programmatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!