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程序。
- java程序代码:
@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;
}
}- 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>
相关推荐
newfarhui 2020-01-18
zhangxiaocc 2019-12-06
forliberty 2015-05-04
Adolphlwq 2017-08-10
newfarhui 2019-10-23
neweastsun 2013-12-07
Selier 2014-05-28
蜀川居 2017-10-16
jianghuchuanke 2019-09-05
zhongjcbill 2015-11-30
xiajlxiajl 2015-09-01
industry0 2014-12-08
cloudspring 2014-11-29
bobobocai 2014-07-17
LunaZhang 2012-06-11
89467606 2015-12-25
iPro 2014-05-28
LunaZhang 2011-09-14
chenhualeguan 2011-11-30