• struts2结合axis开发webservice


    第一步:引入axis的依赖jar包 

     

    第二步:修改web.xml文件   

    <listener>
      	<listener-class>org.apache.axis.transport.http.AxisHTTPSessionListener</listener-class>
      </listener>
      <servlet>
        <display-name>Apache-Axis Servlet</display-name>
        <servlet-name>AxisServlet</servlet-name>
        <servlet-class>org.apache.axis.transport.http.AxisServlet</servlet-class>
      </servlet>
      <servlet-mapping>
        <servlet-name>AxisServlet</servlet-name>
        <url-pattern>/servlet/AxisServlet</url-pattern>
      </servlet-mapping>
      <servlet-mapping>
        <servlet-name>AxisServlet</servlet-name>
        <url-pattern>/services/*</url-pattern>
      </servlet-mapping>
    

    第三步:在struts.properties文件中新增 struts.action.excludePattern=/services/.*,/servlet/AxisServlet

    第四部:server-config.wsdd编写

     

     

     

     

     

     

    server-config.wsdd代码编写:

    <?xml version="1.0" encoding="UTF-8"?>
    <deployment xmlns="http://xml.apache.org/axis/wsdd/" xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
     <globalConfiguration>
      <parameter name="sendMultiRefs" value="true"/>
      <parameter name="disablePrettyXML" value="true"/>
      <parameter name="adminPassword" value="admin"/>
      <parameter name="attachments.Directory" value="D:apache-tomcat-6.0.24webappsCHIMSWEBWEB-INFattachments"/>
      <parameter name="dotNetSoapEncFix" value="true"/>
      <parameter name="enableNamespacePrefixOptimization" value="false"/>
      <parameter name="sendXMLDeclaration" value="true"/>
      <parameter name="attachments.implementation" value="org.apache.axis.attachments.AttachmentsImpl"/>
      <parameter name="sendXsiTypes" value="true"/>
      <requestFlow>
       <handler type="java:org.apache.axis.handlers.JWSHandler">
        <parameter name="scope" value="session"/>
       </handler>
       <handler type="java:org.apache.axis.handlers.JWSHandler">
        <parameter name="scope" value="request"/>
        <parameter name="extension" value=".jwr"/>
       </handler>
      </requestFlow>
     </globalConfiguration>
     <handler name="URLMapper" type="java:org.apache.axis.handlers.http.URLMapper"/>
     <handler name="LocalResponder" type="java:org.apache.axis.transport.local.LocalResponder"/>
     <handler name="Authenticate" type="java:org.apache.axis.handlers.SimpleAuthenticationHandler"/>
     <service name="chimsBoneServer" provider="java:RPC">
      <parameter name="allowedMethods" value="*"/>
      <parameter name="className" value="com.zhongzhi.chims.service.chimswebservice.server.ChimsBoneServer"/>
      <beanMapping languageSpecificType="java:com.zhongzhi.chims.model.EvalBoneAge" qname="ns1:EvalBoneAge" xmlns:ns1="urn:EvalBoneAge"/>
     </service>
     
     <!-- 手机app调用  name="className" value="webservice接口实现类"  name="allowedMethods" value="*"表示可以调用类里面的所有方法 -->
      <service name="ChimsAppImplService" provider="java:RPC">
    	  <parameter name="allowedMethods" value="*"/>
    	  <parameter name="className" value="com.zhongzhi.chims.service.App.service.ChimsAppImplService"/>
     </service>
     
     <service name="AdminService" provider="java:MSG">
      <parameter name="allowedMethods" value="AdminService"/>
      <parameter name="enableRemoteAdmin" value="false"/>
      <parameter name="className" value="org.apache.axis.utils.Admin"/>
      <namespace>http://xml.apache.org/axis/wsdd/</namespace>
      <namespace>http://xml.apache.org/axis/wsdd/</namespace>
     </service>
     <service name="Version" provider="java:RPC">
      <parameter name="allowedMethods" value="getVersion"/>
      <parameter name="className" value="org.apache.axis.Version"/>
     </service>
     <transport name="http">
      <requestFlow>
       <handler type="URLMapper"/>
       <handler type="java:org.apache.axis.handlers.http.HTTPAuthHandler"/>
      </requestFlow>
      <parameter name="qs:list" value="org.apache.axis.transport.http.QSListHandler"/>
      <parameter name="qs:wsdl" value="org.apache.axis.transport.http.QSWSDLHandler"/>
      <parameter name="qs.list" value="org.apache.axis.transport.http.QSListHandler"/>
      <parameter name="qs.method" value="org.apache.axis.transport.http.QSMethodHandler"/>
      <parameter name="qs:method" value="org.apache.axis.transport.http.QSMethodHandler"/>
      <parameter name="qs.wsdl" value="org.apache.axis.transport.http.QSWSDLHandler"/>
     </transport>
     <transport name="local">
      <responseFlow>
       <handler type="LocalResponder"/>
      </responseFlow>
     </transport>
    </deployment>
    

      下面就可以开始webservice接口开发了

    webservice接口:

    package com.zhongzhi.chims.service.App.service;
    
    /***
     * 
     * @author pxh</br>
     *
     * 2015-12-9 上午11:50:26</br>
     * 
     * chims系统与手机APP对接服务
     */
    public interface ChimsAppInterfaceService extends java.rmi.Remote{
    
    	/**
    	 * 获取儿童信息
    	 * @param appChildInfo
    	 * @throws java.rmi.RemoteException
    	 */
    	public void getChildBasicInfo(java.lang.String childInfoXml) throws java.rmi.RemoteException;
    	
    	/***
    	 * 身高、体重对比
    	 * @param childId   儿童id
    	 * @param height    身高	
    	 * @param weight	体重
    	 * @param boneAge	骨龄
    	 * @return
    	 * @throws java.rmi.RemoteException
    	 */
    	public java.lang.String sendHeightAndWeight(java.lang.String childId,java.lang.String height,java.lang.String weight,String boneAge)throws java.rmi.RemoteException;
    
    	/***
    	 * 五年长高目标(成长跑道)
    	 * @param childId
    	 * @param currentHeight
    	 * @return
    	 * @throws java.rmi.RemoteException
    	 */
    	public java.lang.String longHighTarget(java.lang.String childId,java.lang.String currentHeight)throws java.rmi.RemoteException;
    
    	
    	/***
    	 * 风险评估
    	 * @param childId
    	 * @param riskXml
    	 * @return
    	 * @throws java.rmi.RemoteException
    	 */
    	public java.lang.String riskAssessment(java.lang.String childId,java.lang.String riskXml) throws java.rmi.RemoteException;
    }
    

      webservice接口实现类:

    package com.zhongzhi.chims.service.App.service;
    
    import java.rmi.RemoteException;
    
    public class ChimsAppImplService implements ChimsAppInterfaceService {
    
    	public void getChildBasicInfo(String childInfoXml) throws RemoteException {
    		System.out.println(childInfoXml);
    	}
    
    	/***
    	 * 儿童身高、体重对比
    	 */
    	public String sendHeightAndWeight(String childId, String height,
    			String weight, String boneAge) throws RemoteException {
    		//String str="<returns><state>0</state><heightStandard></heightStandard></returns>";
    		StringBuffer buffer=new StringBuffer();
    		buffer.append("<returns>");
    		buffer.append("<state>0</state>");
    		buffer.append("<heightStandard>84</heightStandard>");
    		buffer.append("<ageHeight>2</ageHeight>");
    		buffer.append("<boneAgeHeight>2</boneAgeHeight>");
    		buffer.append("<weightStandard>34</weightStandard>");
    		buffer.append("<ageweight>2</ageweight>");
    		buffer.append("<heightAndWeight>2</heightAndWeight>");
    		buffer.append("</returns>");
    		return buffer.toString();
    	}
    
    	/***
    	 * 五年成长目标(成长跑道)
    	 */
    	public String longHighTarget(String childId, String currentHeight)throws RemoteException {
    		StringBuffer buffer=new StringBuffer();
    		buffer.append("<returns>");
    		buffer.append("<state>0</state>");
    		buffer.append("<forecastHeights>");
    		buffer.append("<forecastHeight age="1" targetHeight="65">-161.2</forecastHeight>");
    		buffer.append("<forecastHeight age="2" targetHeight="71.4">161.2</forecastHeight>");
    		buffer.append("<forecastHeight age="3" targetHeight="90.8">163.1</forecastHeight>");
    		buffer.append("<forecastHeight age="4" targetHeight="99.1">164.9</forecastHeight>");
    		buffer.append("<forecastHeight age="5" targetHeight="107.1">166.7</forecastHeight>");
    		/*buffer.append("<forecastHeight age='6' targetHeight='114.6'>168.6</forecastHeight>");
    		buffer.append("<forecastHeight age='7' targetHeight='122.3'>170.6</forecastHeight>");
    		buffer.append("<forecastHeight age='8' targetHeight='130'>172.7</forecastHeight>");
    		buffer.append("<forecastHeight age='9' targetHeight='137.3'>174.8</forecastHeight>");
    		buffer.append("<forecastHeight age='10' targetHeight='144.4'>176.8</forecastHeight>");
    		buffer.append("<forecastHeight age='11' targetHeight='151.3'>178.7</forecastHeight>");
    		buffer.append("<forecastHeight age='12' targetHeight='158.9'>180.5</forecastHeight>");
    		buffer.append("<forecastHeight age='13' targetHeight='166.2'>182.3</forecastHeight>");
    		buffer.append("<forecastHeight age='14' targetHeight='173.6'>184.2</forecastHeight>");
    		buffer.append("<forecastHeight age='15' targetHeight='181.5'>+184.2</forecastHeight>");*/
    		buffer.append("</forecastHeights></returns>");
    		return buffer.toString();
    	}
    
    	/***
    	 * 风险评估
    	 */
    	public String riskAssessment(String childId, String riskXml)throws RemoteException {
    		StringBuffer buffer=new StringBuffer();
    		buffer.append("<returns>");
    		buffer.append("<state>0</state>");
    		buffer.append("<shortRisk score="60">6</shortRisk>");
    		buffer.append("<obesityRisk score="40">4</obesityRisk>");
    		buffer.append("<precociousRisk score="60">6</precociousRisk>");
    		buffer.append("<diseaseRisk score="100">10</diseaseRisk>");
    		buffer.append("</returns>");
    		return buffer.toString();
    	}
    	
    	
    }
    

      

      

  • 相关阅读:
    “Clang” CFE Internals Manual---中文版---"Clang"C语言前端内部手册
    LLVM每日谈之十七 LLVM/Clang的学习的思考
    Using Clang as a Library----Choosing the Right Interface for Your Application---翻译
    IT人员必备技能之Over the Wall.
    离散傅立叶变换之听声音破解电话号码
    Google Summer of Code: C++ Modernizer Improvements----Monday, November 18, 2013
    Design: cpp11-migrate
    C++11 迁移器的状态--2013年4月15日
    购物系统③完结篇
    (转)Eclipse中junit框架的使用——单元测试
  • 原文地址:https://www.cnblogs.com/ph123/p/5047551.html
Copyright © 2020-2023  润新知