web services - How to implement webservice version gateway with Apache Camel, CXF and Spring Boot -
i working on project use apache camel, cxf webservice implementation. on top of use spring boot (with tomcat embedded).
i developed different cxf endpoints each of web service version , can accessed in following manner http://myserver.com/service/v1
or http://myserver.com/service/v2
. working fine unless got requirement make these services working under 1 url http://myserver.com/service/commonversion
, route specific version based on xpath.
i don't know how configure , dispatch web service request common entry point version specific entry point.
i want provide some setup have application: cxf-context.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:camel="http://camel.apache.org/schema/spring" xmlns:cxf="http://camel.apache.org/schema/cxf" 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://camel.apache.org/schema/cxf http://camel.apache.org/schema/cxf/camel-cxf.xsd"> <cxf:cxfendpoint id="servicev1" address="/service/v1" servicename="s:service" serviceclass="com.myservice.v1.service" xmlns:s="http://com.myservice/servicev1"> <cxf:properties> <entry key="allowstreaming" value="false" /> </cxf:properties> </cxf:cxfendpoint> <cxf:cxfendpoint id="servicev2" address="/service/v2" servicename="s:service" serviceclass="com.myservice.v2.service" xmlns:s="http://com.myservice/servicev2"> <cxf:properties> <entry key="allowstreaming" value="false" /> </cxf:properties> </cxf:cxfendpoint> </beans>
and sample route defined cxf endpoint
@component public class servicev1 extends springroutebuilder { public void configure() throws exception { from("cxf:bean:servicev1").to("mock:processfurther") } }
my application configuration follows:
@springbootapplication @importresource({ "/cxf-context.xml" }) public class application extends springbootservletinitializer { public static void main(string[] args) { springapplication.run(application.class, args); } @override protected springapplicationbuilder configure( springapplicationbuilder application) { return super.configure(application).sources(application.class); } @bean public servletregistrationbean servletregistrationbean() { cxfservlet servlet = new cxfservlet(); return new servletregistrationbean(servlet, "/*"); } }
you surely know cxf , camel, implementations of services made routes themselves.
i rename call "servicev1" ("extends springroutebuilder") "routes" (because routes in there , not 1 service), , implement -- example make things realistic:
@component public class myroutes extends springroutebuilder { public void configure() throws exception { from("cxf:bean:servicev1") .to("direct:v1"); from("cxf:bean:servicev2") .to("direct:v2"); from("cxf:bean:servicecommon") .choice() .when(header("version").isequalto("v1")) .to("direct:v1") .otherwise() .to("direct:v2") .end(); from("direct:v1") .beanref("paymentservicev1", "buy"); from("direct:v1") .beanref("paymentservicev2", "buy"); } }
here not switch on xpath on header value -- idea. want looking for?
Comments
Post a Comment