You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by ranetruptiv <ra...@gmail.com> on 2014/04/16 09:17:27 UTC

Issue while dynamically adding cxfEndpoint and its routes using Camel

Hello,

I am newbie to Camel.
In my current project, we are using cxfEndpoint as consumer and 
dynamically building the spring-ws producer for posting request on
downstream system.

The spring-ws  producer is built by retrieving the data from database and
then forming routes. These routes are then added to the CamelContext.

I also want to dynamically add cxfEndpoint as producer and eventually build
the routes for it.

Currently, I have written below code in DynaRouteBuilder, which is invoked
from camel-context.xml

/public class DynaRouteBuilder {

	public void buildDynamicRoute(Exchange exchange){
		RoutesDefinition routes;		
		StringBuffer endpointRoute = new StringBuffer("<routes
xmlns=\"http://camel.apache.org/schema/spring\">"); 
		endpointRoute.append(" <route id=\"endpointRoute\"><from
uri=\"cxf:bean:1\"/><to uri=\"direct-vm:processMessage\"/></route>")	 
		.append("</routes>");
		
		SimpleRegistry registry = new SimpleRegistry();
		CxfEndpoint cxfEndpoint = new CxfEndpoint();
		cxfEndpoint.setAddress("/CustomerRequestImplPort"); 
		try {
			cxfEndpoint.setServiceClass("custDetail.CustomerRequestPT");
		} catch (ClassNotFoundException e2) {
			// TODO Auto-generated catch block
			e2.printStackTrace();
		}
		cxfEndpoint.setWsdlURL("wsdl/CustomerRequest.wsdl");
		
		try {
			
			registry.put("1", cxfEndpoint);
			CamelContext camelContext = new DefaultCamelContext(registry);			
			camelContext.addEndpoint("1", cxfEndpoint);
			routes = RoutesXml.loadRoutesFromXML(endpointRoute.toString());
			System.out.println(routes.getRoutes());			
			camelContext.addRouteDefinitions(routes.getRoutes());			
			camelContext.start();
			
		} catch (Exception e2) {
			// TODO Auto-generated catch block
			e2.printStackTrace();
		}
	}
}/


Camel-context.xml

/<route>
  			<from uri="timer://foo?repeatCount=1"/>
  			<to uri="sql:{{sql.routeQuery}}" />
  			<to uri="bean:dynaRouteBuilder?method=buildDynamicRoute"/>
		</route>/

When the context is loaded, i get below server logs

/
12:25:40,620 INFO  [stdout] (Camel (camel) thread #1 - timer://foo)
[Route(endpointRoute)[[From[cxf:bean:1]] -> [To[direct-vm:processMessage]]]]

12:25:40,621 INFO  [org.apache.camel.impl.DefaultCamelContext] (Camel
(camel) thread #1 - timer://foo) Apache Camel 2.12.2 (CamelContext: camel-3)
is starting
12:25:40,621 INFO  [org.apache.camel.management.ManagedManagementStrategy]
(Camel (camel) thread #1 - timer://foo) JMX is enabled
12:25:40,635 INFO  [org.apache.camel.impl.converter.DefaultTypeConverter]
(Camel (camel) thread #1 - timer://foo) Loaded 201 type converters
12:25:40,652 INFO  [org.apache.camel.impl.DefaultCamelContext] (Camel
(camel) thread #1 - timer://foo) StreamCaching is not in use. If using
streams then its recommended to enable stream caching. See more details at
http://camel.apache.org/stream-caching.html
12:25:40,692 INFO 
[org.apache.cxf.service.factory.ReflectionServiceFactoryBean] (Camel (camel)
thread #1 - timer://foo) Creating Service
{http://cmp.custDetail/}CustomerRequestPTService from WSDL:
wsdl/CustomerRequest.wsdl
12:25:40,816 INFO  [org.apache.cxf.endpoint.ServerImpl] (Camel (camel)
thread #1 - timer://foo) Setting the server's publish address to be
/CustomerRequestImplPort
12:25:40,823 INFO  [org.apache.camel.impl.DefaultCamelContext] (Camel
(camel) thread #1 - timer://foo) Route: endpointRoute started and consuming
from: Endpoint[cxf://bean:1]
12:25:40,825 INFO  [org.apache.camel.impl.DefaultCamelContext] (Camel
(camel) thread #1 - timer://foo) Total 1 routes, of which 1 is started.
12:25:40,825 INFO  [org.apache.camel.impl.DefaultCamelContext] (Camel
(camel) thread #1 - timer://foo) Apache Camel 2.12.2 (CamelContext: camel-3)
started in 0.205 seconds
/


When I invoke the service at
http://localhost:8080/customerapp/CustomerRequestImplPort, i get below error

/12:26:13,115 WARNING [org.apache.cxf.transport.servlet.ServletController]
(http-localhost/127.0.0.1:8080-1) Can't find the the request for
http://localhost:8080/customerapp/CustomerRequestImplPort's Observer/


Can someone please help finding the issue, here.


Thanks,
Trupti



--
View this message in context: http://camel.465427.n5.nabble.com/Issue-while-dynamically-adding-cxfEndpoint-and-its-routes-using-Camel-tp5750281.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Issue while dynamically adding cxfEndpoint and its routes using Camel

Posted by ranetruptiv <ra...@gmail.com>.
I was able to invoke
http://localhost:8080/customerapp/CustomerRequestImplPort. 
I replaced
/CamelContext camelContext = new DefaultCamelContext(registry);/
	with  
/SpringCamelContext contextSpring = (SpringCamelContext)
exchange.getContext();
contextSpring.setRegistry(registry);/


Thanks,
Trupti



--
View this message in context: http://camel.465427.n5.nabble.com/Issue-while-dynamically-adding-cxfEndpoint-and-its-routes-using-Camel-tp5750281p5750300.html
Sent from the Camel - Users mailing list archive at Nabble.com.