Forum Home » Fuse Distributions » Fuse Mediation Router

Thread: CXF Endpoint Creation

 

Permlink Replies: 15 - Last Post: Nov 15, 2011 9:12 PM Last Post By: gt6081a
gt6081a

Posts: 34
Registered: 07/22/11
CXF Endpoint Creation
Posted: Nov 4, 2011 7:32 PM
  Click to reply to this thread Reply
Attachment log.txt (25.3 KB)
Since the other thread got a wee bit cluttered I figured I would start one anew regarding my current effort towards creating a cxf endpoint to be leveraged by camel in future routes.

I have pretty much taken the example striaght out of my trusty Camel In Action book. At any rate I am getting an error that I am unfamiliar with which I have attached. I am not familiar with referencing the OSGI classpath xml files so I am sure it is an issue surrounding those.

The beans.xml file is:
<?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:cxf="http://camel.apache.org/schema/cxf"
xmlns:sfdc="urn:enterprise.soap.sforce.com"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://camel.apache.org/schema/cxf
http://camel.apache.org/schema/cxf/camel-cxf.xsd">

<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-http.xml" />
<import resource="classpath:META-INF/cxf/osgi/cxf-extension-osgi.xml" />

<cxf:cxfEndpoint
id="salesforceLogin"
address="https://test.salesforce.com/services/Soap/c/22.0"
wsdlURL="wsdl/sfdc.wsdl"
serviceClass="com.sforce.soap.enterprise.Login">
</cxf:cxfEndpoint>

</beans>
njiang

Posts: 572
Registered: 09/17/07
Re: CXF Endpoint Creation
Posted: Nov 5, 2011 1:53 PM   in response to: gt6081a in response to: gt6081a
  Click to reply to this thread Reply
Which version of CXF are you using ?
I'm just assuming that you are using CXF 2.3.x ?
Do you try to add import package of "org.apache.cxf.binding.soap.spring" into your bundle ?

Willem
gt6081a

Posts: 34
Registered: 07/22/11
Re: CXF Endpoint Creation
Posted: Nov 7, 2011 3:04 PM   in response to: njiang in response to: njiang
  Click to reply to this thread Reply
I am not trying to use any specific version of cxf as I am just trying to leverage the packages in servicemix. Looking at the installed features I see:

camel-cxf is 2.7.1-fuse-00-43
cxf is 2.4.1-fuse-00-43
servicemix-cxf-bc is 2011.02.0-fuse-00-43

I haven't tried importing anything into the POM other than

<dependencies>
<dependency>
<groupId>org.apache.servicemix</groupId>
<artifactId>servicemix-cxf-bc</artifactId>
<version>2011.01.0-fuse-02-05</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-cxf</artifactId>
<version>2.7.1</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http-jetty</artifactId>
<version>2.2.10</version>
</dependency>
</dependencies>

which was what I had found in the example in the Camel in Action book. I do have the following in the imported packages section which I had gotten from a similar example

<Import-Package>javax.jws,javax.wsdl,META-INF.cxf,META-INF.cxf.osgi,
org.apache.cxf.bus,org.apache.cxf.bus.spring,org.apache.servicemix.cxfbc,
org.apache.cxf.configuration.spring, org.apache.cxf.resource,
org.springframework.beans.factory.config,org.apache.cxf.transports.http_jetty.configuration,*</Import-Package>

Edited by: gt6081a on Nov 7, 2011 3:06 PM

gt6081a

Posts: 34
Registered: 07/22/11
Re: CXF Endpoint Creation
Posted: Nov 7, 2011 3:28 PM   in response to: gt6081a in response to: gt6081a
  Click to reply to this thread Reply
Ok so I went through the maven importing dance and now that I am through that I am seeing the following when trying to deploy. Those included xml files that are referenced I just copied from the book so I am not sure what their role is or how I should treat issues around them like this.

