【问题标题】:Apache FELIX JAX-RS Change context pathApache FELIX JAX-RS 更改上下文路径
【发布时间】:2015-06-04 15:26:07
【问题描述】:

我目前正在开发一个 REST Web 服务并在 FELIX 下以捆绑包的形式公开它。我正在为 Web 服务使用 JAX-RS 连接器。 该服务工作正常,但如果我想访问资源模板 URL 是

http://IP:PORT/services/path/to/my/resource

目标是将上下文路径服务更改为通过 URL 访问资源 像 http://IP:PORT/path/to/my/resource

我尝试更改管理员配置,如 JAX-RS 连接器的常见问题解答中所述,但我仍然遇到问题

ServiceReference configurationAdminReference = bundleContext.getServiceReference(ConfigurationAdmin.class.getName());
if(configurationAdminReference != null) {
    ConfigurationAdmin confAdmin = (ConfigurationAdmin) bundleContext.getService(configurationAdminReference);
    if(confAdmin != null) {
        Configuration configConnector = confAdmin.getConfiguration("com.eclipsesource.jaxrs.connector",null); 
        Dictionary<String, String> props = configConnector.getProperties()
        if (props == null) {
            Dictionary<String, String> props = new Hashtable<String,String>();
         }
        props.put("root","/");    
        configConnector.update(props);
    }
}

我已经看到有人在这个论坛上遇到过这个问题,但在我的情况下它并没有解决问题 我可以在 felix web 控制台中看到以下错误消息

错误:PID“com.eclipsesource.jaxrs.connector”绑定到“file:/c:/Dev/Tools/Apache/Felix/bundle/mybundle-1.0.0.jar”,但实际托管服务是从“inputstream:publisher-4.3.jar”包注册

有什么想法吗?

【问题讨论】:

    标签: java rest jax-rs apache-felix


    【解决方案1】:

    configConnector.getProperties() 返回 null 时,您的代码会导致 NullPointerException,因为您在 if 子句中声明了一个新变量 props,而不是将新的哈希表实例分配给现有变量。

    一旦你解决了这个问题,你可能会遇到这个问题:https://github.com/hstaudacher/osgi-jax-rs-connector/issues/114

    以下代码有效:

        org.osgi.service.cm.Configuration configuration = configurationAdmin.getConfiguration("com.eclipsesource.jaxrs.connector", null);
        Dictionary props = configuration.getProperties();
        if (props == null) {
            props = new Hashtable();
        }
        props.put("root", "/jaxrs");
        configuration.update(props);
    

    【讨论】:

      猜你喜欢
      • 2013-12-18
      • 2011-06-14
      • 1970-01-01
      • 2017-09-02
      • 2014-09-11
      • 1970-01-01
      • 2019-01-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多