网管联盟 | 网管论坛 | 网管u家 | 网管博客 | 网管软件 | 网管求职 | 小游戏 | 网管搜索 | 网管原创 | 网管聚合 | 网管读摘 | 网管焦点 | 世界素材 | 会员投稿 | 会员中心 
中国网管联盟
Windows Linux Cisco 网络技术 数据库 黑客攻防 DotNet Java PHP 认证 新闻资讯 服务器 存储资讯 网络设备 网管学堂 技术专题 焦点 网吧频道
 当前位置: > bitsCN.com > JAVA > Java&XML > WebServices > Eclipse插件实现Axis WebService客户端  

Eclipse插件实现Axis WebService客户端

2005-08-04  作者:BitsCN整理  来源:中国网管联盟  点评 投稿 收藏


  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">
  
  
  
  
  
  
  
  

  
  
  
  
  
  

  
  
  
  
  
  

  
   网管下载dl.bitscn.com
  
  
  
  

  
  
  
  
  
  

  
  
  
  
  
  

  
  
  
  
  
  

  
  
  
  
  
  

  
  
  
  
  
  

  
  
  
  
  
  

  
  
  
  
  
  

  
  

  
  
  
  
  
  
  
  

   网管网www_bitscn_com
    
  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">
  
  
  
  
  
  
网管网www.bitscn.com

  
  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=
网管u家u.bitscn@com

  
  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} ); 网管u家u.bitscn@com
  
  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 中国网管论坛bbs.bitsCN.com
  
  */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
网管网www_bitscn_com

  
  */ 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并返回控制台结果。

TAGs   客户端   实现   插件   the   import   new   action   public   workbench      
 上一篇:使用JWSDP完成Web Service在java的入门(一)   下一篇:ConnectionManager适应多数据库环境
相关文章列表
Eclipse插件实现Axis WebService客户端 评论:
loading.. 评论加载中…
评论:请自觉遵守互联网相关政策法规,评论不得超过250字。

验证码: 注册用户
本类热门排行:
1.Eclipse插件实现Axis WebService客户端
2.WebLogic 9新特性:Web Services(组图)
3.学用Java Web Start
4.Java Web Services的远端调用
5.WebLogic Server 国际化
6.Java Web Service
7.Web Service实现包--AXIS2学习笔记一
8.3步把您的java程序转换为webservice
9.JFreeChart 在 webwork 中的应用
10.WEB开发中的JAVA字符编码经验总结
最新推荐文章:
1.Java的编程过程
2.在 XSL/XSLT 中实现随机排序
3.使用Axis开发Web Service程序
4.Sun公司的WEB服务战略
5.WebLogic的初步研究
6.WebLogic Server 性能调优
7.用Tea简化Web开发
8.学用Java Web Start
9.Weblogic70的配置简单手动配置web app
10.WebLogic 9新特性:Web Services(组图)
网管论坛交流:
·不疯魔不成活
·令你大开眼界的真正标准化机房,已整理重
·为赈灾,女孩舍身拍“裸照”
·Windows Server 2003服务器群集创建和配
·exchange2k3全套官方资料
·双儿一周岁了。。。特殊的礼物来啦。。
·存储备份技术版块守则
·无盘技术交流区守则
·DOS命令基础大全之命令详解<作者吐血
·Windows XP 操作系统默认设置需要注意的