10:18:18,799 | INFO | xtenderThread-60 | DefaultListableBeanFactory | 68 - org.springframework.beans - 3.0.5.RELEASE | Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@46ccc076: defining beans http://cxf,org.apache.cxf.bus.spring.BusWiringBeanFactoryPostProcessor,org.apache.cxf.bus.spring.Jsr250BeanPostProcessor,org.apache.cxf.bus.spring.BusExtensionPostProcessor,org.apache.cxf.binding.soap.SoapBindingFactory,org.apache.cxf.binding.soap.SoapTransportFactory,org.apache.cxf.binding.soap.customEditorConfigurer,org.apache.cxf.transport.http.ClientOnlyHTTPTransportFactory,osgiDestinationRegistry,org.apache.cxf.transport.http.HTTPTransportFactory,salesforceLogin; root of factory hierarchy
10:18:18,800 | WARN | xtenderThread-60 | DisposableBeanAdapter | 68 - org.springframework.beans - 3.0.5.RELEASE | Invocation of destroy method 'shutdown' failed on bean with name 'cxf': org.springframework.beans.factory.BeanCreationNotAllowedException: Error creating bean with name 'org.apache.cxf.binding.soap.SoapBindingFactory': Singleton bean creation not allowed while the singletons of this factory are in destruction (Do not request a bean from a BeanFactory in a destroy method implementation!)
10:18:18,800 | ERROR | xtenderThread-60 | ContextLoaderListener | 85 - org.springframework.osgi.extender - 1.2.1 | Application context refresh failed (OsgiBundleXmlApplicationContext(bundle=SalesforceEndpoint, config=osgibundle:/META-INF/spring/*.xml))
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.apache.cxf.binding.soap.SoapBindingFactory' defined in OSGi resourceclasspath:META-INF/cxf/cxf-extension-soap.xml: Could not resolve matching constructor (hint: specify index/type/name arguments for simple parameters to avoid type ambiguities)
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:250)68:org.springframework.beans:3.0.5.RELEASE
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1003)68:org.springframework.beans:3.0.5.RELEASE
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:907)68:org.springframework.beans:3.0.5.RELEASE
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:485)68:org.springframework.beans:3.0.5.RELEASE
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)68:org.springframework.beans:3.0.5.RELEASE
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)68:org.springframework.beans:3.0.5.RELEASE
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)68:org.springframework.beans:3.0.5.RELEASE
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)68:org.springframework.beans:3.0.5.RELEASE
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)68:org.springframework.beans:3.0.5.RELEASE
at org.springframework.beans.factory.support.AbstractBeanFactory.isSingleton(AbstractBeanFactory.java:396)68:org.springframework.beans:3.0.5.RELEASE
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:317)68:org.springframework.beans:3.0.5.RELEASE
at org.springframework.context.support.AbstractApplicationContext.getBeanNamesForType(AbstractApplicationContext.java:1136)70:org.springframework.context:3.0.5.RELEASE
at org.apache.cxf.bus.spring.SpringBeanLocator.getBeansOfType(SpringBeanLocator.java:89)123:org.apache.cxf.bundle:2.4.1.fuse-00-43
at org.apache.cxf.bus.CXFBusImpl.getExtension(CXFBusImpl.java:99)123:org.apache.cxf.bundle:2.4.1.fuse-00-43
at org.apache.cxf.bus.extension.ExtensionManagerBus.initialize(ExtensionManagerBus.java:151)123:org.apache.cxf.bundle:2.4.1.fuse-00-43
at org.apache.cxf.bus.spring.SpringBus.onApplicationEvent(SpringBus.java:92)123:org.apache.cxf.bundle:2.4.1.fuse-00-43
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:97)70:org.springframework.context:3.0.5.RELEASE
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:303)70:org.springframework.context:3.0.5.RELEASE
at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:911)70:org.springframework.context:3.0.5.RELEASE
at org.springframework.osgi.context.support.AbstractOsgiBundleApplicationContext.finishRefresh(AbstractOsgiBundleApplicationContext.java:235)82:org.springframework.osgi.core:1.2.1
at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext$4.run(AbstractDelegatedExecutionApplicationContext.java:358)82:org.springframework.osgi.core:1.2.1
at org.springframework.osgi.util.internal.PrivilegedUtils.executeWithCustomTCCL(PrivilegedUtils.java:85)82:org.springframework.osgi.core:1.2.1
at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.completeRefresh(AbstractDelegatedExecutionApplicationContext.java:320)82:org.springframework.osgi.core:1.2.1
at org.springframework.osgi.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor$CompleteRefreshTask.run(DependencyWaiterApplicationContextExecutor.java:132)85:org.springframework.osgi.extender:1.2.1
at java.lang.Thread.run(Thread.java:662):1.6.0_23

ffang

Posts: 1,320
Registered: 12/24/07
Re: CXF Endpoint Creation
Posted: Nov 9, 2011 1:44 AM   in response to: gt6081a in response to: gt6081a
  Click to reply to this thread Reply
Hi,

Your bundle depend CXF 2.2.10 but in OSGi container the CXF version is 2.4.1-fuse-00-43, this mismatch could cause issues, also, after CXF 2.4.0, you don't need
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-http.xml" />
anymore,
so you need remove it from your beans.xml and change the CXF dependency to keep it same as the OSGi container and rebuild it.

Freeman
gt6081a

Posts: 34
Registered: 07/22/11
Re: CXF Endpoint Creation
Posted: Nov 10, 2011 6:03 PM   in response to: ffang in response to: ffang
  Click to reply to this thread Reply
Thanks, making those changes everything appears to have been deployed to the container without issue.

So now in a camel route I should be able to just call cxf:bean:salesforceLogin and that will in effect pass the message off to that webservice?
gt6081a

Posts: 34
Registered: 07/22/11
Re: CXF Endpoint Creation
Posted: Nov 11, 2011 4:41 PM   in response to: ffang in response to: ffang
  Click to reply to this thread Reply
So deploying my route which references the endpoint I just deployed, I am getting
org.apache.camel.RuntimeCamelException: org.apache.camel.FailedToCreateRouteException: Failed to create route SalesforceAuthentication at: >>> To[cxf:bean:salesforceLogin] <<< in route: Route[[From[timer://sforce?fixedRate=true&period=60000]] -> ... because of Failed to resolve endpoint: cxf://bean:salesforceLogin due to: registry entry called salesforceLogin of type org.apache.camel.component.cxf.spring.CxfEndpointBean must be specified

I am not sure why the endpoint I deployed wouldn't be in the context.

The route is just

<route id="SalesforceAuthentication">
<from uri="timer://sforce?fixedRate=true&amp;period=60000"/>
<to uri="velocity://velocity/sforceLogin.vm" />
<convertBodyTo type="java.lang.String" />
<to uri="cxf:bean:salesforceLogin"/>
<convertBodyTo type="java.lang.String" />
<to uri="file:data/sforce?fileName=sforceLoginResponse.xml"/>
</route>

Just as a reminder the beans.xml for the deployed endpoint is:
<?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:cxf="http://camel.apache.org/schema/cxf"
	xmlns:sfdc="urn:enterprise.soap.sforce.com"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans 
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://camel.apache.org/schema/cxf
        http://camel.apache.org/schema/cxf/camel-cxf.xsd">
    <import resource="classpath:META-INF/cxf/cxf.xml" />
    <import resource="classpath:META-INF/cxf/osgi/cxf-extension-osgi.xml" />
	<cxf:cxfEndpoint
		id="salesforceLogin"
		address="https://test.salesforce.com/services/Soap/c/22.0"
		wsdlURL="wsdl/sfdc.wsdl"
		serviceClass="com.sforce.soap.enterprise.Login">
	</cxf:cxfEndpoint>
</beans>


Edited to add endpoint
davsclaus

Posts: 1,893
Registered: 10/14/08
Re: CXF Endpoint Creation
Posted: Nov 12, 2011 8:23 AM   in response to: gt6081a in response to: gt6081a
  Click to reply to this thread Reply
Where do you have the Camel routes?

If you have the Camel routes and the CXF bean in the same XML file, then Camel should be able to find the CXF bean.
gt6081a

Posts: 34
Registered: 07/22/11
Re: CXF Endpoint Creation
Posted: Nov 14, 2011 3:30 PM   in response to: davsclaus in response to: davsclaus
  Click to reply to this thread Reply
Currently they are in separate projects as I wanted to have the endpoint used by other routes as well that will be deployed separately. Is there a way to make the CXF endpoint available outside of the same xml?
gt6081a

Posts: 34
Registered: 07/22/11
Re: CXF Endpoint Creation
Posted: Nov 14, 2011 4:23 PM   in response to: davsclaus in response to: davsclaus
  Click to reply to this thread Reply
Attachment sfdc.wsdl (473.9 KB)
I've put the camel-context.xml and beans.xml into the same osgi bundle and deployed. Now I get

10:55:25,920 | ERROR | xtenderThread-75 | ContextLoaderListener            | 85 - org.springframework.osgi.extender - 1.2.1 | Application context refresh failed (OsgiBundleXmlApplicationContext(bundle=HCMSalesforceRoute, config=osgibundle:/META-INF/spring/*.xml))
org.apache.camel.FailedToCreateProducerException: Failed to create Producer for endpoint: Endpoint[cxf://bean:salesforceLogin]. Reason: org.apache.cxf.service.factory.ServiceConstructionException: Could not find definition for service {http://enterprise.soap.sforce.com/}SforceService.


I am looking over the namespaces and such and everything seems to match so I am not entirely sure where the disconnect is.

camel-context.xml:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<beans xmlns="http://www.springframework.org/schema/beans" 
	   xmlns:ctx="http://www.springframework.org/schema/context" 
	   xmlns:osgi="http://camel.apache.org/schema/osgi" 
	   xmlns:osgix="http://www.springframework.org/schema/osgi-compendium" 
	   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
	   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/osgi 
	   		http://camel.apache.org/schema/osgi/camel-osgi.xsd        
	   		http://www.springframework.org/schema/osgi-compendium 
	   		http://www.springframework.org/schema/osgi-compendium/spring-osgi-compendium.xsd        
	   		http://www.springframework.org/schema/context 
	   		http://www.springframework.org/schema/context/spring-context.xsd ">
 
  	<camelContext xmlns="http://camel.apache.org/schema/spring" trace="true">
 
	<route id="SalesforceAuthentication">
   		<from uri="timer://sforce?fixedRate=true&amp;period=60000"/>
   		<to uri="velocity://velocity/sforceLogin.vm" />
    	<convertBodyTo type="java.lang.String" />
    	<to uri="cxf:bean:salesforceLogin"/> 
    	<convertBodyTo type="java.lang.String" />
    	<to uri="file:data/sforce?fileName=sforceLoginResponse.xml"/>
    </route>      
     
</camelContext>
</beans>


beans.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:cxf="http://camel.apache.org/schema/cxf"
	xmlns:sfdc="urn:enterprise.soap.sforce.com"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans 
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://camel.apache.org/schema/cxf
        http://camel.apache.org/schema/cxf/camel-cxf.xsd">
 
    <import resource="classpath:META-INF/cxf/cxf.xml" />
    <import resource="classpath:META-INF/cxf/osgi/cxf-extension-osgi.xml" />
 
	<cxf:cxfEndpoint
		id="salesforceLogin"
		address="https://test.salesforce.com/services/Soap/c/22.0"
		wsdlURL="wsdl/sfdc.wsdl"
		serviceClass="com.sforce.soap.enterprise.SforceService">
	</cxf:cxfEndpoint>
 
</beans>


I also attached the WSDL in case it is relevant. I have the bundle setup to generate the sources from the WSDL with CXF, so all the stubs are a part of the bundle as well.
davsclaus

Posts: 1,893
Registered: 10/14/08
Re: CXF Endpoint Creation
Posted: Nov 14, 2011 5:56 PM   in response to: gt6081a in response to: gt6081a
  Click to reply to this thread Reply
They have to be in the same file.

Alternatively you would need to use xml:include to include another XML file. But its just easier to put them all in the same XML file, to have it working.
gt6081a

Posts: 34
Registered: 07/22/11
Re: CXF Endpoint Creation
Posted: Nov 14, 2011 7:50 PM   in response to: davsclaus in response to: davsclaus
  Click to reply to this thread Reply
I tried putting them into the same file. I actually got the exact same error.

14:47:09,007 | ERROR | xtenderThread-83 | ContextLoaderListener            | 85 - org.springframework.osgi.extender - 1.2.1 | Application context refresh failed (OsgiBundleXmlApplicationContext(bundle=HCMSalesforceRoute, config=osgibundle:/META-INF/spring/*.xml))
org.apache.camel.FailedToCreateProducerException: Failed to create Producer for endpoint: Endpoint[cxf://bean:salesforceLogin]. Reason: org.apache.cxf.service.factory.ServiceConstructionException: Could not find definition for service {http://enterprise.soap.sforce.com/}SforceService.
        at org.apache.camel.impl.ProducerCache.doGetProducer(ProducerCache.java:362)[77:org.apache.camel.camel-core:2.7.1.fuse-00-43]
        at org.apache.camel.impl.ProducerCache.acquireProducer(ProducerCache.java:93)[77:org.apache.camel.camel-core:2.7.1.fuse-00-43]
        at org.apache.camel.impl.ProducerCache.startProducer(ProducerCache.java:124)[77:org.apache.camel.camel-core:2.7.1.fuse-00-43]


When the stubs from the wsdl are generated, I see the com/sforce/soap/enterprise/SforceService.java, and the class exists in the bundle when I look inside. Is there something misconfigured with the serviceClass or something else that would be causing this?
ffang

Posts: 1,320
Registered: 12/24/07
Re: CXF Endpoint Creation
Posted: Nov 15, 2011 12:47 AM   in response to: gt6081a in response to: gt6081a
  Click to reply to this thread Reply
Hi,

This error generally means your wsdl has not wsdl:service like
{http://enterprise.soap.sforce.com/}SforceService
Could you check your wsdl/sfdc.wsdl?

Freeman
gt6081a

Posts: 34
Registered: 07/22/11
Re: CXF Endpoint Creation
Posted: Nov 15, 2011 3:43 PM   in response to: ffang in response to: ffang
  Click to reply to this thread Reply
In the WSDL is

<import namespace="urn:enterprise.soap.sforce.com"/>
...
<!-- Soap Service Endpoint -->
<service name="SforceService">
<documentation>Sforce SOAP API</documentation>
<port binding="tns:SoapBinding" name="Soap">
<soap:address location="https://test.salesforce.com/services/Soap/c/22.0"/>
</port>
</service>

I changed the xml to use

<cxf:cxfEndpoint
id="salesforceLogin"
address="https://test.salesforce.com/services/Soap/c/22.0"
wsdlURL="wsdl/sfdc.wsdl"
serviceClass="com.sforce.soap.enterprise.SforceService"
serviceName="s:SforceService"
endpointName="s:Soap"
xmlns:s="urn:enterprise.soap.sforce.com">
</cxf:cxfEndpoint>

Which gives the error that SforceService is not an interface
gt6081a

Posts: 34
Registered: 07/22/11
Re: CXF Endpoint Creation
Posted: Nov 15, 2011 9:12 PM   in response to: gt6081a in response to: gt6081a
  Click to reply to this thread Reply
I figured it out, started back at square one and was diligent about all the port, bind and service names and it eventually got deployed properly. Unfortunately this has raised another issue I will post about shortly.
njiang

Posts: 572
Registered: 09/17/07
Re: CXF Endpoint Creation
Posted: Nov 12, 2011 8:25 AM   in response to: gt6081a in response to: gt6081a
  Click to reply to this thread Reply
You need to make sure the <cxfEndpoint id="salesforceLogin"> are in the same application context of the camel context.

Willem