当前位置:编程学习 > JSP >>

第一个Type Mapping测试成功...

答案:测试环境:

  WebSphere 3.5
  Apache SOAP 2.2

布署描述文件(DeploymentDescriptor.xml):

<isd:service xmlns:isd="http://xml.apache.org/xml-soap/deployment"
             id="urn:AddressManager">
  <isd:provider type="java"
                scope="Application"
                methods="newAddress">
    <isd:java class="soap.AddressManager"/>
  </isd:provider>
  
  <isd:faultListener>org.apache.soap.server.DOMFaultListener</isd:faultListener>

  <isd:mappings>
    <isd:map encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
             xmlns:x="urn:xml-soap-mapping-test" qname="x:address"
             javaType="soap.Address"
             java2XMLClassName="org.apache.soap.encoding.soapenc.BeanSerializer"
             xml2JavaClassName="org.apache.soap.encoding.soapenc.BeanSerializer"/>
  </isd:mappings>
</isd:service>

布署批处理(Deploy.bat):

java org.apache.soap.server.ServiceManagerClient http://localhost/soap/servlet/rpcrouter deploy DeploymentDescriptor.xml
pause

Address.java:

package soap;

/**
* 此处插入类型说明。
* 创建日期:(2001-12-13 14:25:30)
* @author:Administrator
*/
public class Address {
    public java.lang.String name;
    public java.lang.String address;
/**
* 此处插入方法说明。
* 创建日期:(2001-12-13 14:26:08)
* @return java.lang.String
*/
public java.lang.String getAddress() {
    return address;
}
/**
* 此处插入方法说明。
* 创建日期:(2001-12-13 14:25:53)
* @return java.lang.String
*/
public java.lang.String getName() {
    return name;
}
/**
* 此处插入方法说明。
* 创建日期:(2001-12-13 14:26:08)
* @param newAddress java.lang.String
*/
public void setAddress(java.lang.String newAddress) {
    address = newAddress;
}
/**
* 此处插入方法说明。
* 创建日期:(2001-12-13 14:25:53)
* @param newName java.lang.String
*/
public void setName(java.lang.String newName) {
    name = newName;
}
}

AddressManager.java:

package soap;

import java.net.*;
import java.util.*;

import org.apache.soap.*;
import org.apache.soap.rpc.*;
import org.apache.soap.encoding.*;
import org.apache.soap.encoding.soapenc.*;
import org.apache.soap.util.xml.*;

/**
* 此处插入类型说明。
* 创建日期:(2001-12-13 14:27:05)
* @author:Administrator
*/
public class AddressManager {
/**
* 启动应用程序。
* @param args 命令行自变量数组
*/
public static void main(java.lang.String[] args) {
    SOAPMappingRegistry registry = new SOAPMappingRegistry();
    BeanSerializer bs = new BeanSerializer();
    registry.mapTypes("http://schemas.xmlsoap.org/soap/encoding/", new QName("urn:xml-soap-mapping-test","address"), Address.class, bs, bs);
    
    String name = "何志强";
    String address = "北京";

    Vector params = new Vector();
    params.add(new Parameter("name", String.class, name, null));
    params.add(new Parameter("address", String.class, address, null));
    
    Call call = new Call();
    call.setSOAPMappingRegistry(registry);
    call.setTargetObjectURI("urn:AddressManager");
    call.setMethodName("newAddress");
    call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
    call.setParams(params);

    try {
        Response res = call.invoke(new URL("http://localhost/soap/servlet/rpcrouter"), "");
        if ( res.generatedFault() ) {
            System.out.println(res.getFault());
        } else {
            Address ret = (Address)res.getReturnValue().getValue();
            System.out.print("姓名:");
            System.out.println(ret.getName());
            System.out.print("地址:");
            System.out.println(ret.getAddress());
        }
    } catch (Exception ex) {
        ex.printStackTrace(System.out);
    }
}
/**
* 此处插入方法说明。
* 创建日期:(2001-12-13 14:28:00)
* @return soap.Address
* @param name java.lang.String
* @param address java.lang.String
*/
public Address newAddress(String name, String address) {
    Address ret = new Address();
    
    ret.setName(name);
    ret.setAddress(address);
    
    return ret;
}
}

上一个:J2ME常用名字解释 转
下一个:DOM概览

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,