【问题标题】:Restlet Server Resource in Blueprint (Apache Karaf)蓝图中的 Restlet 服务器资源 (Apache Karaf)
【发布时间】:2016-02-26 15:39:03
【问题描述】:

我正在使用 Apache KarafBlueprint ,我很难将这些技术与 Restlet 集成。我找到了使用 Service Component Runtimeorg.restlet.ext.osgi 库和本教程 OSGi at REST

所以一个示例 ServerResource 将是

public SampleResource extends ServerResource {
    @Get
    public Representation represent(Representation representation){
         /* Do something crazy here */
    }
}

要将其注册到资源,它必须附加到路由器或应用程序

public class SampleRouter extends Router {
    public SampleRouter {
        super();
        attach("/sampleroute", SampleResource.class);
    }
}

如果我使用 Blueprint

注入依赖项,使用 SampleResource.class 附加它会很麻烦
public SampleResource extends ServerResource {

    private InjectedDependency dependency; /* Injected using Blueprint */

    @Get
    public Representation represent(Representation representation){
         /* Do something crazy here */
    }
}    

即使我已经注入了Blueprint Services,我如何才能附加ServerResource 或者有其他替代方法吗?

【问题讨论】:

    标签: restlet apache-karaf blueprint-osgi


    【解决方案1】:

    使用 Apache camel 定义 Restlet 集成。事实上,他们的新 REST DSL 很容易使用。 看 http://camel.apache.org/rest-dsl.html http://camel.apache.org/restlet.html

    Camel 定义了一个蓝图架构,因此您可以获得工具支持并帮助您进行蓝图定义。如果您想在 Karaf 中使用 Restlet 使用蓝图,我会采用这种方式。

    编辑: 这是 Camel Blueprint 中 Restlet 的一个准系统示例:

    <camelContext>
      <route id="RS_RestletDemo">
        <from uri="restlet:http://localhost:7000/demo/{id}" />
        <transform>
          <simple>Request type : ${header.CamelHttpMethod} and ID : ${header.id}</simple>
        </transform>
      </route> 
    </camelContext>
    

    有关更多信息,请查看 Camel 文档。我认为根据您的要求转换您的代码或创建一些东西是您学习它的一个很好的练习。

    【讨论】:

    • 您介意举一些例子或者使用Apache Camel更好地翻译上面的sn-p吗?
    猜你喜欢
    • 1970-01-01
    • 2018-02-05
    • 1970-01-01
    • 2017-02-16
    • 1970-01-01
    • 2020-05-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多