OSGI 容器中基于 Apache CXF 的 REST 服务器

发布于 2024-12-11 13:03:58 字数 8 浏览 0 评论 0原文

continue

I've been playing lately with REST services. I've created my service with Apache CXF and deploy it to OSGI container - which is Apache Servicemix 4.

I've managed to get it to work, but encountered a couple of caveats:

  1. the first attempt to deploy the JaxRS server in Servicemix was to use bundle Activator. Despite the fact that the class of the Activator is being run, the server does not start. I suspect my configuration is wrong. These are the contents of Activator class:

    public void start(BundleContext context) throws Exception {
        System.out.println("TEST");
        Dictionary<String, String> restProps = new Hashtable<String, String>();
    
        restProps.put("service.exported.interfaces", "*");
        restProps.put("service.exported.configs", "org.apache.cxf.rs");
        restProps.put("service.exported.intents", "HTTP");
        restProps.put("org.apache.cxf.rs.provider", MessageWriterProvider.class.getName());
        restProps.put("org.apache.cxf.rs.address", "http://localhost:8080/");
        context.registerService(MyService.class.getName(), new MyServiceImpl(), restProps);
    }
    
  2. The second problem was with REST annotations. I needed to add REST annotations both on MyServiceImpl and on MyService (interface).

Explanation for this - it was needed on because:

  • MyServiceImpl - becasue deployed project would not execute all methods - only the first one in the given class
  • MyService - because I was unable to create a client instance for this WS

Actually I've seen in CXF tests that there is no interface-implementing class example. Generally annotations are put on simple POJO methods and Client class is declared programaticly, but this seems tedious and repetitive.

  1. What's more, despite the fact, that the service is deployable and is working correctly my tests won't pass and I can't think of a reason for this. Perhaps someone could have a quick look.

I've put all the code on github: https://github.com/zygm0nt/cxf-playground in case anyone would be interested to look into this issues.

Please bear in mind, I haven't used CXF much before, so theses may be some simple problems, but searching google didn't give a definitive answers on them.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文