从简单的Java客户端调用Web服务

时间:2011-07-08 11:00:02

标签: java web-services axis2

在Eclipse中,我在客户端编写此代码,从wsdl文件生成...

TravelAssistServicesStub t = new TravelAssistServicesStub();
ConversionRateByCountry c = new ConversionRateByCountry();
c.setCountry("India");
c.setUser_Id("satya");
ConversionRateByCountryResponse ccy = t.conversionRateByCountry(c);

System.out.println("Conversion: " + ccy.get_return());

...我得到以下异常:

java.lang.NoClassDefFoundError: org/apache/http/HttpResponseFactory
    at org.apache.axis2.transport.http.SimpleHTTPServer.init(SimpleHTTPServer.java:113)
    at org.apache.axis2.engine.ListenerManager.init(ListenerManager.java:74)
    at org.apache.axis2.context.ConfigurationContext.getListenerManager(ConfigurationContext.java:692)
    at org.apache.axis2.client.ServiceClient.configureServiceClient(ServiceClient.java:163)
    at org.apache.axis2.client.ServiceClient.<init>(ServiceClient.java:143)
    at com.travelassist.services.TravelAssistServicesStub.<init>(TravelAssistServicesStub.java:159)
    at com.travelassist.services.TravelAssistServicesStub.<init>(TravelAssistServicesStub.java:145)
    at com.travelassist.services.TravelAssistServicesStub.<init>(TravelAssistServicesStub.java:196)
    at com.travelassist.services.TravelAssistServicesStub.<init>(TravelAssistServicesStub.java:188)
    at com.tcs.client.login.LoginClient.main(LoginClient.java:37)
Caused by: java.lang.ClassNotFoundException: org.apache.http.HttpResponseFactory
    at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)

2 个答案:

答案 0 :(得分:2)

你缺少apache httpcomponents jar。确保它在运行时位于类路径中。

答案 1 :(得分:1)

在类路径上添加jar文件axis2-transport-http-1.5.jar