<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    Terry.Li-彬

    虛其心,可解天下之問;專其心,可治天下之學;靜其心,可悟天下之理;恒其心,可成天下之業。

      BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
      143 隨筆 :: 344 文章 :: 130 評論 :: 0 Trackbacks
    1、在%TOMCAT_HOME%\webapps中放入axis2.war,這個可以在www.apache.org下載
    2、啟動Tomcat,將該war包解開
    3、服務端代碼
      
    import java.io.ByteArrayInputStream;
    import java.io.ByteArrayOutputStream;
    import java.io.IOException;
    import java.io.ObjectInputStream;
    import java.io.ObjectOutputStream;

    /**
     * @company      
     *
     * @description 
     *
     * 
    @author      Terry.B.Li
     *
     * @date        2009.1.7
     
    */
    public class WSServer {
        
    public byte[] invoke(String id, byte[] bytes) {
            
            
    byte[] result = null;

            System.out.println(
    "id:" + id);

            Object[] params 
    = byteConvertObj(bytes);
            System.out.print(
    "參數:");
            
    for (Object param : params) {
                System.out.println(param.getClass());
            }

            
    // 通過 Axis2 反射調用返回的對象
            Object resultObj = "返回值";
            
            
    //根據功能號 ID 解析調用方法

            ByteArrayOutputStream arrayOutputStream 
    = new ByteArrayOutputStream();
            ObjectOutputStream objectOutputStream 
    = null;
            
    try {
                objectOutputStream 
    = new ObjectOutputStream(arrayOutputStream);
                objectOutputStream.writeObject(resultObj);
                
                result 
    = arrayOutputStream.toByteArray();
            } 
    catch (IOException e) {
                e.printStackTrace();
            } 
    finally {
                
    try {
                    objectOutputStream.close();
                } 
    catch (IOException e) {
                    e.printStackTrace();
                }
            }
             
            
    return result;
        }

        
    private Object[] byteConvertObj(byte[] bytes) {
            Object[] result 
    = null;
            ByteArrayInputStream byteArrayInputStream 
    = null;
            ObjectInputStream objectInputStream 
    = null;
            
    try {
                byteArrayInputStream 
    = new ByteArrayInputStream(bytes);
                objectInputStream 
    = new ObjectInputStream(byteArrayInputStream);
                result 
    = (Object[]) objectInputStream.readObject();
            } 
    catch (IOException e) {
                e.printStackTrace();
            } 
    catch (ClassNotFoundException e) {
                e.printStackTrace();
            }
            
    return result;
        }
    }

    4、將該代碼編譯后放入%TOMCAT_HOME%\webapps\axis2\WEB-INF\pojo下
    5、客戶端代碼如下
    package com.newegg.lab.ws.client;

    import java.io.ByteArrayInputStream;
    import java.io.ByteArrayOutputStream;
    import java.io.IOException;
    import java.io.ObjectInputStream;
    import java.io.ObjectOutputStream;
    import java.io.Serializable;

    import javax.xml.namespace.QName;

    import org.apache.axis2.addressing.EndpointReference;
    import org.apache.axis2.client.Options;
    import org.apache.axis2.rpc.client.RPCServiceClient;
    import org.apache.commons.logging.Log;
    import org.apache.commons.logging.LogFactory;

    public class WSClient implements Serializable{

        
    private static final long serialVersionUID = -8513162370253557533L;

        
    private static final Log log = LogFactory.getLog(WSClient.class); 
        
        
    private static EndpointReference endpointReference = new EndpointReference("http://localhost:8080/axis2/services/WSServer");
        
        
    private static String namespace = "http://ws.apache.org/axis2";

        
    /**
         * 
    @param args
         
    */
        
    public static void main(String[] args) {
            
    try {
                log.info(invoke(
    "123456""aaa""得到的的""埃擔罰埃擔罰",34,new WSClient()));
                } 
    catch (Exception e) {
                    e.printStackTrace();
                }
            log.info(
    "OK");
        }
        
        
    private static Object invoke(String id,Object params){
            Object result 
    = null;
            
    try {
                RPCServiceClient serviceClient 
    = new RPCServiceClient();
                Options options 
    = serviceClient.getOptions();
                options.setTo(endpointReference);
                QName qname 
    = new QName(namespace,"invoke");
                Class[] clz 
    = new Class[]{byte[].class};
                Object[] _params 
    = new Object[]{id,objConvertByte((Object[])params)};
                Object[] results 
    =  serviceClient.invokeBlocking(qname, _params, clz);
                
    byte[] bytes = (byte[]) results[0];
                result 
    = byteConvertObj(bytes);
            } 
    catch (Exception e) {
                e.printStackTrace();
            }
            
    return result;
        }
        
        
    private static byte[] objConvertByte(Object obj){
            
    byte[] result = null;
            ByteArrayOutputStream byteArrayOutputStream 
    = null;
            ObjectOutputStream objectOutputStream 
    = null;
            
    try {
                byteArrayOutputStream 
    = new ByteArrayOutputStream();
                objectOutputStream  
    = new ObjectOutputStream(byteArrayOutputStream);
                objectOutputStream.writeObject(obj);
                result 
    = byteArrayOutputStream.toByteArray();
            } 
    catch (IOException e) {
                e.printStackTrace();
            } 
    finally {
                
    try {
                    objectOutputStream.close();
                    byteArrayOutputStream.close();
                } 
    catch (IOException e) {
                    e.printStackTrace();
                }
            }
            
    return result;
        }
        
        
    private static Object byteConvertObj(byte[] bytes){
            Object result 
    = null;
            ByteArrayInputStream byteArrayInputStream 
    = null;
            ObjectInputStream objectInputStream 
    = null;
            
    try {
                byteArrayInputStream 
    = new ByteArrayInputStream(bytes);
                objectInputStream 
    = new ObjectInputStream(byteArrayInputStream);
                result 
    = objectInputStream.readObject();
            } 
    catch (IOException e) {
                e.printStackTrace();
            } 
    catch (ClassNotFoundException e) {
                
    // TODO Auto-generated catch block
                e.printStackTrace();
            }
            
    return result;
        }
    }

    6、將客戶端代碼打包放入%TOMCAT_HOME%\webapps\axis2\WEB-INF\lib下
    7、啟動Tomcat
    8、測試訪問:http://localhost:8080/axis2/services/WSServer?wsdl
    9、執行客戶端代碼

    posted on 2009-01-08 02:25 禮物 閱讀(1023) 評論(1)  編輯  收藏 所屬分類: web service

    評論

    # re: (原創)用Axis2寫的通用WebService組件 2009-08-10 15:42 禮物
    太強了  回復  更多評論
      

    主站蜘蛛池模板: 亚洲欧美熟妇综合久久久久| 亚洲精品中文字幕无乱码| 猫咪免费人成网站在线观看入口| 四虎在线免费播放| 亚洲乱妇熟女爽到高潮的片| 毛色毛片免费观看| 亚洲AV日韩AV一区二区三曲| 国产精品久免费的黄网站| 羞羞网站在线免费观看| 亚洲性在线看高清h片| 成人毛片100免费观看| 亚洲A∨无码无在线观看| 久久久久高潮毛片免费全部播放| 久久亚洲精品成人AV| 中文字幕乱码免费视频| 亚洲精品美女久久久久久久| 国产高清免费在线| 国产精品免费久久久久影院| 久久精品国产精品亚洲艾| 8888四色奇米在线观看免费看| 亚洲一区二区三区免费在线观看| 成年人视频在线观看免费| 国产成人综合亚洲| 国产一精品一aⅴ一免费| 亚洲精品视频免费| 亚洲国产综合专区在线电影| 日韩免费一区二区三区在线| jizzjizz亚洲日本少妇| 美丽姑娘免费观看在线观看中文版| 亚洲男人电影天堂| 国产免费一区二区三区VR| 国产一级婬片A视频免费观看| 亚洲一二成人精品区| 午夜dj免费在线观看| 亚洲网站在线播放| 日韩一级视频免费观看| 日韩av无码免费播放| 国产成人精品亚洲2020| 国产亚洲色婷婷久久99精品91| 2022久久国产精品免费热麻豆| 国产成人亚洲综合a∨|