在Apache Felix中使用ConfigurationAdmin更改HttpService端口

时间:2013-05-03 16:35:04

标签: java osgi apache-felix

我在我的项目中使用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由于某些原因没有获取新配置。我究竟做错了什么?之间我可以使用System属性方法更改端口。但我希望能够使用ConfigurationAdmin来做到这一点。 我正在运行Equinox 3.8容器

1 个答案:

答案 0 :(得分:0)

您使用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}",