【问题标题】:Changing HttpService port using ConfigurationAdmin in Apache Felix在 Apache Felix 中使用 ConfigurationAdmin 更改 HttpService 端口
【发布时间】:2013-05-03 16:35:03
【问题描述】:

我在我的项目中使用Apache Felix HTTP Service Jetty 2.2.0。在documentation的基础上,我写了如下代码来更改默认服务端口。

ConfigurationAdmin configAdmin = // get ConfigurationAdmin from OSGi service registry
Configuration config = configAdmin.getConfiguration("org.apache.felix.http" ,  null);
Dictionary<String, Object> props = config.getProperties();
if(props == null)
{
  props = new Hashtable<String, Object>();
}
props.put("org.osgi.service.http.port", newport);
config.update(props);

如您所见,我获取了配置对象,更新了属性并调用了更新方法。所有这些工作正常,但 HttpService 出于某种原因没有选择新配置。我究竟做错了什么?之间我可以使用系统属性方法更改端口。但我希望能够使用ConfigurationAdmin 来做到这一点。 我正在运行Equinox 3.8 容器

【问题讨论】:

    标签: java osgi apache-felix


    【解决方案1】:

    您使用 OSGi 系统属性而不是 Felix Http 配置管理属性...这是一个示例:

       "service.pid":                              "org.apache.felix.http", 
       "org.apache.felix.http.enable":             true, 
       "org.osgi.service.http.port":               8080,
       "org.apache.felix.http.debug":              true, 
       "org.apache.felix.https.debug":             true, 
       "org.apache.felix.https.enable":            true, 
       "org.osgi.service.http.port.secure":        8085,
       "org.apache.felix.https.keystore":          "@{resource:example.keystore.ks}", 
       "org.apache.felix.https.keystore.password": "@{.example.keystore}",
    

    【讨论】:

    • 我必须以编程方式进行。我的应用程序有一个 Web 界面,让管理员可以更改端口。更改应在重新启动时反映出来。在 Equinox 中,我可以使用 config.ini 文件来指定这些属性,但这需要手动输入,除非有 OSGi 指定的 API 来持续更新系统属性。
    猜你喜欢
    • 2011-10-31
    • 2013-07-27
    • 2013-03-02
    • 1970-01-01
    • 2012-01-24
    • 2016-06-03
    • 2012-08-12
    • 1970-01-01
    • 2016-12-25
    相关资源
    最近更新 更多