`
touchinsert
  • 浏览: 1316034 次
  • 性别: Icon_minigender_1
  • 来自: 北京
文章分类
社区版块
存档分类
最新评论

创建简单Eclipse插件实现Axis WebService客户端

阅读更多

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,在<Runtime>里加上运行调用Web Service所需jar包。内容如下:

<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.0"?>
<plugin
id="colimas_plugin"
name="Colimas_plugin Plug-in"
version="1.0.0"
provider-name="nova"
class="colimas_plugin.Colimas_pluginPlugin">

<runtime>
<library name="colimas_plugin.jar">
<export name="*"/>
</library>
<library name="lib/activation.jar">
<export name="*"/>
</library>
<library name="lib/axis.jar">
<export name="*"/>
</library>
<library name="lib/commons-beanutils.jar">
<export name="*"/>
</library>
<library name="lib/commons-discovery-0.2.jar">
<export name="*"/>
</library>
<library name="lib/commons-logging-1.0.4.jar">
<export name="*"/>
</library>
<library name="lib/jaxrpc.jar">
<export name="*"/>
</library>
<library name="lib/xalan.jar">
<export name="*"/>
</library>
<library name="lib/xerces.jar">
<export name="*"/>
</library>
<library name="lib/saaj.jar">
<export name="*"/>
</library>
<library name="lib/mail.jar">
<export name="*"/>
</library>
</runtime>

<requires>
<import plugin="org.eclipse.ui"/>
<import plugin="org.eclipse.core.runtime"/>
</requires>

<extension
point="org.eclipse.ui.actionSets">
<actionSet
label="Sample Action Set"
visible="true"
id="colimas_plugin.actionSet">
<menu
label="Sample &amp;Menu"
id="sampleMenu">
<separator
name="sampleGroup">
</separator>
</menu>
<action
label="&amp;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">
</action>
</actionSet>
</extension>

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

分享到:
评论

相关推荐

    webservice axis eclipse客户端插件

    webservice开发,axis的eclipse客户端插件,用于生成webservice客户端代码

    eclipse+tomcat+axis下创建WebService

    WebService 在 Eclipse 中是一个相对直观的过程,涉及到的主要步骤包括安装和配置 Eclipse 插件、设置 Tomcat 和 Axis、编写 Java 类、发布 WebService、编辑 `server.xml` 以及创建和测试 WebService 客户端。...

    axis开发webservice客户端

    标题中的“axis开发webservice客户端”指的是使用Apache Axis框架创建并使用Web服务客户端的过程。Apache Axis是Java平台上的一个开源工具,它简化了SOAP(Simple Object Access Protocol)Web服务的开发,包括...

    Axis2_Codegen_Wizard_1.4.0( eclipse中Webservice客户端生成插件)

    Axis2 Codegen Wizard 1.4.0 是一个专门针对Eclipse集成开发环境设计的插件,用于简化Web服务客户端的生成过程。在Web服务的世界里,开发人员经常需要调用远程服务,以便通过网络进行数据交换。这个插件正是为了解决...

    Axis2 Eclipse WebService插件

    在Eclipse集成开发环境中, Axis2 WebService插件扮演着至关重要的角色,使得开发、调试和测试Web服务变得更加便捷。 首先,让我们深入了解Axis2的核心特性: 1. **模块化架构**:Axis2的设计基于模块化思想,允许...

    eclipse的axis插件 开发 webservice 例程

    4. 创建Web服务:现在,我们可以使用Axis插件将这个实现转换为Web服务。右键点击项目,选择"New" -&gt; "Web Service",在向导中选择"Create a new Web service from scratch",然后选择我们的服务接口`...

    webservice客户端插件1.4.1.rar

    eclipse,myeclipse反向生成webservice客户端插件,将文件夹解压到\MyEclipse 8.5\dropins\目录下重启Mycelipse,在Myeclipse中选择import Axis2 Code Generator项目即可反向生成webservice客户端代码1.4版本,可以...

    eclipse+AXIS开发webservice.doc

    1. **Eclipse插件安装**: - Eclipse提供了Web服务开发的插件,可以从官方网站下载WTP(Web Tools Platform)All-in-One SDK,其中包含了开发Web服务所需的组件。 - 安装插件通常涉及解压缩下载的文件,然后通过...

    axis2支持webservice 自动生成代码客户端服务端代码插件

    使用Axis2的Eclipse插件,开发人员可以导入一个WSDL文件,然后自动创建与之对应的Java服务实现类和服务部署配置文件,以及客户端的Stub类,使得调用Web服务如同调用本地方法一样简单。 在描述中提到的“基于eclipse...

    webservice客户端插件1.6.2.rar

    eclipse,myeclipse反向生成webservice客户端插件,将文件夹解压到\MyEclipse 8.5\dropins\目录下重启Mycelipse,在Myeclipse中选择import Axis2 Code Generator项目即可反向生成webservice客户端代码1.6版本

    eclipse+tomcat+axis2创建webservice

    【知识点详解】 本文将介绍如何使用Eclipse集成开发环境、... Axis2的Eclipse插件大大简化了开发过程,使得服务的创建、部署和测试更加直观。了解并掌握这些步骤,有助于开发者高效地开发基于SOAP或REST的Web服务。

    eclipse+AXIS开发webservice.pdf

    通过上述步骤,你可以成功地在Eclipse中使用AXIS开发和发布一个基本的WebService,并创建一个测试客户端来调用该服务。注意,使用JDK1.5以上的版本可以确保生成的客户端代码能够正确编译和运行。如果遇到问题,如...

    webservice客户端生成工具

    客户端生成工具是实现Web服务交互的关键组件,它能够帮助开发者自动创建与WebService接口进行通信的客户端代码,大大简化了开发流程。本文将详细介绍关于Web服务客户端生成工具的相关知识点。 1. **Web服务标准与...

    部署WebService(eclipse-axis2)

    通过上述步骤,我们不仅完成了基于Eclipse和Axis2的WebService服务端的部署,还实现了客户端的构建与测试。整个过程涉及到的要点如下: - **版本选择**:确保使用的Eclipse和Axis2版本兼容。 - **配置Axis2**:正确...

    Eclipse用Axis框架开发WebService

    2. **Eclipse 集成 Axis 开发 WebService**: Eclipse 是一个广泛使用的 Java IDE,通过 Axis 插件,可以在 Eclipse 中方便地创建和调试 Web 服务。这使得开发者能够在熟悉的环境中进行 WebService 开发,无需离开 ...

    axis2-1.7.7 eclipse的webservice开发插件

    Axis2是Apache软件基金会开发的一款...总之,Axis2 1.7.7 Eclipse插件是Web服务开发者在Eclipse环境中不可或缺的工具,它为Web服务的全生命周期管理提供了强大的支持,使得开发者能够高效地开发、测试和部署Web服务。

    Eclipse Webservice开发插件 AXIS 资料

    6. **消费服务**:对于其他项目,如果需要使用已发布的Web服务,AXIS插件同样提供了生成客户端代理类的功能,使得调用Web服务如同调用本地方法一样简单。 在提供的资料中,可能包含了AXIS的使用教程、示例代码、...

    webservice eclipse插件1

    "webservice eclipse插件1"正是这样一个工具,它专门用于在Eclipse环境中创建、调试和管理Web服务。 首先,让我们深入了解Web服务。Web服务是一种基于开放标准(如XML、SOAP、WSDL和UDDI)的软件接口,允许不同系统...

    myeclipse8.5使用axis2插件开发webservice服务并调用

    通过上述步骤,我们不仅完成了使用MyEclipse 8.5与Axis2插件创建WebService服务的过程,而且还学会了如何从客户端调用这些服务。这种方式极大地简化了分布式系统的开发流程,提高了开发效率。希望本文能够帮助您更好...

Global site tag (gtag.js) - Google Analytics