towne1 2009-06-12 02:11
浏览 197
已采纳

手机业务系统的对接问题

最近和别的公司做一个手机业务系统
我负责做伺服器程序 那边负责做界面处理
双方约定以webservice的方式实现
(因接口开发与调用双方所采用开发语言不同,许多数据类型都是各自语言特定的,其他程序无法直接使用。故为避免,特采用XML的形式。所有返回结果均用XML以String的形式返回--这是开发文档说明)
然而在交付的时候
我使用的是struts2+xml 是用插件生成的完全符合约定的xml结构

    <package name="xml-default" extends="struts-default">

    &lt;result-types&gt;
        &lt;result-type name="xml" class="com.xxx.xxx.web.struts2.plugin.xml.XmlResult"/&gt;
    &lt;/result-types&gt;
&lt;/package&gt;


&lt;package name="xml" extends="xml-default" namespace="/xml"&gt;
    &lt;global-results&gt; 
        &lt;result name="success" type="xml"&gt;
        &lt;param name="defaultEncoding"&gt;UTF-8&lt;/param&gt;
        &lt;/result&gt;
        &lt;result name="error"&gt;/WEB-INF/jsp/err/myerror-xml.jsp&lt;/result&gt; 
    &lt;/global-results&gt;
    &lt;global-exception-mappings&gt;
        &lt;exception-mapping exception="java.lang.Exception" result="error"/&gt;
    &lt;/global-exception-mappings&gt;       
&lt;/package&gt;</pre><br />想问两个问题:<br />1.我这个算webservice吗?<br />2.可能手机客户端公司要求的是Axis之类的处理方式,那我们这两个系统好对接整合吗?
  • 写回答

