zoukankan      html  css  js  c++  java
  • tomcat 用AXIS2发布WebService 网站的方法

    Axis2+tomcat7.0 实现webService 服务端发布与客户端的调用。  

    Aixs2开发webService的方法有很多,在此只介绍一种比较简单的实现方法。

    第一步:首先要下载开发所需要的jar包   

    下载:

    axis2-1.6.2-war.zip  http://www.apache.org/dist//axis/axis2/Java/core/1.6.2/ 

    下载完后将axis2.war放至tomcat安装目录下的webapps文件夹下,然后启动tomcat后,在webapps目录下会生成axis2文件夹。  访问http://localhost:8080/axis2/能看到以下页面表示axis2运行成功。    

    第二步  在MyEclipse下新建Web Project,工程名:elecProject。新建包cn.itcast.elec.service,在cn.itcast.elec.service下新建类WebSystemDDLServiceImpl。

    [java] view plain copy
     
    1. package cn.itcast.elec.service.impl;  
    2.   
    3. import java.util.ArrayList;  
    4. import java.util.LinkedHashMap;  
    5. import java.util.List;  
    6. import java.util.Map;  
    7.   
    8. import org.apache.commons.lang.StringUtils;  
    9. import org.springframework.context.ApplicationContext;  
    10. import org.springframework.context.support.ClassPathXmlApplicationContext;  
    11.   
    12. import cn.itcast.elec.dao.IElecSystemDDLDao;  
    13. import cn.itcast.elec.domain.ElecSystemDDL;  
    14.   
    15. public class WebSystemDDLServiceImpl {  
    16.   
    17.     public String findSystemByKeyword(String keyword) {  
    18.         ApplicationContext ac = new ClassPathXmlApplicationContext("beans.xml");  
    19.         IElecSystemDDLDao elecSystemDDLDao = (IElecSystemDDLDao) ac.getBean(IElecSystemDDLDao.SERVICE_NAME);  
    20.           
    21.         //组织查询条件  
    22.         String condition = "";  
    23.         List<Object> paramsList = new ArrayList<Object>();  
    24.         if(StringUtils.isNotBlank(keyword)){  
    25.             condition += " and o.keyword = ?";  
    26.             paramsList.add(keyword);  
    27.         }  
    28.         Object [] params = paramsList.toArray();  
    29.         //排序语句  
    30.         Map<String, String> orderby = new LinkedHashMap<String, String>();  
    31.         orderby.put("o.ddlCode","asc");//按照数据项的编号升序排列  
    32.         //数据字典进行查询的时候,使用二级缓存增强检索的效率  
    33.         List<ElecSystemDDL> list = elecSystemDDLDao.findColectionByConditionNoPageWithCache(condition, params, orderby);  
    34. //      List<ElecSystemDDL> list = elecSystemDDLDao.findColectionByConditionNoPage(condition, params, orderby);  
    35.         StringBuffer webObject  = new StringBuffer("");//axis2支持String类型和XML的类型  
    36.         if(list!=null && list.size()>0){  
    37.             for(int i=0;i<list.size();i++){  
    38.                 webObject.append(list.get(i).getDdlName()+",");//值之间用逗号分隔  
    39.             }  
    40.             webObject.deleteCharAt(webObject.length()-1);  
    41.         }  
    42.         return webObject.toString();  
    43.     }  
    44. }  

    在WEB-INF目录下修改web.xml文件,内容如下:  

    [html] view plain copy
     
    1. <?xml version="1.0" encoding="UTF-8"?>   
    2. <web-app version="2.5"   xmlns="http://java.sun.com/xml/ns/javaee"    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   xsi:schemaLocation="http://java.sun.com/xml/ns/javaee   http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">       
    3. <!--Axis2 config start-->   
    4. <servlet>    
    5. <servlet-name>AxisServlet</servlet-name>   <servlet-class>org.apache.axis2.transport.http.AxisServlet</servlet-class >   <load-on-startup>1</load-on-startup>   
    6. </servlet>    
    7. <servlet-mapping>       
    8. <servlet-name>AxisServlet</servlet-name>    <url-pattern>/services/*</url-pattern>     
    9. </servlet-mapping>      
    10. <!--Axis2  end-->     
    11. </web-app>     

    把tomcat安装目录下的webapps/axis2/WEB-INF下的modules、service和conf文件拷至itcastProject下的WEB-INF目录下。同时把lib下的如下jar包也拷到项目的lib包下

    为了与项目的其他包不发生冲突,需要的jar包有:

    然后在WEB-INF/services下新建systemDDLService/META-INF路径,

    META-INF下新建services.xml,

    内容如下:  

    [html] view plain copy
     
    1. <?xml version="1.0" encoding="UTF-8"?>  
    2. <service name="systemDDLService">         
    3.     <description>elecProject Service Example</description>          
    4.     <parameter name="ServiceClass">cn.itcast.elec.service.impl.WebSystemDDLServiceImpl</parameter>    
    5.     <operation name="findSystemByKeyword">             
    6.         <messageReceiver  class="org.apache.axis2.rpc.receivers.RPCMessageReceiver" />         
    7.     </operation>  
    8. </service>   



    启动tomcat后访问:

    http://127.0.0.1:8080/elecProject/services/systemDDLService?wsdl能看到服务信息了。  到此Axis2的WebService服务已成功发布。

    看webservice的使用说明书,记住要从下向上看。

    (1)

    (2)

     

    (3)

     

    (4)

     

    (5)

     

    Axis2客户端调用:

    下面看看利用axis2 客户端调用实例   

    客户端程序需要的jar包

  • 相关阅读:
    archdexls主题游戏页面game-play.php有评论时,报错( ! ) Warning: printf(): Too few arguments in D:wampwwwwp-content hemesarcadexlsgames-play.php on line 97
    完美解决方案:wordpress后台进不去,用户名、密码输入了登陆没有反应(有更新)
    试验如何通过审核Google AdSense——我跟谷歌ads杠上啦
    BuddyPress创建组、查看成员信息等找不到页面
    〖wordpress实用小技巧〗添加几个字符实现子目录访问转移到域名直接访问
    hibernate不调用save也保存上了
    92. Reverse Linked List II
    86. Partition List
    142. Linked List Cycle II
    234. Palindrome Linked List
  • 原文地址:https://www.cnblogs.com/pangguoming/p/6437850.html
Copyright © 2011-2022 走看看