我已经通过osgi中的http白板servlet模式构建了REST接口
@Component(service = RestComponentImpl.class)
@JaxrsResource
@HttpWhiteboardResource(pattern = "/rest/*", prefix = "static")
public class RestComponentImpl {
@Path("test")
@PUT
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public TestObject getTest(TestObject testo) {
return testo;
}
}
我通过在启动时作为json传递的osgi配置为HTTPS配置了码头
{
"org.apache.felix.http": {
"org.apache.felix.http.enable": "true",
"org.apache.felix.https.enable": "true",
"org.osgi.service.http.port.secure": "8443",
"org.apache.felix.https.keystore": "src/main/resources/jetty_key/keystore",
"org.apache.felix.https.keystore.password": "mostsecurepasswordever",
}
}
我的bndrun看起来像
index: target/index.xml;name="rest-app"
-standalone: ${index}
-runrequires:
osgi.identity;filter:='(osgi.identity=resttest.rest-services)',\
osgi.identity;filter:='(osgi.identity=org.apache.felix.metatype)',\
osgi.identity;filter:='(osgi.identity=org.apache.johnzon.core)',\
-runfw: org.eclipse.osgi
-runee: JavaSE-1.8
-runbundles: \
ch.qos.logback.classic;version='[1.2.3,1.2.4)',\
ch.qos.logback.core;version='[1.2.3,1.2.4)',\
org.apache.aries.javax.jax.rs-api;version='[1.0.0,1.0.1)',\
org.apache.aries.jax.rs.whiteboard;version='[1.0.0,1.0.1)',\
org.apache.felix.configadmin;version='[1.9.2,1.9.3)',\
org.apache.felix.http.jetty;version='[4.0.0,4.0.1)',\
org.apache.felix.http.servlet-api;version='[1.1.2,1.1.3)',\
org.apache.felix.scr;version='[2.1.0,2.1.1)',\
org.apache.servicemix.specs.annotation-api-1.3;version='[1.3.0,1.3.1)',\
org.osgi.service.jaxrs;version='[1.0.0,1.0.1)',\
org.osgi.util.function;version='[1.1.0,1.1.1)',\
org.osgi.util.promise;version='[1.1.0,1.1.1)',\
slf4j.api;version='[1.7.25,1.7.26)',\
org.apache.servicemix.specs.json-api-1.1;version='[2.9.0,2.9.1)',\
org.osgi.util.converter;version='[1.0.0,1.0.1)',\
org.apache.felix.metatype;version='[1.2.0,1.2.1)',\
resttest.rest-app;version='[0.0.1,0.0.2)',\
org.apache.felix.configurator;version='[1.0.0,1.0.1)',\
org.apache.johnzon.core;version='[1.1.0,1.1.1)'
如果没有上述提供的https配置,则servlet可以通过http://localhost:8080/test正常运行 通过配置,我仍然可以通过https://localhost:8443/rest/index.html访问静态内容,例如位于静态的index.html。 使用https配置时,该服务甚至无法启动:
Component #0 resttest.rest.RestComponentImpl, state satisfied
我无法连接到https://localhost:8443/test,得到:
HTTP ERROR 404
Problem accessing /test. Reason:
Not Found
通过两种方式,通过http://localhost:8080/system/console/或https://localhost:8443/system/console/,Apache Felix Web Console可以正常工作
有人有想法或建议吗?或任何其他想法,以快速构建使用json序列化在osgi-context中部署的REST解决方案,而又无需麻烦使用更大的框架? 谢谢。