OSGI 容器中基于 Apache CXF 的 REST 服务器
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:
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); }
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.
- 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论