简体   繁体   English

从axis2的静态上下文中获取参数

[英]Get parameter from static context in axis2

While trying to move an axis2 web-app from glassfish3 to tomcat6, I can't seem to find a way to get a config parameter from a static context. 尝试将axis2 Web应用程序从glassfish3移到tomcat6时,我似乎找不到从静态上下文中获取配置参数的方法。

In glassfish3, a system property was defined in a far away place and read from the application using System.getProperty(String name) . 在glassfish3中,系统属性是在很远的地方定义的,并使用System.getProperty(String name)从应用程序中读取。 Not only does the web agree that this is not the way to go for a web application, this trick is just not feasible for tomcat (tomcat docs) . Web不仅同意这不是Web应用程序的方法,而且这一技巧对于tomcat (tomcat docs)也是不可行的。

Reading parameters from the ServletContext is also not feasible as the app uses axis2 and I can't seem to find a way to access any kind of servlet voodoo from the static context that initializes the app's configuration. ServletContext读取参数也是不可行的,因为该应用程序使用axis2,而且我似乎找不到从初始化应用程序配置的静态上下文访问任何类型的servlet伏都教的方法。

services.xml (the file containing the service description for axis2) can contain <parameter> nodes, so that seems a nice place to configure the configuration location, but I can't seem to find a way to read these parameters from the application. services.xml (包含axis2服务描述的文件)可以包含<parameter>节点,因此这似乎是配置配置位置的好地方,但是我似乎找不到找到从应用程序读取这些参数的方法。

So in short: any ideas on how to get a value configured outside the application's code available from a static context? 简而言之:关于如何从静态上下文中获取关于如何在应用程序代码之外配置值的任何想法?


(answer listed here as StackOverflow does not allow me to answer my own question...) (此处列为StackOverflow的答案不允许我回答自己的问题...)

After scouring the Internet some more, a solution was found using an implementation of org.apache.axis2.engine.ServiceLifeCycle , which could read a parameter in the startUp -method as such: 在对Internet进行更多搜索之后,使用org.apache.axis2.engine.ServiceLifeCycle的实现找到了解决方案,该实现可以读取startUp方法中的参数,如下startUp

Parameter param = service.getParameter("name");
if (param != null) {
    saveParamValue(param.getValue().toString());
} else {
    // log warning on falling back to System.getProperty()
}

The life cycle class is attached using class="fully.qualified.ClassName" on the <service> node of the services.xml file used by axis2. 使用axis2使用的services.xml文件的<service>节点上的class="fully.qualified.ClassName"附加生命周期类。

This works, now the application just crashes on something else (but that has little to with this issue). 这行得通,现在应用程序只是崩溃了(但这与该问题几乎没有关系)。

The parameters in services.xml can be accessed by getting the ServiceContext object for the service, then calling ServiceContext.getParameter() . 可以通过获取服务的ServiceContext对象,然后调用ServiceContext.getParameter()来访问services.xml的参数。 If your service implementation class implements the Lifecycle interface, then Axis2 will call Lifecycle.init() every time it creates a new instance of the service class. 如果您的服务实现类实现了Lifecycle接口,则Axis2每次创建服务类的新实例时都会调用Lifecycle.init() The argument to Lifecycle.init() is the service's ServiceContext . Lifecycle.init()的参数是服务的ServiceContext Your init() implementation could save the context object or look up the parameters that you're interested in. 您的init()实现可以保存上下文对象或查找您感兴趣的参数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM