Eclipse插件实现Axis WebService客户端
日期:2007年6月9日 作者: 查看:[大字体 中字体 小字体]-
1 建立Eclipse插件
File->New->Project->Plug-in development的Plug-in project->Next,填写Project名,Next, 填写内容,Next,选择Create plug-in using one of the templates,选择Hello,World,Finish。
在视图可看到plugin.xml,在里加上运行调用Web Service所需jar包。内容如下:
id="colimas_plugin"
name="Colimas_plugin Plug-in"
version="1.0.0"
provider-name="nova"
class="colimas_plugin.Colimas_pluginPlugin">
point="org.eclipse.ui.actionSets">
label="Sample Action Set"
visible="true"
id="colimas_plugin.actionSet">
label="Sample &Menu"
id="sampleMenu">
name="sampleGroup">
label="&Sample Action"
icon="icons/sample.gif"
class="colimas_plugin.actions.SampleAction"
tooltip="Hello, Eclipse world"
menubarPath="sampleMenu/sampleGroup"
toolbarPath="sampleGroup"
id="colimas_plugin.actions.SampleAction">
2 建立调用Web Service类,该类实现调用Axis的WebService
/*
*
Created on 2005/07/30
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/package com.nova.colimas.plugin.eclipse;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import javax.xml.namespace.QName;import java.io.*;
/**
*@author tyrone
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class SendFileClient { private Call call;
/**
* The constrUCtor.
*/
public SendFileClient() {
try{
Service service=
new Service();
call = (Call) service.createCall();
}catch(Exception ex){ System.out.println(ex.getMessage());
} } public void saveFile(){ try { String endpoint = "http://localhost:8080/axis/services/DocumentFileManagement";
System.out.println("start web service");
call.setTargetEndpointAddress( new java.net.URL(endpoint) );
call.setOperationName(new QName("http://soapinterop.org/", "saveFile"));
File fp=new File("D:\\MyProject\\colimas\\colimas_plugin\\lib\\mail.jar");
BufferedInputStream in=new BufferedInputStream(new FileInputStream(fp));
int len=in.available();
byte[] contents=new byte[len];
in.read(contents,0,len);
System.out.println("begin run");
//开始调用Web Service:DocumentFileManagement的saveFile方法
String ret = (String) call.invoke( new Object[] {fp.getName(),contents} );
in.close();
} catch (Exception e) { System.err.println("error"+e.toString());
}
}
}
3 修改Action类的run方法
Action类的run方法里的内容是Eclipse插件真正要做到事
package colimas_plugin.actions;import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.ui.IWorkbenchWindow;import org.eclipse.ui.IWorkbenchWindowActionDelegate;
import org.eclipse.jface.dialogs.MessageDialog;
import com.nova.colimas.plugin.eclipse.*;
/**
* Our sample action implements workbench action delegate.
* The action proxy will be created by the workbench and
* shown in the UI. When the user tries to use the action,
* this delegate will be created and execution will be
* delegated to it. * @see IWorkbenchWindowActionDelegate
*/public class SampleAction implements IWorkbenchWindowActionDelegate { private IWorkbenchWindow window;
/**
* The constructor.
*/ public SampleAction() { }
/**
* The action has been activated. The argument of the
* method represents the 'real' action sitting
* in the workbench UI.
* @see IWorkbenchWindowActionDelegate#run
*/ public void run(IAction action) { SendFileClient client=new SendFileClient();
client.saveFile();
MessageDialog.openInformation( window.getShell(),
"Colimas_plugin Plug-in", "Colimas Connected");
} /** * Selection in the workbench has been changed. We
* can change the state of the 'real' action here
* if we want, but this can only happen after
* the delegate has been created.
* @see IWorkbenchWindowActionDelegate#selectionChanged
*/ public void selectionChanged(IAction action, ISelection selection) { }
/**
* We can use this method to dispose of any system
* resources we previously allocated.
* @see IWorkbenchWindowActionDelegate#dispose
*/ public void dispose() { }
/**
* We will cache window object in order to
* be able to provide parent shell for the message dialog.
* @see IWorkbenchWindowActionDelegate#init
*/ public void init(IWorkbenchWindow window) { this.window = window;
}
4 调试
首先启动Axis服务器,然后选择Eclipse的Run菜单的Run As -〉Run time workbench。
这样会启动另一个Eclipse workbench,在这个workbench里你会看到toolbar里新增了一个按钮,
点击按钮就会调用Webservice并返回控制台结果。 - [1] [2] 下一页
-
- Eclipse插件实现Axis WebService客户端 相关文章:
- ·Eclipse插件实现Axis WebService客户端
- Eclipse插件实现Axis WebService客户端 相关软件
- 特别声明:本站除部分特别声明禁止转载的专稿外的其他文章可以自由转载,但请务必注明出处和原始作
- 者.文章版权归文章原始作者所有.对于被本站转载文章的个人和网站,我们表示深深的谢意。如果本站转
- 载的文章有版权问题请联系编辑人员,我们尽快予以更正. 转载请注明来源:http://www.hackhome.com
精品推荐
热点TOP10
- ·Servlet简介
- ·Java编写的计算器程序及源代码(1)
- ·Java学生成绩管理系统源代码
- ·servlet和JSP过滤器Filter
- ·Web2.0时代的核心应用:Ajax简介
- ·Struts+Spring+Hibernate实现上传下载
- ·用Java实现音频播放
- ·Java Map 集合类简介
- ·你能过关吗?J2EE面试题集锦(附答案)
- ·在桌面应用中使用JAVA DB
- ·使用poi操作Excel的几点注意事项
- ·java网络五子棋的源代码
- ·候捷谈Java反射机制
- ·J2ME游戏开发实例讲解
- ·开源技术——体验Struts
- ·Java基础:三步学会Java Socket编程
- ·用java实现print screen,读取位图文件,将位图文件转化位jpeg格式并保存成文件输出!
- ·SOAP协议初级指南
- ·JavaDoc用法
- ·FreeMarker概述
特别推荐
- ·你能过关吗?J2EE面试题集锦(附答案)
- ·面向过程与面向对象的区别
- ·Tapestry入门
- ·候捷谈Java反射机制
- ·标准的web.xml
- ·Java异常处理的特殊情况
- ·SOAP协议初级指南
- ·Why Java can be used for games?
- ·用Java Socket制作广播信使程序
- ·J2ME游戏开发实例讲解
- ·用java实现print screen,读取位图文件,将位图文件转化位jpeg格式并保存成文件输出!
- ·[SNAP]实例讲解移动QQ在线平台
- ·0. Preface: Core Technologies
- ·一个简单实用的数据库操作框架
- ·开源技术——体验Struts
- ·Java资料:Swing中的事件处理详细资料
- ·Tomcat性能调整
- ·Java基础:三步学会Java Socket编程
- ·一种通用的输入校验方法和气球泡提示的实现(键盘用户界面模块)
- ·JBoss 4.0 简化了中间件的开发
