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

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

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

    Terry.Li-彬

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

      BlogJava :: 首頁(yè) :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
      143 隨筆 :: 344 文章 :: 130 評(píng)論 :: 0 Trackbacks
    首先確定已經(jīng)安裝好axis2 并把相應(yīng)的war包放到servlet容器下,我用的是 tomcat.
        容器自動(dòng)部署war包,可以看到下面的目錄結(jié)構(gòu):
    axis2

         我們做的服務(wù)放在services目錄下就可以了。

    第一步:創(chuàng)建服務(wù) StockQuoteService.java
    package samples.quickstart.service.pojo;

    import java.util.HashMap;

    public class StockQuoteService {
        
    private HashMap map = new HashMap();

        
    public double getPrice(String symbol) {
            Double price 
    = (Double) map.get(symbol);
            
    if (price != null{
                
    return price.doubleValue();
            }

            
    return 42.00;
        }


        
    public void update(String symbol, double price) {
            map.put(symbol, 
    new Double(price));
        }

        
        
    public String echo(String name){
            
    return "Hello,"+name+"!";
        }

    }

     
       這個(gè)服務(wù)是一個(gè)POJO,不再解釋。

    第二步:創(chuàng)建服務(wù)描述 services.xml
    <service name="StockQuoteService" scope="application" targetNamespace="http://quickstart.samples/">
        
    <description>
            Stock Quote Service
        
    </description>
        
    <messageReceivers>
            
    <messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-only"
                             class
    ="org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver"/>
            
    <messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-out"
                             class
    ="org.apache.axis2.rpc.receivers.RPCMessageReceiver"/>
        
    </messageReceivers>
        
    <schema schemaNamespace="http://quickstart.samples/xsd"/>
        
    <parameter name="ServiceClass">samples.quickstart.service.pojo.StockQuoteService</parameter>
    </service>

    在服務(wù)描述 services.xml 中定義了幾個(gè)屬性值。

    第三步:組裝成axis2服務(wù)的文件目錄格式:
    StockQuoteService
       - META-INF
          - services.xml
       - samples
          - quickstart
            - service
              - pojo
                - StockQuoteService.class

    文件夾名字為StockQuoteService,下面有兩個(gè)子文件夾META-INF,samples分別存放服務(wù)描述XML和服務(wù)的CLASS。

    第四步:將
    StockQuoteService文件夾拷到%TOMCAT_HOME%\webapps\axis2\WEB-INF\services下并啟動(dòng)TOMCAT,
    這時(shí)訪問:http://localhost:8080/axis2/rest/StockQuoteService/echo?name=World 看看是不是得到:

    <ns:echoResponse>
    <ns:return>Hello,World!</ns:return>
    </ns:echoResponse>

    yes! 說明服務(wù)已經(jīng)配置成功了,接下來創(chuàng)建一個(gè)客戶端訪問服務(wù):

    客戶端需要兩個(gè)jar文件,可以在axis2安裝目錄的lib下找到,這兩個(gè)是: axiom-api-1.2.jar,axis2-kernel-1.1.jar

    AXIOMClient.java
    package samples.quickstart.clients;

    //axiom-api-1.2.jar
    import org.apache.axiom.om.OMAbstractFactory;
    import org.apache.axiom.om.OMElement;
    import org.apache.axiom.om.OMFactory;
    import org.apache.axiom.om.OMNamespace;
    //axis2-kernel-1.1.jar
    import org.apache.axis2.Constants;
    import org.apache.axis2.addressing.EndpointReference;
    import org.apache.axis2.client.Options;
    import org.apache.axis2.client.ServiceClient;

    public class AXIOMClient {

        
    private static EndpointReference targetEPR = 
            
    new EndpointReference(
                                  
    "http://localhost:8080/axis2/services/StockQuoteService");

        
    public static OMElement getPricePayload(String symbol) {
            OMFactory fac 
    = OMAbstractFactory.getOMFactory();
            OMNamespace omNs 
    = fac.createOMNamespace(
                                                     
    "http://quickstart.samples/xsd""tns");

            OMElement method 
    = fac.createOMElement("getPrice", omNs);
            OMElement value 
    = fac.createOMElement("symbol", omNs);
            value.addChild(fac.createOMText(value, symbol));
            method.addChild(value);
            
    return method;
        }


        
    public static OMElement echoServie(String name){
            OMFactory fac 
    = OMAbstractFactory.getOMFactory();
            OMNamespace omNs 
    = fac.createOMNamespace(
                    
    "http://quickstart.samples/xsd""tns");
            
            OMElement method 
    = fac.createOMElement("echo", omNs);
            OMElement value 
    = fac.createOMElement("name", omNs);
            value.addChild(fac.createOMText(value, name));
            method.addChild(value);
            
    return method;
        }

        
    public static OMElement updatePayload(String symbol, double price) {
            OMFactory fac 
    = OMAbstractFactory.getOMFactory();
            OMNamespace omNs 
    = fac.createOMNamespace(
                                                     
    "http://quickstart.samples/xsd""tns");

            OMElement method 
    = fac.createOMElement("update", omNs);

            OMElement value1 
    = fac.createOMElement("symbol", omNs);
            value1.addChild(fac.createOMText(value1, symbol));
            method.addChild(value1);

            OMElement value2 
    = fac.createOMElement("price", omNs);
            value2.addChild(fac.createOMText(value2,
                                             Double.toString(price)));
            method.addChild(value2);
            
    return method;
        }


        
    public static void main(String[] args) {
            
    try {
                OMElement echoServie 
    = echoServie("Bene.Wu");
                OMElement getPricePayload 
    = getPricePayload("WSO");
                OMElement updatePayload 
    = updatePayload("WSO"128.42);
                Options options 
    = new Options();
                options.setTo(targetEPR);
                options.setTransportInProtocol(Constants.TRANSPORT_HTTP);

                ServiceClient sender 
    = new ServiceClient();
                sender.setOptions(options);

                OMElement resultEcho 
    = sender.sendReceive(echoServie);
                String responseEcho 
    = resultEcho.getFirstElement().getText();
                System.err.println(responseEcho);
                
                sender.fireAndForget(updatePayload);
                System.err.println(
    "done");
                
                OMElement result 
    = sender.sendReceive(getPricePayload);
                String response 
    = result.getFirstElement().getText();
                System.err.println(
    "Current price of WSO: " + response);

            }
     catch (Exception e) {
                e.printStackTrace();
            }

        }

        
    }



    運(yùn)行一下,看看結(jié)果是不是:
    Hello,Bene.Wu!
    done
    Current price of WSO: 128.42

        哈,bingo!  axis2一共有五種創(chuàng)建服務(wù)的方式和四種創(chuàng)建客戶端的方式,我覺得只要選擇自己適合的方式就可以了,沒有必要糾纏在技術(shù)細(xì)節(jié)上。接下來我打算繼續(xù)學(xué)習(xí)和研究axis2的一些實(shí)現(xiàn)細(xì)節(jié)以及OSGi插件在axis2中的應(yīng)用。

        axis2和OSGi一樣 帶來的不僅僅是服務(wù)實(shí)現(xiàn)技術(shù),而是對(duì)軟件架構(gòu)的沖擊。
    我覺得SOA時(shí)代已經(jīng)到來,你準(zhǔn)備好了嗎?
    posted on 2007-11-21 18:02 禮物 閱讀(1247) 評(píng)論(0)  編輯  收藏 所屬分類: web service
    主站蜘蛛池模板: 亚洲综合视频在线| 中文字幕在线观看亚洲视频| 亚洲日韩中文字幕| 深夜a级毛片免费视频| 亚洲精品免费观看| 国产最新凸凹视频免费| 亚洲AV无码成人精品区蜜桃| 亚洲欧洲免费无码| 久久国产精品免费网站| 日韩免费三级电影| 亚洲综合久久综合激情久久 | 亚洲精品亚洲人成在线| 免费无码黄网站在线看| 午夜毛片不卡免费观看视频| 亚洲国产精品一区第二页| 亚洲JIZZJIZZ妇女| 最近中文字幕免费2019| 亚洲国产精品狼友中文久久久| 亚洲熟妇无码久久精品| 男女一进一出抽搐免费视频| 毛片免费全部免费观看| 亚洲AV天天做在线观看| 免费人成网站永久| 在线视频观看免费视频18| 亚洲成AV人片在线播放无码| 精品久久久久久亚洲综合网| 免费黄色网址网站| 亚洲另类激情综合偷自拍图| 自拍偷自拍亚洲精品偷一| 99在线精品视频观看免费| 亚洲国产综合无码一区| 黄色一级视频免费| 成人au免费视频影院| 亚洲精品国产手机| a级毛片黄免费a级毛片| vvvv99日韩精品亚洲| 亚洲日韩乱码中文字幕| 天天影院成人免费观看| 亚洲AV无码一区东京热久久| 一区二区视频免费观看| 国产一级做a爱免费视频|