Terry.Li-彬

          虛其心,可解天下之問;專其心,可治天下之學(xué);靜其心,可悟天下之理;恒其心,可成天下之業(yè)。

            BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
            143 隨筆 :: 344 文章 :: 130 評論 :: 0 Trackbacks
          1 建立Eclipse插件
            
            File->New->Project->Plug-in development的Plug-in project->Next,填寫Project名,Next, 填寫內(nèi)容,Next,選擇Create plug-in using one of the templates,選擇Hello,World,F(xiàn)inish。
            
            在視圖可看到plugin.xml,在里加上運(yùn)行調(diào)用Web Service所需jar包。內(nèi)容如下:
            
            
            
            
            
               
            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 建立調(diào)用Web Service類,該類實(shí)現(xiàn)調(diào)用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");
            
            //開始調(diào)用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方法里的內(nèi)容是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 調(diào)試
            
            首先啟動Axis服務(wù)器,然后選擇Eclipse的Run菜單的Run As -〉Run time workbench。
            
            這樣會啟動另一個Eclipse workbench,在這個workbench里你會看到toolbar里新增了一個按鈕,
            
            點(diǎn)擊按鈕就會調(diào)用Webservice并返回控制臺結(jié)果。
          posted on 2007-09-11 10:12 禮物 閱讀(1684) 評論(0)  編輯  收藏 所屬分類: web service
          主站蜘蛛池模板: 安仁县| 丰镇市| 洞头县| 通州市| 东安县| 福贡县| 弥渡县| 宝应县| 香河县| 房产| 聊城市| 华阴市| 宿松县| 东明县| 禹州市| 和林格尔县| 黑山县| 渝北区| 那坡县| 永顺县| 抚顺县| 阿巴嘎旗| 霸州市| 宁河县| 通海县| 普定县| 义乌市| 台南县| 大姚县| 淮阳县| 合作市| 宁波市| 刚察县| 沛县| 岳普湖县| 神农架林区| 前郭尔| 衡水市| 安庆市| 余江县| 宁安市|