【发布时间】:2018-12-12 09:50:58
【问题描述】:
我必须使用基于路径的路由开发 Camel REST 路由。 场景如下:我们有一个业务合作伙伴,它提供了一个用于显示文档的 REST Web 服务。 REST Web 服务部署在 3 个不同的服务器上,具体取决于地理位置。 所以我们基本上有 3 个这样的服务器:
http://north.acme.com/flowdocv2/rest/repository/attachment/{id}/findById
http://center.acme.com/flowdocv2/rest/repository/attachment/{id}/findById
http://south.acme.com/flowdocv2/rest/repository/attachment/{id}/findById
我的目标是开发一个单一骆驼路线来映射这些服务器,接受路径中的服务器名称。像这样的:
http://my.camel.com/center/repository/attachment/{id}/findById
http://my.camel.com/north/repository/attachment/{id}/findById
http://my.camel.com/south/repository/attachment/{id}/findById
我的(简化且不工作的)blueprint.xml:
<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0"
xmlns:cxf="http://camel.apache.org/schema/blueprint/cxf"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0
https://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd">
<cm:property-placeholder persistent-id="my.config.file"/>
<reference id="sharedNettyHttpServer" interface="org.apache.camel.component.netty4.http.NettySharedHttpServer"/>
<camelContext id="my_context" xmlns="http://camel.apache.org/schema/blueprint">
<restConfiguration component="netty4-http">
<endpointProperty key="nettySharedHttpServer" value="#sharedNettyHttpServer"/>
</restConfiguration>
<rest path="/center/repository">
<get uri="/attachment/{attachmentId}/findById">
<route streamCache="true" trace="true">
<to uri="http://center.acme.com/flowdocv2/rest?bridgeEndpoint=true"/>
</route>
</get>
</rest>
<rest path="/north/repository">
<get uri="/attachment/{attachmentId}/findById">
<route streamCache="true" trace="true">
<to uri="http://north.acme.com/flowdocv2/rest?bridgeEndpoint=true"/>
</route>
</get>
</rest>
</camelContext>
</blueprint>
问题是我不知道如何从路径中删除 /center、/north 或 /south,所以标头被转发到目标服务,它不知道如何处理它。 调用:
http://my.camel.com/center/repository/attachment/{id}/findById
导致在目标服务器上调用以下 URL:
http://center.acme.com/flowdocv2/rest/center/repository/attachment/{id}/findById
如何摆脱center?我不想在不同的端口上部署 3 条骆驼路线。
谢谢
【问题讨论】:
标签: rest apache-camel apache-servicemix