2013-05-03 48 views
0

我在我的項目中使用Apache Felix HTTP Service Jetty 2.2.0。基於documentation,我編寫了以下代碼來更改默認服務端口。在Apache Felix中使用ConfigurationAdmin更改HttpService端口

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); 

正如你可以看到我得到的配置對象,更新屬性並調用更新method.All這個工作正常,但HttpService出於某種原因不拿起新的配置。我究竟做錯了什麼?我可以通過使用系統屬性方法更改端口。但我希望能夠使用ConfigurationAdmin來做到這一點。 我正在Equinox 3.8容器

回答

0

您可以使用,而不是菲利克斯的Http配置管理特性OSGi的系統屬性...這裏有一個例子:

"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}", 
+0

我必須以編程方式做到這一點。我的應用程序有一個Web界面,管理員可以更改端口。更改應反映在重新啓動。在equinox中,我可以使用config.ini文件來指定這些屬性,但需要手動輸入,除非有一個OSGi指定的API持久地更新系統屬性。 – nadirsaghar 2013-05-03 18:47:58