Apache CXF结合camel blueprint demo

cxf框架是apache的web service框架,提供简单易用的webservice功能,同时可以实现restful风格的soa。

camel也是apache出品,他将request到response以route的形式进行处理,同时将response返回给请求端。这一点类似前端emberjs的思路,每一个请求都通过一个route作为入口,然后根据XML的配置经过每个处理,最后将结果返回。

为了方便实用和配置,camel同时提供了blueprint的配置方式,将请求配置到xml文件中,从而可以更加清晰的了解访问路由,利于维护。

 

本例是基于jboss fuse, karaf的osgi程序。

  1. java程序代码:
  2. @Path("/")
    @Consumes(MediaType.APPLICATION_JSON)
    public interface LoginEndPoint{
    
    @POST
    @Produces(MediaType.APPLICATION_JSON)
    @Path("/addCustomer")
    public String addCustomer(CustomerVo cust);
    
    @POST
    @Produces(MediaType.APPLICATION_JSON)
    @Path("/loginCustomer/{name}")
    public CustomerVo loginCustomer(@PathParam("name")String name);
    }
     具体business实现
    public class LoginEndPointImpl implements LoginEndPoint{
    
    @Override
    public String addCustomer(CustomerVo cust){
    
    return null;
    }
    
    @Override
    public CustomerVo loginCustomer(String name){
    
    return null;
    }
    }
     
    public interface Processor{
    
    public Object process(String name);
    }
     
    Processor 实现
    public LoginCustomerProcessor implements Processor{

    public Object process(String name){

    CustomerVo cust=new CustomerVo();
    cust.setName(name);
    cust.setStatus("Y");
    return cust;
    }
    }
     
  3. blueprint.xml默认配置路径在./resources/OSGI-INF/blueprint/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:jaxws="http://cxf.apache.org/blueprint/jaxws" 
xmlns:jaxrs="http://cxf.apache.org/blueprint/jaxrs" 
    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://camel.apache.org/schema/blueprint
http://camel.apache.org/schema/blueprint/camel-blueprint.xsd
">

<bean id="loginService" class="com.XX.endpoint.LoginEndPointImpl"/>
<bean id="loginProcessor" class="com.XX.processor.LoginCustomerProcessor"/>

<cxf:rsServer id="rsServer" address="login" serviceClass="com.XX.endpoint.LoginEndPointImpl"/>

<camelContext id="loginContext" xmlns="http://camel.apache.org/schema/blueprint">
<route id="login">
<from uri="cxfrs://bean://rsServer"/>
<recipientList>
  <simple>direct:${header.operationName}</simple>
</recipientList>
</route>

<route id="loginCustomer">
  <from uri="direct:loginCustomer"/>
  <process ref="loginProcessor"></process>
</route>
</camelContext>
</blueprint>
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值