我最近升级到骆驼2.14.1并一直在玩新的REST DSL。在我的骆驼背景Camel REST DSL是否支持Restlet Servlet?
<!-- Restlet Servlet -->
<servlet>
<servlet-name>RestletServlet</servlet-name>
<servlet-class>org.restlet.ext.spring.SpringServerServlet</servlet-class>
<init-param>
<param-name>org.restlet.component</param-name>
<param-value>RestletComponent</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>RestletServlet</servlet-name>
<url-pattern>/rs/*</url-pattern>
</servlet-mapping>
而这个:在升级之前,我在web.xml中使用的Restlet一个servlet容器,即中与此
<bean id="RestletComponent" class="org.restlet.Component" />
<bean id="RestletComponentService" class="org.apache.camel.component.restlet.RestletComponent">
<constructor-arg index="0">
<ref bean="RestletComponent" />
</constructor-arg>
</bean>
这并不与REST DSL工作。
我用这个简单的路线测试它:
<rest>
<get uri="/hello">
<to uri="direct:hello"/>
</get>
</rest>
<route id="hello">
<from uri="direct:hello"/>
<setBody><constant>Dolly</constant></setBody>
</route>
其余DSL成功找到我的web.xml中定义的RestletComponent豆,但豆类不具备与之关联的camelContext,所以当代码试图访问上下文时,我得到一个空指针异常。
基本上,我开始怀疑REST DSL与servlet容器内的Restlet不兼容。我想托管servlet容器来处理传入的请求,我不想为我的骆驼上下文产生单独的restlet服务器进程(在新的端口上)。
我运气不好吗?
OK,使事情变得更容易,我是从现有的例子之一开始:骆驼例如-的Restlet-JDBC其采用的Restlet,所以它采用了全新的其余DSL改变它。
这里的XML-dsl.xml文件:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd">
<import resource="common.xml" />
<camelContext xmlns="http://camel.apache.org/schema/spring">
<rest>
<post uri="/persons">
<route>
<setBody>
<simple>insert into person(firstName, lastName) values('${header.firstName}','${header.lastName}')
</simple>
</setBody>
<to uri="jdbc:dataSource"/>
<setBody>
<!--<simple>select * from person ORDER BY id desc OFFSET 1 ROWS</simple>-->
<simple>select * from person where id in (select max(id) from person)</simple>
</setBody>
<to uri="jdbc:dataSource"/>
</route>
</post>
<get uri="/persons/{personId}">
<route>
<setBody>
<simple>select * from person where id = ${header.personId}</simple>
</setBody>
<to uri="jdbc:dataSource"/>
</route>
</get>
<get uri="/persons">
<route>
<setBody>
<constant>select * from person</constant>
</setBody>
<to uri="jdbc:dataSource"/>
</route>
</get>
</rest>
</camelContext>
</beans>
这是行不通的。它java.net.SocketException异常:权限被拒绝
你是如何设置spring来加载骆驼上下文的?你能和我们分享你的骆驼环境吗? –
@WillemJiang,为了使这个更清洁,我尝试使用camel-example-restlet-jdbc中的REST dsl。这样我可以看到它是我的设置还是其余的dsl。 –
我认为这个问题很大程度上与RestletComponent的createConsumer()方法总是创建一个绝对uri的端点有关,即使相对的uris在camel-restlet中受支持 –