1、spring-camel.xml
<camelContext id="camelContext" xmlns="http://camel.apache.org/schema/spring">
<restConfiguration bindingMode="auto" component="restlet" port="8080" />
<!-- 用法一 -->
<rest path="/service">
<!-- 訪問路徑 http://ip:8080/service/login-->
<get uri="/login">
<to uri="direct:login" />
</get>
</rest>
<route>
<from uri="direct:login" />
<to uri="bean:product?method=login" />
</route>
</camelContext>
<bean id="product" class="com.service.CustomerService" />
2、定義服務接口
public class CustomerService {
public CustomerService() {
}
public void login(Exchange exchange){
HttpRequest request = exchange.getIn().getHeader(RestletConstants.RESTLET_REQUEST, HttpRequest.class);
Form form = request.getResourceRef().getQueryAsForm();
Map<String, String> map = form.getValuesMap();
String name = map.get("name");
String password = map.get("password");
exchange.getOut().setBody("success");
}
}
3、依賴
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-restlet</artifactId>
<version>2.16.3</version>
</dependency>