英文:
What are the minimum requirements to get a CXF (JAX-RS) Web Resource up and running in Felix?
问题
以下是翻译好的内容:
我想在OSGI中(具体来说是在运行Apache Felix的Apache Karaf中)启动并运行实现了JAX-RS的CXF。
使用这个项目作为示例:cxf-osgi-activator,我看到工程师在设计上做出了一个决定,将jetty Karaf特性与jax-rs Karaf特性分开。这两者在运行时是否存在依赖关系?jax-rs特性是否使用了一些技巧(例如来自环境的OSGI HTTP服务)来使自己监听入站连接,还是仍然需要它?也许我的问题可以通过解释RestDeployer.java文件的第250行来回答。它从哪里获取它的Server?它是否总是获取一个,或者它是否依赖于jetty Karaf特性?
我查看了测试,似乎使用了iPojo或声明性服务(很难区分!)来减少样板代码,但代价是理解上的困难(因为它需要比我目前拥有的更深入的主题知识)。
官方的CXF文档在这个主题上不太理想。
我理解的是,它归结为以下几点:
- 一个带有JAX-RS注解的网络资源文件,将入站调用映射到本地函数
- CXF运行时(管理从接收调用到返回序列化信息的生命周期的注册服务)
- 一个服务器(Java Servlet,或者有效地说是一个为给定端口生成线程的抽象)https://stackoverflow.com/questions/39342353/purpose-of-cxf-rt-transports-http-jetty
这一切在OSGI中是如何协同工作的?我还应该提到我对Gradle最熟悉,并且Maven的pom.xml文件可能包含我不认识的内容。
我不喜欢https://stackoverflow.com/questions/28437936/cxf-web-services-with-osgi-and-karaf 的被接受答案,因为它特定于Blueprint,而我不想使用它,因为它依赖于XML。我在这里寻找一个技术性的答案,解释CXF和OSGI之间的关系(就像OSGI HTTP服务一样)。
相关链接:
- https://stackoverflow.com/questions/20331153/apache-cxf-jax-rs-felix-and-jetty
- https://stackoverflow.com/questions/39342353/purpose-of-cxf-rt-transports-http-jetty?noredirect=1&lq=1
英文:
I'd like to get CXF, which implements JAX-RS, up and running in OSGI (specifically, Apache Karaf running Apache Felix).
Using this project: cxf-osgi-activator as an example, I see that the engineer made a design decision to split up the jetty Karaf feature from the jax-rs Karaf feature. Is there a dependency between the two at runtime? Does the jax-rs feature use some trick (from the environment: OSGI HTTP Service, for example) to get itself listening for inbound connections, or is that still needed? Maybe my question can be answered with an explanation of line 250 of the RestDeployer.java file. Where is it pulling its Server from exactly? Does it always get one, or does it have a dependency on the jetty Karaf feature?
I had a look at the tests, which seem to use iPojo or Declarative Services (hard for me to tell the difference!) to cut down on boiler plate code, but at the expense of understanding (because it requires more in-depth knowledge on the subject than I have at the moment it would seem.)
The official CXF documentation is less than desirable on this subject.
My understanding is that it boils down to having:
- a web resource file annotated with JAX-RS annotations to map inbound calls to local functions
- CXF runtime (some registration service that manages the lifecycle from reception of a call to return of serialized information)
- a server (Java Servlet or effectively an abstraction thereof that spawns threads for a given port) https://stackoverflow.com/questions/39342353/purpose-of-cxf-rt-transports-http-jetty
How does this all play together in OSGI? I should also mention that am most familiar with Gradle, and the Maven pom.xml files likely contain things that I do not recognize.
I do not like the accepted answer to https://stackoverflow.com/questions/28437936/cxf-web-services-with-osgi-and-karaf, because it is specific to Blueprint, which I do not want to use because of its reliance on XML. I am looking for a technical answer here that explains the relationship between CXF and OSGI (like the OSGI HTTP Service).
Related:
答案1
得分: 1
首先,对OSGi进行简要回顾:
- OSGi是一个需要实现的规范。
- Felix/Equinox是在Karaf中找到的两种实现(请查看您的etc/config.properties,使用属性karaf.framework来检查您使用的实现,您可以进行更改!)。
- Karaf是一个管理工具,它将在您执行每个命令时在其后使用Felix/Equinox。通常,这些命令会被代理到由OSGi定义的相应行为,以用于Felix/Equinox的实现。
因此,您在链接中提到的使用Blueprint的解决方案在任何情况下仍然是有效的。但是,如果您不喜欢Blueprint,您可以查看声明性服务(Declarative Services),在其中您在“spring/blueprint”环境中定义的每个“bean”都将变成@Service/@Reference(更符合OSGi最初的思维方式),或者使用OSGi CDI集成(OSGI CDI Integration),如果您习惯了在Bundle内部使用更经典的@Named/@Inject方式进行思考,这将更加直观。
但最终,原则是完全相同的:您希望运行一个服务器,将自身注册到CXF总线(通常不应在您的Bundle中声明,您可以使用默认总线),并且您的服务将自身注册到服务器中。
英文:
Firstly, a tiny recap about OSGi :
- OSGi is a specification that needs to be implemented
- Felix/Equinox are the two implementations found in karaf (see your etc/config.properties, with the property karaf.framework to check the one you use, you can change it !)
- Karaf is an administration tool that will use Felix/Equinox behind each command you make. Often, those commands are proxied to the corresponding behaviour defined by OSGi to the Felix/Equinox implementation.
So, the solution you linked with Blueprint is still true no matter your context. However, if you don't like Blueprint, you can either check Declarative Services where each "bean" you would have defined in a "spring/blueprint" world would become @Service/@Reference (more pure to OSGi original way of thinking) or use OSGI CDI Integration which will be way more intuitive if you are used to the more classic @Named/@Inject way of thinking inside a bundle.
But in the end, it's exactly the same principles : you want to have a Server running registering itself to the CXF Bus (which normally you shouldn't declare in your bundle, you can use the default one) and your Service registering itself in Server.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论