`
Aga
  • 浏览: 213413 次
  • 性别: Icon_minigender_1
  • 来自: 天津
社区版块
存档分类
最新评论

利用axis2、eclipse plugin生成webservice

阅读更多
这两天闲来无事,工作比较轻松,于是就学习了下axis2数据绑定端采用了XMLBean,因为工作量太大,所以采用了eclipse插件。关于插件的使用步骤详见http://wso2.org/library/1719
我的客户端采用了xmlbean方法实现,服务器端采用了最简单的pojo其实具体采用pojo xmlbean axiom我觉得不是重点,关键是如何使用工具生成的stub类。我的服务类如下:
package com.cxz.webservice;

public class AsynGreeting {
	public String greetings(String name) {
		try {
			//To show the Asynchronization influence
			Thread.sleep(3000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		return "Greetings to " + name;
	}
}

就是很简单的helloworld,唯一不同的就是加了一个sleep()用来在异步调用中显示作用。
然后利用plugin生成其他部分。
如果客户端采取同步调用,其调用类如下:
package com.cxz.webservice.client;

import java.lang.Exception;
import com.cxz.webservice.GreetingsDocument;
import com.cxz.webservice.GreetingsResponseDocument;
import com.cxz.webservice.GreetingServiceStub;

public class SyncClient {
	public static void main(String[] args) {
		GreetingServiceStub stub = null;
		try {
			stub = new GreetingServiceStub();
			GreetingsDocument reqDoc = GreetingsDocument.Factory.newInstance();
			reqDoc.addNewGreetings();
			reqDoc.getGreetings().setName("Bernard");
			GreetingsResponseDocument respDoc = stub.greetings(reqDoc);
			System.out.println(respDoc.getGreetingsResponse().getReturn());
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}
}

当然,客户端的数据绑定采用了xmlbean方式。

在实现一部调用之前,要实现一些回雕接口,让axis2框架在完成调用之后自动去调用,该回调类如下:
package com.cxz.webservice.impl;

import com.cxz.webservice.GreetingServiceCallbackHandler;

public class CallbackHandlerImpl extends GreetingServiceCallbackHandler {
	public boolean isFinished = false;
	public void receiveResultgreetings(
			com.cxz.webservice.GreetingsResponseDocument result) {
		System.out.println(result.getGreetingsResponse().getReturn());
		isFinished = true;
	}
	public void receiveErrorgreetings(java.lang.Exception e) {
		e.printStackTrace();
	}
}




下面的部分就是采用异步方式调用的客户端
package com.cxz.webservice.client;

import com.cxz.webservice.GreetingServiceCallbackHandler;
import com.cxz.webservice.GreetingServiceStub;
import com.cxz.webservice.GreetingsDocument;
import com.cxz.webservice.impl.CallbackHandlerImpl;

public class AsynClient {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		GreetingServiceStub stub = null;
		try {
			CallbackHandlerImpl callback = new CallbackHandlerImpl();
			stub = new GreetingServiceStub();
			GreetingsDocument reqDoc = GreetingsDocument.Factory.newInstance();
			reqDoc.addNewGreetings();
			reqDoc.getGreetings().setName("Bernard");
			//GreetingsResponseDocument respDoc = stub.greetings(reqDoc);
			//System.out.println(respDoc.getGreetingsResponse().getReturn());
			stub.startgreetings(reqDoc, callback);
			synchronized(callback){
				while(!callback.isFinished){
					callback.wait(100l);
				}
				System.out.println("End");
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}


异步调用中最重要的是:一定要让main线程保持活动状态,我曾经犯的一个让我很迷惑的错误是:支线程在在完成之前,main线程就结束了,导致非预期结果,让我感到很迷茫,看了网上的一些例子才明白。
还有一点就是那个回调类,一定要重写receiveErrorgreetings()方法,否则不会报任何异常。
  • Hello.jar (413.7 KB)
  • 描述: 源代码,除了lib
  • 下载次数: 81
5
0
分享到:
评论
1 楼 Aga 2008-06-11  
文件提取地址http://pickup.mofile.com/1275485956247476

相关推荐

    部署WebService(eclipse-axis2)

    部署WebService(eclipse-axis2)部署WebService(eclipse-axis2)部署WebService(eclipse-axis2)部署WebService(eclipse-axis2)部署WebService(eclipse-axis2)

    axis2开发webservice(二)

    资源包含了:axis2-1.7.4-bin.zip、axis2-1.7.4-war.zip、axis2-eclipse-codegen-plugin-1.7.4.zip、axis2-eclipse-service-plugin-1.7.4.zip。 myeclipse安装axis2.txt文件:详细说明了myeclipse如何安装axis2插件...

    axis2方式开发webservice

    资源包含了:axis2-1.7.4-bin.zip、axis2-1.7.4-war.zip、axis2-eclipse-codegen-plugin-1.7.4.zip、axis2-eclipse-service-plugin-1.7.4.zip。 myeclipse安装axis2.txt文件:详细说明了myeclipse如何安装axis2插件...

    axis2-eclipse-codegen-plugin-1.5.6.zip

    eclipse的在编写webservice时生成wsdl的插件

    WebService axis2-eclipse-codegen-plugin

    web service axis2

    axis2-eclipse-codegen-plugin-1.7.1

    eclipse 工具通过axis2插件,根据wsdl生成webservice客户端代码。将此文件解压缩,放到%eclipse_home%\eclipse\plugins中,重启eclipse。然后选中项目,新建-other-axis2 wizards 下的axis2 code generate ,然后...

    axis2开发webservice(三)

    资源包含了:axis2-1.7.4-bin.zip、axis2-1.7.4-war.zip、axis2-eclipse-codegen-plugin-1.7.4.zip、axis2-eclipse-service-plugin-1.7.4.zip。 myeclipse安装axis2.txt文件:详细说明了myeclipse如何安装axis2插件...

    AXIS2 Eclipse插件 WSDL

    AXIS2 最新版本1.7.3针对 eclipse插件,一方面可以根据java接口类生成WSDL文件,另一方面可以根据WSDL生成客户端或服务端代码,生成的WSDL文件和代码符合web server SOAP协议规范标准!解压后的jar复制到Eclipse的...

    Axis2调用SAP Webservice源码

    Axis2调用SAP Webservice源码 使用Axis2 org.apache.axis2.eclipse.codegen.plugin_1.6.2.jar插件生成本地Java Proxy同事生成同步和异步调用测试用例 更重要的是配备详细文档,实乃Java与SAP集成是宝典!

    axis2_eclipse_codegen&service_plugin_1.6.2

    axis2 WebService eclipse插件,直接放在\dropins根目录下

    eclipse下开发axis2

    文档是 MyEclipse 如果想用 Eclipse 那么安装插件 看我CSDN博客

    axis2 Eclipse插件

    axis2实现webservice,在Eclipse中打包aar文件插件、新建web service client客户端插件。在Eclipse中新建选项会出现 Axis2 Wizards Axis2 Code Generator Axis2 Service Archiver Web Service Client 等。 资源包括...

    org.apache.axis2.eclipse.codegen.plugin_1.6.4

    axis2是实现webservice的一种技术框架,在官网中提供了基于eclipse的操作插件

    axis2-eclipse-codegen-plugin-1.6.3.zip

    开发webservice需要用到的axis2-eclipse-codegen-plugin-1.6.3.zip

    MyEclipse 8.5 Axis2 插件完整jar包开发webservice

    --org.apache.axis2.eclipse.codegen.plugin_1.6.2.jar --org.apache.axis2.eclipse.service.plugin_1.6.2.jar --javax.xml.bind_2.1.9.v201005080401.jar --javax.xml.stream_1.0.1.v201004272200.jar --javax.xml_...

    axis2 webservice开发 包合集

    axis2-1.6.3-bin.zip axis2-1.6.3-war.zip axis2-eclipse-codegen-plugin-1.6.2.zip axis2-eclipse-service-plugin-1.6.2.zip

    axis2-eclipse-service-plugin-1.6.3.zip

    开发webservice需要用到的Eclipse插件axis2-eclipse-service-plugin-1.6.3.zip

Global site tag (gtag.js) - Google Analytics