Willem.Jiang wrote > > Just one comment, if you are using Camel 2.8.x or trunk, you can do it > without any issue. If you are using the version which is below the > 2.8.x, you can't do it that way. >
What is the issue with Camel version below 2.8.x? I'm using 2.7.3. Claus Ibsen-2 wrote > > Hi > > the <cxf:cxfEndpoint id="foo"> is a namespace handler, that will > create a CxfEndpoint and register it in the Registry with that given > id. > > In pure Java code for an unit test, you would need to enlist the CXF > endpoint manually. > For example you can use the SimpleRegistry with the > DefaultCamelContext, which is just a Map. > Then you can put the created CxfEndpoint in that map with the id of > choice. > I can put the endpoint in the registry like Claus proposed: SimpleRegistry registry = new SimpleRegistry(); CamelContext context = new DefaultCamelContext(registry); CxfEndpoint commonService = context.getEndpoint("cxf:{com.company.integration.endpoints.commonservice.url}",CxfEndpoint.class); commonService.setServiceName("{http://impl.gateway.pumax.company.com/}CommonService"); commonService.setPortName("{http://impl.gateway.pumax.company.com/}CommonServicePort"); commonService.setWsdlURL("wsdl/CommonService.wsdl"); registry.put("CommonServiceEndpoint", commonService); context.addRoutes(new myRouteBuilder()); But then I get the problem my routebuilder expexts a bean: .to("cxf:bean:CommonServiceEndpoint?dataFormat=PAYLOAD") org.apache.camel.ResolveEndpointFailedException: Failed to resolve endpoint: cxf://bean:CommonServiceEndpoint due to: java.lang.ClassCastException: Cannot cast org.apache.camel.component.cxf.CxfEndpoint to org.apache.camel.component.cxf.spring.CxfEndpointBean So I tried to add a CxfEndpointBean to the registry instead: SimpleRegistry registry = new SimpleRegistry(); CxfEndpointBean commonService = new CxfEndpointBean(); commonService.setAddress("{com.company.integration.endpoints.commonservice.url}"); commonService.setServiceName(new QName("http://impl.gateway.pumax.company.com/", "CommonService")); commonService.setEndpointName(new QName("http://impl.gateway.pumax.company.com/", "CommonServicePort")); commonService.setWsdlURL("wsdl/CommonService.wsdl"); registry.put("CommonServiceEndpoint", commonService); SpringCamelContext context = new SpringCamelContext(); context.setRegistry(registry); context.addRoutes(new myRouteBuilder()); But somewhere the registering went wrong, I think, because I get a ResolveEndpointFailedException: org.apache.camel.ResolveEndpointFailedException: Failed to resolve endpoint: cxf://bean:CommonServiceEndpoint due to: null at org.apache.camel.impl.DefaultCamelContext.getEndpoint(DefaultCamelContext.java:450) at org.apache.camel.impl.DefaultCamelContext.getEndpoint(DefaultCamelContext.java:464) at com.company.integrator.router.myRouteBuilder.configure(myRouteBuilder.java:80) at org.apache.camel.builder.RouteBuilder.checkInitialized(RouteBuilder.java:322) at org.apache.camel.builder.RouteBuilder.configureRoutes(RouteBuilder.java:277) at org.apache.camel.builder.RouteBuilder.addRoutesToCamelContext(RouteBuilder.java:263) at org.apache.camel.impl.DefaultCamelContext.addRoutes(DefaultCamelContext.java:613) at com.company.integrator.routertest.ConvertRouterTest.testConvert(ConvertRouterTest.java:87) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184) at org.junit.runners.ParentRunner.run(ParentRunner.java:236) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197) Caused by: java.lang.NullPointerException at org.apache.cxf.configuration.spring.ConfigurerImpl.initWildcardDefinitionMap(ConfigurerImpl.java:81) at org.apache.cxf.configuration.spring.ConfigurerImpl.addApplicationContext(ConfigurerImpl.java:245) at org.apache.cxf.configuration.spring.ConfigurerImpl.setApplicationContext(ConfigurerImpl.java:225) at org.apache.cxf.configuration.spring.ConfigurerImpl.<init>(ConfigurerImpl.java:75) at org.apache.camel.component.cxf.CxfSpringEndpoint.init(CxfSpringEndpoint.java:68) at org.apache.camel.component.cxf.CxfSpringEndpoint.<init>(CxfSpringEndpoint.java:61) at org.apache.camel.component.cxf.CxfComponent.createEndpoint(CxfComponent.java:64) at org.apache.camel.impl.DefaultComponent.createEndpoint(DefaultComponent.java:75) at org.apache.camel.impl.DefaultCamelContext.getEndpoint(DefaultCamelContext.java:432) ... 29 more -- View this message in context: http://camel.465427.n5.nabble.com/How-to-set-endpoint-id-in-Java-dsl-tp5080518p5085640.html Sent from the Camel - Users mailing list archive at Nabble.com.