osgi3——camel配置restlet

来源:互联网 发布:织金网络推广专员招聘 编辑:程序博客网 时间:2024/04/29 18:25

restlet是rest一种轻量级框架实现,弥补servlet的不足之处

下面请看blueprint.xml配置

<?xml version="1.0" encoding="UTF-8"?><blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"           xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0"           xmlns:camel-cxf="http://camel.apache.org/schema/blueprint/cxf"           xmlns:cxfcore="http://cxf.apache.org/blueprint/core"           xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd                                  http://camel.apache.org/schema/blueprint/cxf http://camel.apache.org/schema/blueprint/cxf/camel-cxf.xsd                                http://cxf.apache.org/blueprint/core http://cxf.apache.org/schemas/blueprint/core.xsd                                http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0 http://aries.apache.org/schemas/blueprint-cm/blueprint-cm-1.1.0.xsd">    <camelContext xmlns="http://camel.apache.org/schema/blueprint" >        <restConfiguration  component="restlet"  port="9011" host="0.0.0.0" >            <componentProperty key="restletMethods" value="GET,POST,PUT,DELETE"/>        </restConfiguration>        <rest path="/RS">            <get uri="/Test/{resources}/{param}">                <to uri="vm:Test"/>             </get>            <post uri="/Test/{resources}">                <to uri="vm:Test"/>             </post>            <delete uri="/Test/{resources}">                <to uri="vm:Test"/>            </delete>        </rest></camelContext></blueprint>Test.xml<?xml version="1.0" encoding="UTF-8"?><blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"           xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0"           xmlns:camel-cxf="http://camel.apache.org/schema/blueprint/cxf"           xmlns:cxfcore="http://cxf.apache.org/blueprint/core"           xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd                                  http://camel.apache.org/schema/blueprint/cxf http://camel.apache.org/schema/blueprint/cxf/camel-cxf.xsd                                http://cxf.apache.org/blueprint/core http://cxf.apache.org/schemas/blueprint/core.xsd                                http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0 http://aries.apache.org/schemas/blueprint-cm/blueprint-cm-1.1.0.xsd">        <bean id="test" class="com.cn.yyc.Test">    </bean>    <camelContext xmlns="http://camel.apache.org/schema/blueprint" >        <route>            <from uri="vm:Test"/>            <to uri="bean:test"/>         </route>    </camelContext></blueprint>  


Test类

import org.apache.camel.Exchange;import org.apache.commons.lang.StringUtils;import org.slf4j.Logger;import org.slf4j.LoggerFactory;public class Test implements Processor {    @Override    public void process(Exchange exchange) throws Exception {        String method = exchange.getIn().getHeader("CamelHttpMethod", String.class);                switch (method) {            case "GET":                                break;                            case "POST":                               break;                            case "DELETE":                               break;                            case "PUT":                                break;        }    }}

pom.xml需要导入的包

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

如果部署在servicemix服务器需要,安装下面插件  rest.xml

<?xml version="1.0" encoding="UTF-8"?><features xmlns="http://karaf.apache.org/xmlns/features/v1.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://karaf.apache.org/xmlns/features/v1.0.0 http://karaf.apache.org/xmlns/features/v1.0.0"> <feature name='yyc-Camel-restlet' version='1.0.0' install="auto"> <bundle start-level='50'>mvn:commons-codec/commons-codec/1.9</bundle><bundle start-level='50'>mvn:org.apache.httpcomponents/httpcore-osgi/4.3.2</bundle><bundle start-level='50'>mvn:org.apache.httpcomponents/httpclient-osgi/4.3.3</bundle><bundle start-level='50'>http://maven.restlet.com/org/restlet/osgi/org.restlet/2.2.1/org.restlet-2.2.1.jar</bundle> <bundle start-level='50'>http://maven.restlet.com/org/restlet/osgi/org.restlet.ext.httpclient/2.2.1/org.restlet.ext.httpclient-2.2.1.jar</bundle><bundle start-level='50'>mvn:org.apache.camel/camel-restlet/2.14.1</bundle> </feature> </features>





0 0
原创粉丝点击