骆驼雷斯特莱特 - 上下文路径歧义



我有Spring Boot Camel应用程序,其中使用camel-restlet公开了rest api

示例路由

@Component
public class AppRoute extends RouteBuilder{
    public void configure(CamelContext context){
       from("restlet:employee?restletMethods=GET").log("${body}");
    }
}

该应用程序运行良好(spring-boot:run(。 但无法找到 API 在哪个路径下公开。日志没有信息。

我点击的每个 API 都返回 404。日志显示路由已启动。它在哪条路径下运行。我该如何更改它?

注意:请不要建议任何基于 XML 的配置。我可以放在@Configuration下的任何东西都是完美的

我会选择由 camel-restlet 组件支持的 Rest DSL,如下所示

restConfiguration().component("restlet").port(8080);
rest("/rest")
   .get("employee")
   .route().log("${body}")
   .endRest();

而这条路线会监听下面的网址 http://localhost:8080/rest/employee

编辑: 我想你可以做一些不使用Rest DSL的事情

    String host = InetAddress.getLocalHost().getHostName();
    from("restlet:http://" + host + contextPath + "/employee?restletMethods=GET").log("${body}")

端口和上下文路径可通过以下属性进行配置

camel.component.restlet.port=8686
server.servlet.context-path=/my-path

上下文路径可以在路由生成器中注入

@Value("${server.servlet.context-path}")
private String contextPath;

根据文档,restlet 端点定义中 URI 的格式应如下所示:

restlet:restletUrl[?options]

其中restletUrl应具有以下格式:

protocol://hostname[:port][/resourcePattern]

因此,在您的情况下,您可以通过以下方式定义 URI:

from("restlet:http://localhost/employee?restletMethods=GET")

这应使终结点在以下 URL 下可用:

http://localhost/employee

例如,您可以在网络浏览器中进行测试。

使用此处描述的三种配置方法中的第一种: https://restlet.com/open-source/documentation/javadocs/2.0/jee/ext/org/restlet/ext/servlet/ServerServlet.html

您应该能够使用组件对其进行自定义: https://restlet.com/open-source/documentation/javadocs/2.0/jee/api/org/restlet/Component.html?is-external=true

请参阅特定的 setServers(( 方法(或 XML 等效项(来更改主机名和端口。

最新更新