新泽西2 +灰熊2 +阿帕奇菲利克斯+德布里



您如何评价这个解决方案?

让所有这些在Apache Felix OSGi上工作,给你一个轻量级但超级强大的全OSGi解决方案。

安装Felix HTTP API和BASE然后将grizzly-httpservice-bundle-2.3.22.jar复制到bundle目录。

(如果你想先测试,然后是完整的web控制台)

启动所有服务,并确保您的web控制台工作。

你要做的是:

将Jersy 2 RI目录中的所有库复制到felix bundle目录中(可以删除那些没有真实描述的文件),并将derby.jar复制到该目录中。

这是我的工作Felix bundle目录:

aopalliance-repackage -2.4.0-b31.jar asm-debug-all-5.0.4.jargrizzly-httpservice-bundle-2.3.22.jar hk2-api-2.4.0-b31.jarhk2-locator-2.4.0-b31.jar hk2-utils-2.4.0-b31.jarjavassist-3.18.1-GA.jar javax.annotation-api-1.2.jarjavax.inject-2.4.0-b31.jar javax.servlet-api-3.0.1.jarjersey-client.jarjersey-container-servlet-core.jar jersey-container-servlet.jarjar jersey-media-jaxb.jarorg.apache.felix.gogo.command-0.14.0.jarorg.apache.felix.gogo.runtime-0.16.2.jarorg.apache.felix.gogo.shell-0.10.0.jarorg.apache.felix.http.api-3.0.0.jarorg.apache.felix.http.base-3.0.0.jar org.apache.felix.log-1.0.1.jarorg.apache.felix.webconsole-4.2.10-all.jarosgi-resource-locator-1.0.1.jar validation-api-1.1.0.Final.jar

创建基本的OSGi包…

普通的激活器重写方法看起来像这样。(不包括错误检查:)让事情更清楚一点…但应该加上)

@Override
public void start(BundleContext context) throws Exception {
ServiceReference refHttpService = 
    context.getServiceReference(HttpService.class.getName());
HttpService httpService = (HttpService) context.getService(refHttpService);
ResourceConfig rc = new ResourceConfig(CHelloResource.class);
ServletContainer servletContainer = new ServletContainer(rc);
httpService.registerServlet(
    "/j",
    servletContainer,
    null,
    httpService.createDefaultHttpContext());
}

@Override
public void stop(BundleContext context) throws Exception {
ServiceReference refHttpService = 
    context.getServiceReference(HttpService.class.getName());
HttpService httpService = (HttpService) context.getService(refHttpService);
httpService.unregister("/j");
}

:)

分配比预期的更简单?JAX-RS和OSGi的结合

我在你的代码中发现的一个错误是你使用getService而不是ungetService。

除此之外,您可能希望使用一个框架,这样您就不必摆弄低级OSGi api了。您应该查看声明性服务和蓝图。

另一件事是,你提供休息的方法非常轻量级,但也非常有限。例如,您将如何进行日志记录或安全性。所以Apache CXF可能是一个不错的选择,因为它提供了许多额外的特性。

手动搜索需要安装的包也可能相当麻烦。为此,你可能想看看Apache Karaf,它提供了许多基础设施,如http和rest支持,易于安装的特性。它比纯felix轻一点,但更容易开始使用。

最新更新