0

I am trying to call a web service from Apache Camel using CXF, that tries to convert the currency from one currency to other, but I am unable to call it because of endpoint resolution. If any simple tutorials are there how to call webservices from Apache Camel please post.. Thanks in advance..

CamelContext is as below..

<?xml version="1.0" encoding="UTF-8" standalone="no"?><beans xmlns="http://www.springframework.org/schema/beans" 
xmlns:cxf="http://camel.apache.org/schema/cxf" 
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-3.0.xsd        
    http://camel.apache.org/schema/spring  
    http://camel.apache.org/schema/spring/camel-spring.xsd">

  <camelContext trace="false" xmlns="http://camel.apache.org/schema/spring">
    <route>
    <from uri="file:src/data/order?noop=true"/>
        <log message="&gt;&gt;&gt; ${body}" loggingLevel="INFO"/>
        <to uri="cxf://http://www.webservicex.net/CurrencyConvertor.asmx?wsdlURL=http://www.webservicex.net/CurrencyConvertor.asmx?wsdl&amp;serviceName={http://www.webserviceX.NET/}CurrencyConvertor&amp;portName={http://www.webserviceX.NET/}CurrencyConvertorSoap&amp;dataFormat=MESSAGE"/>   
        <log message="&gt;&gt;&gt; ${body}" loggingLevel="INFO"/>
    </route>
</camelContext>

</beans>

My order.xml is...

<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
  <soap12:Body>
   <web:ConversionRate>
<web:FromCurrency>AUD</web:FromCurrency>
<web:ToCurrency>USD</web:ToCurrency>
</web:ConversionRate> 
  </soap12:Body>
</soap12:Envelope>

This is the error i am facing while running the camel context ....

*************************************
Error occurred while running main from: org.apache.camel.spring.Main
java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.apache.camel.maven.RunMojo$1.run(RunMojo.java:440)
    at java.lang.Thread.run(Thread.java:744)
