gpt4 book ai didi

java - Apache FELIX JAX-RS 更改上下文路径

转载 作者:太空宇宙 更新时间:2023-11-04 13:47:51 25 4
gpt4 key购买 nike

我目前开发了一个 REST Web 服务,并将其以捆绑形式公开在 FELIX 下。我正在使用 JAX-RS 连接器作为 Web 服务。该服务工作正常,但如果我想访问资源,模板 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”绑定(bind)到“file:/c:/Dev/Tools/Apache/Felix/bundle/mybundle-1.0.0.jar”,但实际的托管服务是从“inputstream:publisher-4.3.jar”包注册的

有什么想法吗?

最佳答案

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

修复此问题后,您可能会遇到以下问题: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);

关于java - Apache FELIX JAX-RS 更改上下文路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30647991/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com