You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by abhi <il...@rediffmail.com> on 2013/03/22 16:21:02 UTC
How to call CXF web service from Camel
Hi All,
I am new to Apache Camel and I am trying to call CXF web service from Camel.
Here is my camel-context.xml
----------------------------------
<route id="test3">
<from uri="stream:in?promptMessage=Enter Something:"/>
<to uri="cxf:bean:HelloService"/>
<to uri="bean:myBean?method=myMethod"/>
</route>
</camel:camelContext>
<cxf:cxfEndpoint id="HelloService"
address="http://localhost:8080/HelloWeb/Hello"
wsdlURL="http://localhost:8080/HelloWeb/Hello?wsdl"
serviceClass="com.server.HelloFirst"
/>
<bean id="myBean" class="org.test.MyBean"/>
</beans>
Below are the source code of my web service
HelloFirst.java
----------------------------------------------
package com.server;
import javax.jws.WebService;
@WebService
public interface HelloFirst {
public String myHello(String str);
}
HelloFirstImpl.java
----------------------------------------------
package com.server;
import javax.jws.WebService;
@WebService(endpointInterface = "com.server.HelloFirst")
public class HelloFirstImpl {
public String myHello(String str){
return "HelloFirstImpl: Hello :"+str;
}
}
cxf.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:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
<jaxws:endpoint id="Hello"
implementor="com.server.HelloFirstImpl" address="/Hello" />
</beans>
Using a java client I am able to invoke above web service but when I try to
do it through Camel it gives me following error:
Exception in thread "main"
org.springframework.beans.factory.BeanCreationException: Error creating bean
with name 'HelloService': Initialization of bean failed; nested exception is
org.springframework.beans.TypeMismatchException: Failed to convert property
value of type 'java.lang.String' to required type 'java.lang.Class' for
property 'serviceClass'; nested exception is
java.lang.IllegalArgumentException: Cannot find class
[com.server.HelloFirst]
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:526)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:455)
at
org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:293)
at
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at
org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:290)
at
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:192)
at
org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585)
at
org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
at
org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
at
org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at
org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:93)
at
org.apache.camel.spring.Main.createDefaultApplicationContext(Main.java:186)
at org.apache.camel.spring.Main.doStart(Main.java:140)
at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:60)
at org.apache.camel.main.MainSupport.run(MainSupport.java:141)
at org.test.CamelFirstCXF.main(CamelFirstCXF.java:30)
Caused by: org.springframework.beans.TypeMismatchException: Failed to
convert property value of type 'java.lang.String' to required type
'java.lang.Class' for property 'serviceClass'; nested exception is
java.lang.IllegalArgumentException: Cannot find class
[com.server.HelloFirst]
at
org.springframework.beans.BeanWrapperImpl.convertIfNecessary(BeanWrapperImpl.java:486)
at
org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:518)
at
org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:512)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.convertForProperty(AbstractAutowireCapableBeanFactory.java:1373)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1332)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1085)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:516)
... 15 more
Caused by: java.lang.IllegalArgumentException: Cannot find class
[com.server.HelloFirst]
at
org.springframework.util.ClassUtils.resolveClassName(ClassUtils.java:293)
at
org.springframework.beans.propertyeditors.ClassEditor.setAsText(ClassEditor.java:63)
at
org.springframework.beans.TypeConverterDelegate.doConvertTextValue(TypeConverterDelegate.java:421)
at
org.springframework.beans.TypeConverterDelegate.doConvertValue(TypeConverterDelegate.java:393)
at
org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:161)
at
org.springframework.beans.BeanWrapperImpl.convertIfNecessary(BeanWrapperImpl.java:466)
... 21 more
Caused by: java.lang.ClassNotFoundException: com.server.HelloFirst
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at org.springframework.util.ClassUtils.forName(ClassUtils.java:257)
at
org.springframework.util.ClassUtils.resolveClassName(ClassUtils.java:290)
... 26 more
Mar 22, 2013 8:25:29 PM org.apache.camel.main.MainSupport$HangupInterceptor
run
INFO: Received hang up - stopping the main instance.
*******************************
Can you let me know what exactly I am doing wrong? I am new to Camel so
facing lot of issues.
I did lot of googling but not able to get it running.
Thanks in advance !!!!!
Regards,
Abhijit
--
View this message in context: http://camel.465427.n5.nabble.com/How-to-call-CXF-web-service-from-Camel-tp5729692.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: How to call CXF web service from Camel
Posted by abhi <il...@rediffmail.com>.
I have created JAR file of web service project and added it in my Camel
project build path and everything is working fine now.
Thanks for your help
--
View this message in context: http://camel.465427.n5.nabble.com/How-to-call-CXF-web-service-from-Camel-tp5729692p5730119.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: How to call CXF web service from Camel
Posted by santhosh <ra...@gmail.com>.
Sorry.The dataFormat has to be PAYLOAD or MESSAGE.you can look at what that
is on http://camel.apache.org/cxf.html .if you want POJO you should include
stub interface as serviceClass.btw the port name is wrong. It should be
tns:HelloFirstImplServiceSoapBinding where tns should declared in namespace.
--
View this message in context: http://camel.465427.n5.nabble.com/How-to-call-CXF-web-service-from-Camel-tp5729692p5729791.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: How to call CXF web service from Camel
Posted by abhi <il...@rediffmail.com>.
HI,
Thanks for your reply. I have already checked that my web service is
deployed correctly and I can consume it with Java client.
As per your suggestion I made changes camel-context.xml in as follow
<cxf:cxfEndpoint id="HelloService"
address="http://localhost:8080/HelloWeb/Hello"
wsdlURL="http://localhost:8080/HelloWeb/Hello?wsdl"
endpointName="HelloFirstImplService"
serviceName="HelloFirstImplService" />
But when I run it I get following error as "Service class" must be specified
Exception in thread "main" org.apache.camel.FailedToCreateProducerException:
Failed to create Producer for endpoint:
Endpoint[http://localhost:8080/HelloWeb/Hello]. Reason:
java.lang.IllegalArgumentException: serviceClass must be specified
at
org.apache.camel.impl.ProducerCache.doGetProducer(ProducerCache.java:395)
Caused by: java.lang.IllegalArgumentException: serviceClass must be
specified
at org.apache.camel.util.ObjectHelper.notNull(ObjectHelper.java:294)
For you reference here is my wsdl
file.(http://localhost:8080/HelloWeb/Hello?wsdl)
-----------------------------------------------------
<?xml version="1.0" ?><wsdl:definitions
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://server.com/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:ns1="http://schemas.xmlsoap.org/soap/http"
name="HelloFirstImplService" targetNamespace="http://server.com/">
<wsdl:types>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://server.com/" elementFormDefault="unqualified"
targetNamespace="http://server.com/" version="1.0">
<xs:element name="myHello" type="tns:myHello"></xs:element>
<xs:element name="myHelloResponse" type="tns:myHelloResponse"></xs:element>
<xs:complexType name="myHello">
<xs:sequence>
<xs:element minOccurs="0" name="arg0" type="xs:string"></xs:element>
</xs:sequence>
</xs:complexType>
<xs:complexType name="myHelloResponse">
<xs:sequence>
<xs:element minOccurs="0" name="return" type="xs:string"></xs:element>
</xs:sequence>
</xs:complexType>
</xs:schema>
</wsdl:types>
<wsdl:message name="myHelloResponse">
<wsdl:part element="tns:myHelloResponse" name="parameters">
</wsdl:part>
</wsdl:message>
<wsdl:message name="myHello">
<wsdl:part element="tns:myHello" name="parameters">
</wsdl:part>
</wsdl:message>
<wsdl:portType name="HelloFirst">
<wsdl:operation name="myHello">
<wsdl:input message="tns:myHello" name="myHello">
</wsdl:input>
<wsdl:output message="tns:myHelloResponse" name="myHelloResponse">
</wsdl:output>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="HelloFirstImplServiceSoapBinding"
type="tns:HelloFirst">
<soap:binding style="document"
transport="http://schemas.xmlsoap.org/soap/http"></soap:binding>
<wsdl:operation name="myHello">
<soap:operation soapAction="" style="document"></soap:operation>
<wsdl:input name="myHello">
<soap:body use="literal"></soap:body>
</wsdl:input>
<wsdl:output name="myHelloResponse">
<soap:body use="literal"></soap:body>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="HelloFirstImplService">
<wsdl:port binding="tns:HelloFirstImplServiceSoapBinding"
name="HelloFirstImplPort">
<soap:address
location="http://localhost:8080/HelloWeb/Hello"></soap:address>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
What should I put in so that it will work
1) address
2) endpointName
3) serviceName
4) servicClass
Thanks ,
Abhi
--
View this message in context: http://camel.465427.n5.nabble.com/How-to-call-CXF-web-service-from-Camel-tp5729692p5729744.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: How to call CXF web service from Camel
Posted by santhosh <ra...@gmail.com>.
I recommend you try this
Some ideas:
I am assuming you have cxf webservice as seperate project or hitting service
deployed elsewhere from camel.If no, i recommend to untangle cxf webservice
and camel.
First get the cxf webservice project deployed.Check if the wsdl is
available.
then change you cxf bean to take wsdl argument.
<cxf:cxfEndpoint id="HelloService"
address="http://localhost:8080/HelloWeb/Hello"
wsdlURL="http://localhost:8080/HelloWeb/Hello?wsdl" endpointName=??
serviceName=??/>
camel-context:
<route id="test3">
<from uri="stream:in?promptMessage=Enter Something:"/>
<to uri="cxf:bean:HelloService"/>
<to uri="bean:myBean?method=myMethod"/>
</route>
this should work.
--
View this message in context: http://camel.465427.n5.nabble.com/How-to-call-CXF-web-service-from-Camel-tp5729692p5729694.html
Sent from the Camel - Users mailing list archive at Nabble.com.