Caused by: org.apache.camel.FailedToCreateProducerException: Failed to create Producer for endpoint: Endpoint[cxf://http://www.webservicex.net/CurrencyConvertor.asmx?dataFormat=MESSAGE&portName=%7Bhttp%3A%2F%2Fwww.webserviceX.NET%2F%7DCurrencyConvertorSoap&serviceName=%7Bhttp%3A%2F%2Fwww.webserviceX.NET%2F%7DCurrencyConvertor&wsdlURL=http%3A%2F%2Fwww.webservicex.net%2FCurrencyConvertor.asmx%3Fwsdl]. Reason: org.apache.cxf.service.factory.ServiceConstructionException: Failed to create service.
    at org.apache.camel.impl.ProducerCache.doGetProducer(ProducerCache.java:395)
    at org.apache.camel.impl.ProducerCache.acquireProducer(ProducerCache.java:114)
    at org.apache.camel.impl.ProducerCache.startProducer(ProducerCache.java:145)
    at org.apache.camel.processor.SendProcessor.doStart(SendProcessor.java:175)
    at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:60)
    at org.apache.camel.util.ServiceHelper.startService(ServiceHelper.java:62)
    at org.apache.camel.util.ServiceHelper.startService(ServiceHelper.java:52)
    at org.apache.camel.util.ServiceHelper.startServices(ServiceHelper.java:73)
    at org.apache.camel.processor.DelegateAsyncProcessor.doStart(DelegateAsyncProcessor.java:78)
    at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:60)
    at org.apache.camel.util.ServiceHelper.startService(ServiceHelper.java:62)
    at org.apache.camel.util.ServiceHelper.startService(ServiceHelper.java:52)
    at org.apache.camel.util.ServiceHelper.startServices(ServiceHelper.java:73)
    at org.apache.camel.processor.DelegateAsyncProcessor.doStart(DelegateAsyncProcessor.java:78)
    at org.apache.camel.processor.interceptor.TraceInterceptor.doStart(TraceInterceptor.java:358)
    at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:60)
    at org.apache.camel.util.ServiceHelper.startService(ServiceHelper.java:62)
    at org.apache.camel.util.ServiceHelper.startService(ServiceHelper.java:52)
    at org.apache.camel.processor.WrapProcessor.doStart(WrapProcessor.java:52)
    at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:60)
    at org.apache.camel.util.ServiceHelper.startService(ServiceHelper.java:62)
    at org.apache.camel.util.ServiceHelper.startService(ServiceHelper.java:52)
    at org.apache.camel.util.ServiceHelper.startServices(ServiceHelper.java:73)
    at org.apache.camel.processor.RedeliveryErrorHandler.doStart(RedeliveryErrorHandler.java:1064)
    at org.apache.camel.support.ChildServiceSupport.start(ChildServiceSupport.java:41)
    at org.apache.camel.support.ChildServiceSupport.start(ChildServiceSupport.java:28)
    at org.apache.camel.util.ServiceHelper.startService(ServiceHelper.java:62)
    at org.apache.camel.util.ServiceHelper.startService(ServiceHelper.java:52)
    at org.apache.camel.util.ServiceHelper.startServices(ServiceHelper.java:73)
    at org.apache.camel.processor.interceptor.DefaultChannel.doStart(DefaultChannel.java:153)
    at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:60)
    at org.apache.camel.util.ServiceHelper.startService(ServiceHelper.java:62)
    at org.apache.camel.util.ServiceHelper.startService(ServiceHelper.java:52)
    at org.apache.camel.util.ServiceHelper.startServices(ServiceHelper.java:85)
    at org.apache.camel.processor.MulticastProcessor.doStart(MulticastProcessor.java:938)
    at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:60)
    at org.apache.camel.util.ServiceHelper.startService(ServiceHelper.java:62)
    at org.apache.camel.util.ServiceHelper.startService(ServiceHelper.java:52)
    at org.apache.camel.util.ServiceHelper.startServices(ServiceHelper.java:73)
    at org.apache.camel.processor.DelegateAsyncProcessor.doStart(DelegateAsyncProcessor.java:78)
    at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:60)
    at org.apache.camel.util.ServiceHelper.startService(ServiceHelper.java:62)
    at org.apache.camel.util.ServiceHelper.startService(ServiceHelper.java:52)
    at org.apache.camel.util.ServiceHelper.startServices(ServiceHelper.java:73)
    at org.apache.camel.processor.DelegateAsyncProcessor.doStart(DelegateAsyncProcessor.java:78)
    at org.apache.camel.processor.UnitOfWorkProcessor.doStart(UnitOfWorkProcessor.java:88)
    at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:60)
    at org.apache.camel.util.ServiceHelper.startService(ServiceHelper.java:62)
    at org.apache.camel.util.ServiceHelper.startService(ServiceHelper.java:52)
    at org.apache.camel.util.ServiceHelper.startServices(ServiceHelper.java:73)
    at org.apache.camel.processor.DelegateAsyncProcessor.doStart(DelegateAsyncProcessor.java:78)
    at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:60)
    at org.apache.camel.util.ServiceHelper.startService(ServiceHelper.java:62)
    at org.apache.camel.util.ServiceHelper.startService(ServiceHelper.java:52)
    at org.apache.camel.util.ServiceHelper.startServices(ServiceHelper.java:73)
    at org.apache.camel.processor.DelegateAsyncProcessor.doStart(DelegateAsyncProcessor.java:78)
    at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:60)
    at org.apache.camel.util.ServiceHelper.startService(ServiceHelper.java:62)
    at org.apache.camel.impl.RouteService.startChildService(RouteService.java:322)
    at org.apache.camel.impl.RouteService.warmUp(RouteService.java:151)
    at org.apache.camel.impl.DefaultCamelContext.doWarmUpRoutes(DefaultCamelContext.java:2000)
    at org.apache.camel.impl.DefaultCamelContext.safelyStartRouteServices(DefaultCamelContext.java:1928)
    at org.apache.camel.impl.DefaultCamelContext.doStartOrResumeRoutes(DefaultCamelContext.java:1716)
    at org.apache.camel.impl.DefaultCamelContext.doStartCamel(DefaultCamelContext.java:1597)
    at org.apache.camel.impl.DefaultCamelContext.doStart(DefaultCamelContext.java:1453)
    at org.apache.camel.spring.SpringCamelContext.doStart(SpringCamelContext.java:179)
    at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:60)
    at org.apache.camel.impl.DefaultCamelContext.start(DefaultCamelContext.java:1421)
    at org.apache.camel.spring.SpringCamelContext.maybeStart(SpringCamelContext.java:228)
    at org.apache.camel.spring.SpringCamelContext.onApplicationEvent(SpringCamelContext.java:118)
    at org.apache.camel.spring.CamelContextFactoryBean.onApplicationEvent(CamelContextFactoryBean.java:283)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:97)
    at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:327)
    at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:941)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:475)
    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.apache.camel.main.MainSupport.run(MainSupport.java:332)
    at org.apache.camel.spring.Main.main(Main.java:73)
    ... 6 more
Caused by: org.apache.cxf.service.factory.ServiceConstructionException: Failed to create service.
    at org.apache.cxf.wsdl11.WSDLServiceFactory.<init>(WSDLServiceFactory.java:94)
    at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.buildServiceFromWSDL(ReflectionServiceFactoryBean.java:398)
    at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.initializeServiceModel(ReflectionServiceFactoryBean.java:534)
    at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.create(ReflectionServiceFactoryBean.java:248)
    at org.apache.cxf.frontend.AbstractWSDLBasedEndpointFactory.createEndpoint(AbstractWSDLBasedEndpointFactory.java:101)
    at org.apache.cxf.frontend.ClientFactoryBean.create(ClientFactoryBean.java:90)
    at org.apache.camel.component.cxf.CxfEndpoint.createClient(CxfEndpoint.java:527)
    at org.apache.camel.component.cxf.CxfProducer.doStart(CxfProducer.java:76)
    at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:60)
    at org.apache.camel.util.ServiceHelper.startService(ServiceHelper.java:62)
    at org.apache.camel.impl.ProducerCache.doGetProducer(ProducerCache.java:393)
    ... 88 more