6条回答 默认 最新

  • tangqii 2009-06-16 01:59
    关注

    解决方案自己摸索到了 还是谢谢上面各位的热心帮忙,下面说说我的解决方案


    首先在我的pom.xml中加入几个解析包:
    [code="java"]
    soap
    axis
    1.1.0

        <dependency>
          <groupId>soap</groupId>
          <artifactId>jaxrpc</artifactId>
          <version>1.1.0</version>
        </dependency> 
    
        <dependency>
          <groupId>soap</groupId>
          <artifactId>saaj</artifactId>
          <version>1.1.0</version>
        </dependency> 
    
        <dependency>
          <groupId>soap</groupId>
          <artifactId>wsdl4j</artifactId>
          <version>1.6.1</version>
        </dependency> 
    
        <dependency>
          <groupId>commons-discovery</groupId>
          <artifactId>commons-discovery</artifactId>
          <version>0.4</version>
        </dependency>[/code]
    

    然后在我的 web.xml中增加如下配置:
    [code="java"]
    WebServices

    org.apache.axis.transport.http.AxisServlet



    SOAPMonitorService

    org.apache.axis.monitor.SOAPMonitorService


    SOAPMonitorPort
    5001

    100


    AdminServlet

    org.apache.axis.transport.http.AdminServlet

    100


    AxisServlet

    org.apache.axis.transport.http.AxisServlet

    <servlet-mapping>
        <servlet-name>SOAPMonitorService</servlet-name>
        <url-pattern>/SOAPMonitor</url-pattern>
    </servlet-mapping>
    
    <servlet-mapping>
        <servlet-name>AxisServlet</servlet-name>
        <url-pattern>/servlet/AxisServlet</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>AxisServlet</servlet-name>
        <url-pattern>*.jws</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>AxisServlet</servlet-name>
        <url-pattern>/services/*</url-pattern>
    </servlet-mapping>
    
    <servlet-mapping>
        <servlet-name>WebServices</servlet-name>
        <url-pattern>*.jws</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>WebServices</servlet-name>
        <url-pattern>/WebServices/*</url-pattern>
    </servlet-mapping>[/code]
    

    在 web.xml 同等目录增加 server-config.wsdd 的wsdd解析文件
    [code="java"]<?xml version="1.0" encoding="UTF-8"?>
    xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">


    value="true" />






    type="java:org.apache.axis.handlers.JWSHandler">


    type="java:org.apache.axis.handlers.JWSHandler">









    type="java:org.apache.axis.transport.local.LocalResponder" />
    type="java:org.apache.axis.handlers.http.URLMapper" />
    type="java:org.apache.axis.handlers.SimpleAuthenticationHandler" />
    type="java:org.apache.axis.handlers.http.HTTPAuthHandler" />


    type="java:org.apache.axis.handlers.http.HTTPAuthHandler" />





    http://xml.apache.org/axis/wsdd/




    <service name="BusiLink" provider="java:RPC">
        <parameter name="allowedMethods" value="*" />
        <requestFlow>
       </requestFlow>
        <parameter name="className"
            value="com.***.sp.soap.service.impl.BusiLinkImpl" />
        <parameter name="scope" value="Request" />
        <namespace>webservice.***.com</namespace>
    </service>
    
    
    
    
    <transport name="http">
        <requestFlow name="RequestFlow1">
            <handler name="Handler1" type="URLMapper" />
            <handler name="Handler2"
                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:method"
            value="org.apache.axis.transport.http.QSMethodHandler" />
    </transport>
    <transport name="local">
        <responseFlow name="ResponseFlow1">
            <handler name="Handler1" type="LocalResponder" />
        </responseFlow>
    </transport>
    

    [/code]
    由于我已经实现了业务实体pojo在struts2下的解析 所以这里直接以struts2中的action bean来实现webservice 的接口调用,相关代码如下:
    [code="java"]import java.io.Serializable;
    import java.rmi.RemoteException;

    /**

    • @author towne
    • @version 创建时间:2009-6-12 下午03:14:06
    • 类说明 / public interface BusiLink extends Serializable { /* *方法名:QueryYijianList (String businessid) *说 明:根据记录的业务编号 获取审批意见 *输 入:该记录的业务编号 businessid(String)从接口3获取 *返 回:String(XML)
      • @throws RemoteException */ String QueryYijianList (String businessid) throws RemoteException; }[/code] [code="java"]import java.io.StringWriter; import java.rmi.RemoteException;

    import org.springframework.beans.BeansException;
    import org.springframework.context.ApplicationContext;
    import org.springframework.context.ApplicationContextAware;
    import javax.xml.rpc.ServiceException;
    import org.springframework.remoting.jaxrpc.ServletEndpointSupport;

    import com.***.sp.soap.service.BusiLink;
    import com.***.sp.web.struts2.BusiLinkAction;
    import com.***.sp.web.struts2.DataRow;
    import com.***.sp.web.struts2.SpBaseAction;
    import com.***.sp.web.struts2.SpResult;
    import com.***.sp.web.struts2.Table1;
    import com.thoughtworks.xstream.XStream;

    /**

    • @author towne
    • @version 创建时间:2009-6-12 下午03:19:14
    • 类说明
      */
      public class BusiLinkImpl extends ServletEndpointSupport implements BusiLink {
      BusiLinkAction action;
      protected void onInit() throws ServiceException{
      action = (BusiLinkAction)getApplicationContext().getBean("spBusiLinkAction");
      }
      public String QueryYijianList(String businessid) throws RemoteException{
      action.setBusinessid(businessid);
      action.QueryYijianList();
      return toXML(action.getResult());
      }

      public String toXML(SpResult sr){
      XStream xstream = new XStream();
      xstream.alias("result",SpResult.class);
      xstream.alias("DataRow",DataRow.class);
      xstream.useAttributeFor(DataRow.class, "id");
      xstream.addImplicitCollection(DataRow.class, "bean");//去掉集合类型生成xml的父节点
      xstream.addImplicitCollection(Table1.class, "list");
      xstream.useAttributeFor(SpResult.class, "pageCount");
      xstream.useAttributeFor(SpResult.class, "userId");
      xstream.useAttributeFor(SpResult.class, "pageIndex");

      xstream.useAttributeFor(SpResult.class, "typeId");
      xstream.useAttributeFor(Table1.class, "name");
      xstream.useAttributeFor(DataRow.class, "id");
      StringWriter writer = new StringWriter();

      xstream.toXML(sr,writer);

      return writer.toString();
      }
      }[/code]
      这样 开启jetty,测试:
      [code="java"] public void test6656(){
      try{
      String wsdlUrl = "http://localhost:999/sp2/services/BusiLink?wsdl";
      String nameSpaceUri = "http://localhost:999/sp2/services/BusiLink";
      // 创建调用对象
      Service service = new Service();
      Call call = null;
      call = (Call) service.createCall();
      // 调用 getMessage
      System.out.println(">>>getMessage");
      call.setOperationName(new QName(nameSpaceUri, "QueryYijianList"));
      call.setTargetEndpointAddress(new java.net.URL(wsdlUrl));
      String ret = (String) call.invoke(new Object[] {"0906120093901990001"});
      System.out.println("return value is " + ret);
      } catch (Exception e) {
      e.printStackTrace();
      }

      }[/code]
      测试通过 产生需要的xml文件 从而使该系统即支持struts2的调用 也支持webservice的调用 同时支持xml,json,jsp 从而真正达到平台无关性
      /**

    • ps:这分就加给自己吧 我也不客气了
      */

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(5条)
编辑
预览

报告相同问题?

悬赏问题

  • ¥15 MATLAB解决问题
  • ¥20 哪位专业人士知道这是什么原件吗?哪里可以买到?
  • ¥15 关于#c##的问题:treenode反序列化后获取不到上一节点和下一节点,Fullpath和Handle报错
  • ¥15 一部手机能否同时用不同的app进入不同的直播间?
  • ¥15 没输出运行不了什么问题
  • ¥20 输入import torch显示Intel MKL FATAL ERROR,系统驱动1%,: Cannot load mkl_intel_thread.dll.
  • ¥15 点云密度大则包围盒小
  • ¥15 nginx使用nfs进行服务器的数据共享
  • ¥15 C#i编程中so-ir-192编码的字符集转码UTF8问题
  • ¥15 51嵌入式入门按键小项目