Apache Came组件rest的使用

The rest component allows to define REST endpoints using the Rest DSL and plugin to other Camel components as the REST transport.

代码如下:

<camelContext id="camelContext" xmlns="http://camel.apache.org/schema/spring">

	<restConfiguration bindingMode="auto" component="restlet" port="3387" />

	<!-- 用法一  -->
	<rest path="/api">
		<!-- 访问路径 http://127.0.0.1:3387/api/products -->
		<get uri="/products">
			<to uri="direct:products" />
		</get>

		<!-- 访问路径 http://127.0.0.1:3387/api/product/{id} -->
		<get uri="/product/{id}">
			<to uri="direct:product" />
		</get>

		<!-- 访问路径 http://127.0.0.1:3387/api/product/create(post请求方式) -->
		<post uri="/product/create">
			<to uri="bean:productNew" />
		</post>
	</rest>

	<route>
		<from uri="direct:products" />
		<setBody>
			<constant>this is products list</constant>
		</setBody>
	</route>

	<route>
		<from uri="direct:product" />
		<to uri="log:show1?showAll=true&multiline=true" />
		<setBody>
			<simple>this is product ${in.header.id}</simple>
		</setBody>
	</route>

	<!-- 用法二 -->
	<route>
		<!-- 访问地址为 http://127.0.0.1:3387/topics -->
		<from uri="rest:get:topics" />
		<setBody>
			<constant>this is topic list</constant>
		</setBody>
	</route>

	<!-- 访问地址为 http://127.0.0.1:3387/topic/111 -->
	<route>
		<from uri="rest:get:topic/{id}" />
		<setBody>
			<simple>this is topic[id=${in.header.id}]</simple>
		</setBody>
	</route>

</camelContext>


最后,加入maven依赖

<dependency>
	<groupId>org.apache.camel</groupId>
	<artifactId>camel-restlet</artifactId>
	<version>2.15.3</version>
</dependency>



  • 7
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值