Caused by: javax.wsdl.WSDLException: WSDLException: faultCode=PARSER_ERROR: Problem parsing 'http://www.webservicex.net/CurrencyConvertor.asmx?wsdl'.: java.net.UnknownHostException: www.webservicex.net
    at com.ibm.wsdl.xml.WSDLReaderImpl.getDocument(Unknown Source)
    at com.ibm.wsdl.xml.WSDLReaderImpl.readWSDL(Unknown Source)
    at com.ibm.wsdl.xml.WSDLReaderImpl.readWSDL(Unknown Source)
    at org.apache.cxf.wsdl11.WSDLManagerImpl.loadDefinition(WSDLManagerImpl.java:249)
    at org.apache.cxf.wsdl11.WSDLManagerImpl.getDefinition(WSDLManagerImpl.java:192)
    at org.apache.cxf.wsdl11.WSDLServiceFactory.<init>(WSDLServiceFactory.java:92)
    ... 98 more
Caused by: java.net.UnknownHostException: www.webservicex.net
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:178)
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
    at java.net.Socket.connect(Socket.java:579)
    at java.net.Socket.connect(Socket.java:528)
    at sun.net.NetworkClient.doConnect(NetworkClient.java:180)
    at sun.net.www.http.HttpClient.openServer(HttpClient.java:432)
    at sun.net.www.http.HttpClient.openServer(HttpClient.java:527)
    at sun.net.www.http.HttpClient.<init>(HttpClient.java:211)
    at sun.net.www.http.HttpClient.New(HttpClient.java:308)
    at sun.net.www.http.HttpClient.New(HttpClient.java:326)
    at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:996)
    at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:932)
    at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:850)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1300)
    at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity(XMLEntityManager.java:637)
    at com.sun.org.apache.xerces.internal.impl.XMLVersionDetector.determineDocVersion(XMLVersionDetector.java:189)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:812)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:777)
    at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
    at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:243)
    at enter code herecom.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:347)
Matthew Wilson
  • 2,045
  • 14
  • 27
Rahul
  • 149
  • 4
  • 11
  • Essentially you are proxying the web service. See this example http://camel.apache.org/cxf-proxy-example.html – Namphibian May 22 '14 at 22:08
  • Thanks Namphibian for reply...Is the url framed in camel context is correct or wrong,because i am facing error in that url.. – Rahul May 23 '14 at 04:42

1 Answers1

0

When accessing http://www.webservicex.net/CurrencyConvertor.asmx?wsdl your log says:

java.net.UnknownHostException

Check, if you have access to the internet. Or if you are behind a proxy server, you may first set the appropriate proxy settings. Find more information about that here.

That said, your SOAP request misses the web namespace. Without the appropriate setting, the server will complain.

xmlns:web="http://www.webserviceX.NET/"

I started the tests with:

 final org.apache.camel.spring.Main main = new org.apache.camel.spring.Main();
 main.setApplicationContextUri("META-INF/spring/cxf-example.orig.xml");
 main.start();
Community
  • 1
  • 1
Peter Keller
  • 7,526
  • 2
  • 26
  • 29
  • Thanks for the help Peter...I tried the things suggested by you both proxy and added xmlns in my camelcontext but still i am facing the same issue.. – Rahul May 23 '14 at 09:40
  • @Rahulbujji I tested your set-up (with the corrected namespace declaration) and it worked correctly. If possible, test your route from a different server in another domain not behind the firewall. – Peter Keller May 23 '14 at 09:45
  • Peter can you please post the camelcontext you tried..That will be useful to me... – Rahul May 23 '14 at 10:35
  • @Rahulbujji I copy-pasted your example and only changed the file source location. I tested with Camel v2.12.3 and v2.13.1. I added my Java start sequence in my answer. However, as stated in my answer, I guess that your problem is network related. – Peter Keller May 23 '14 at 11:10
  • @Rahulbujji Could you post how you set up the Camel proxy configuration? – Peter Keller May 23 '14 at 11:50
  • @Rahulbujji See http://stackoverflow.com/questions/120797/how-do-i-set-the-proxy-to-be-used-by-the-jvm. I could not test it myself, but it should work. – Peter Keller May 23 '14 at 13:57
  • @Rahulbujji If the answer helped you, you may mark it as correct. – Peter Keller May 30 '14 at 16:21