⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 whitemesasoap12addtestsvctestcase.java

📁 Java有关XML编程需要用到axis 的源代码 把里面bin下的包导入相应的Java工程 进行使用
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/** * WhiteMesaSoap12AddTestSvcTestCase.java * * This file was auto-generated from WSDL * by the Apache Axis WSDL2Java emitter. */package test.wsdl.soap12.additional;import org.apache.axis.AxisFault;import org.apache.axis.Constants;import org.apache.axis.utils.XMLUtils;import org.apache.axis.client.Call;import org.apache.axis.encoding.ser.BeanDeserializerFactory;import org.apache.axis.encoding.ser.BeanSerializerFactory;import org.apache.axis.constants.Style;import org.apache.axis.constants.Use;import org.apache.axis.message.*;import org.apache.axis.soap.SOAP12Constants;import org.apache.axis.soap.SOAPConstants;import org.w3c.dom.Document;import org.w3c.dom.NodeList;import org.w3c.dom.Node;import org.w3c.dom.Element;import test.wsdl.soap12.additional.xsd.SOAPStruct;import javax.xml.namespace.QName;import javax.xml.rpc.ParameterMode;import java.util.Vector;import java.net.URL;/** * Additional SOAP 1.2 tests. *  * For details, see: *   * http://www.w3.org/2000/xp/Group/2/03/soap1.2implementation.html#addtests *  * Auto-generated from WhiteMesa's WSDL, with additional coding by: * @author Davanum Srinivas (dims@apache.org) * @author Glen Daniels (gdaniels@apache.org) */ public class WhiteMesaSoap12AddTestSvcTestCase extends junit.framework.TestCase {    public static final String STRING_VAL = "SOAP 1.2 is cool!";    public static final float FLOAT_VAL = 3.14F;    public static final Float FLOAT_OBJVAL = new Float(FLOAT_VAL);    public static final int INT_VAL = 69;    public static final Integer INT_OBJVAL = new Integer(INT_VAL);    public final String TEST_NS = "http://soapinterop.org/";    public final QName ECHO_STRING_QNAME = new QName(TEST_NS, "echoString");        // Endpoints    // TODO : Shouldn't be hardcoded!//    public static final String HOST = "http://localhost:8080";    public static String HOST = "http://www.whitemesa.net";    public static String RPC_ENDPOINT = HOST + "/soap12/add-test-rpc";    public static String DOC_ENDPOINT = HOST + "/soap12/add-test-doc";    public static String GET_DOC_ENDPOINT = HOST + "/soap12/add-test-doc/getTime";    public static String GET_RPC_ENDPOINT = HOST + "/soap12/add-test-rpc/getTime";    public static String DOC_INT_ENDPOINT = HOST + "/soap12/add-test-doc-int";    public static String DOC_INT_UC_ENDPOINT = HOST + "/soap12/add-test-doc-int-uc";    private QName SOAPSTRUCT_QNAME = new QName("http://example.org/ts-tests/xsd", "SOAPStruct");    static String configFile = null;    public static void main(String[] args) throws Exception {        // If we have an argument, it's a configuration file.        if (args.length > 0) {            configFile = args[0];        }        WhiteMesaSoap12AddTestSvcTestCase tester = new WhiteMesaSoap12AddTestSvcTestCase("testXMLP5");        tester.setUp();        tester.testXMLP19();        System.out.println("Done.");//        junit.textui.TestRunner.run(WhiteMesaSoap12AddTestSvcTestCase.class);    }    public WhiteMesaSoap12AddTestSvcTestCase(java.lang.String name) {        super(name);    }    public void testSoap12AddTestDocUpperPortWSDL() throws Exception {        javax.xml.rpc.ServiceFactory serviceFactory = javax.xml.rpc.ServiceFactory.newInstance();        java.net.URL url = new java.net.URL(new test.wsdl.soap12.additional.WhiteMesaSoap12AddTestSvcLocator().getSoap12AddTestDocUpperPortAddress() + "?WSDL");        javax.xml.rpc.Service service = serviceFactory.createService(url, new test.wsdl.soap12.additional.WhiteMesaSoap12AddTestSvcLocator().getServiceName());        assertTrue(service != null);    }    public void testSoap12AddTestRpcPortWSDL() throws Exception {        javax.xml.rpc.ServiceFactory serviceFactory = javax.xml.rpc.ServiceFactory.newInstance();        java.net.URL url = new java.net.URL(new test.wsdl.soap12.additional.WhiteMesaSoap12AddTestSvcLocator().getSoap12AddTestRpcPortAddress() + "?WSDL");        javax.xml.rpc.Service service = serviceFactory.createService(url, new test.wsdl.soap12.additional.WhiteMesaSoap12AddTestSvcLocator().getServiceName());        assertTrue(service != null);    }    public void testSoap12AddTestDocIntermediaryPortWSDL() throws Exception {        javax.xml.rpc.ServiceFactory serviceFactory = javax.xml.rpc.ServiceFactory.newInstance();        java.net.URL url = new java.net.URL(new test.wsdl.soap12.additional.WhiteMesaSoap12AddTestSvcLocator().getSoap12AddTestDocIntermediaryPortAddress() + "?WSDL");        javax.xml.rpc.Service service = serviceFactory.createService(url, new test.wsdl.soap12.additional.WhiteMesaSoap12AddTestSvcLocator().getServiceName());        assertTrue(service != null);    }    public void testSoap12AddTestDocPortWSDL() throws Exception {        javax.xml.rpc.ServiceFactory serviceFactory = javax.xml.rpc.ServiceFactory.newInstance();        java.net.URL url = new java.net.URL(new test.wsdl.soap12.additional.WhiteMesaSoap12AddTestSvcLocator().getSoap12AddTestDocPortAddress() + "?WSDL");        javax.xml.rpc.Service service = serviceFactory.createService(url, new test.wsdl.soap12.additional.WhiteMesaSoap12AddTestSvcLocator().getServiceName());        assertTrue(service != null);    }    protected void setUp() throws Exception {        if (configFile == null) {            configFile = System.getProperty("configFile");        }        if (configFile == null) {            return;        }        Document doc = XMLUtils.newDocument(configFile);        NodeList nl = doc.getDocumentElement().getChildNodes();        for (int i = 0; i < nl.getLength(); i++) {            Node node = nl.item(i);            if (!(node instanceof Element))                continue;            Element el = (Element) node;            String tag = el.getLocalName();            String data = XMLUtils.getChildCharacterData(el);            if ("host".equals(tag)) {                HOST = data;                RPC_ENDPOINT = HOST + "/soap12/add-test-rpc";                DOC_ENDPOINT = HOST + "/soap12/add-test-doc";                GET_DOC_ENDPOINT = HOST + "/soap12/add-test-doc/getTime";                GET_RPC_ENDPOINT = HOST + "/soap12/add-test-rpc/getTime";                DOC_INT_ENDPOINT = HOST + "/soap12/add-test-doc-int";                DOC_INT_UC_ENDPOINT = HOST + "/soap12/add-test-doc-int-uc";            } else if ("rpcEndpoint".equals(tag)) {                RPC_ENDPOINT = data;            } else if ("docEndpoint".equals(tag)) {                DOC_ENDPOINT = data;            } else if ("getRpcEndpoint".equals(tag)) {                GET_RPC_ENDPOINT = data;            } else if ("getDocEndpoint".equals(tag)) {                GET_DOC_ENDPOINT = data;            } else if ("docIntEndpoint".equals(tag)) {                DOC_INT_ENDPOINT = data;            } else if ("docIntUcEndpoint".equals(tag)) {                DOC_INT_UC_ENDPOINT = data;            }        }    }    /**     * Test xmlp-1 - call echoString with no arguments (even though it expects     * one).  Confirm bad arguments fault from endpoint.     *      * @throws Exception     */     public void testXMLP1() throws Exception {        Call call = new Call(RPC_ENDPOINT);        call.setSOAPVersion(SOAPConstants.SOAP12_CONSTANTS);        try {            call.invoke(ECHO_STRING_QNAME, null);        } catch (AxisFault fault) {            assertEquals(Constants.FAULT_SOAP12_SENDER, fault.getFaultCode());            QName [] subCodes = fault.getFaultSubCodes();            assertNotNull(subCodes);            assertEquals(1, subCodes.length);            assertEquals(Constants.FAULT_SUBCODE_BADARGS, subCodes[0]);            return;        }        fail("Didn't catch expected fault");    }        /**     * Test xmlp-2, using the GET webmethod.     *      * @throws Exception     */     public void testXMLP2() throws Exception {        Call call = new Call(GET_DOC_ENDPOINT);        call.setSOAPVersion(SOAPConstants.SOAP12_CONSTANTS);        call.setProperty(SOAP12Constants.PROP_WEBMETHOD, "GET");        call.setOperationStyle(Style.DOCUMENT);        call.setOperationUse(Use.LITERAL);        call.invoke();        SOAPEnvelope env = call.getMessageContext().getResponseMessage().getSOAPEnvelope();        Object result = env.getFirstBody().getValueAsType(Constants.XSD_TIME);        assertEquals(org.apache.axis.types.Time.class, result.getClass());        // Suppose we could check the actual time here too, but we aren't        // gonna for now.    }    /**     * Test xmlp-3, using the GET webmethod and RPC mode (i.e. deal with     * the rpc:result element).     *      * @throws Exception     */     public void testXMLP3() throws Exception {        Call call = new Call(GET_RPC_ENDPOINT);        call.setSOAPVersion(SOAPConstants.SOAP12_CONSTANTS);        call.setProperty(SOAP12Constants.PROP_WEBMETHOD, "GET");        call.setOperationStyle(Style.RPC);        call.setReturnType(Constants.XSD_TIME);        Object ret = call.invoke("", new Object [] {});        assertEquals(org.apache.axis.types.Time.class, ret.getClass());        // Suppose we could check the actual time here too, but we aren't        // gonna for now.    }        public void testXMLP4() throws Exception {        Call call = new Call(RPC_ENDPOINT);        call.setSOAPVersion(SOAPConstants.SOAP12_CONSTANTS);        call.registerTypeMapping(SOAPStruct.class, SOAPSTRUCT_QNAME,                                 new BeanSerializerFactory(SOAPStruct.class, SOAPSTRUCT_QNAME),                                 new BeanDeserializerFactory(SOAPStruct.class, SOAPSTRUCT_QNAME));        call.addParameter(new QName("", "inputFloat"),                          Constants.XSD_FLOAT, ParameterMode.IN);        call.addParameter(new QName("", "inputInteger"),                          Constants.XSD_INT, ParameterMode.IN);        call.addParameter(new QName("", "inputString"),                          Constants.XSD_STRING, ParameterMode.IN);        call.setReturnType(SOAPSTRUCT_QNAME);        SOAPStruct ret = (SOAPStruct)call.invoke(                new QName(TEST_NS, "echoSimpleTypesAsStruct"),                new Object [] {                    new Float(FLOAT_VAL),                    new Integer(INT_VAL),                    STRING_VAL                 });        assertEquals(STRING_VAL, ret.getVarString());        assertEquals(FLOAT_VAL, ret.getVarFloat(), 0.0004F);        assertEquals(INT_VAL, ret.getVarInt());    }        public void testXMLP5() throws Exception {        Call call = new Call(RPC_ENDPOINT);        try {            call.invoke(new QName(TEST_NS, "echoVoid"), null);                } catch (AxisFault fault) {            // Got the expected Fault - make sure it looks right            assertEquals(Constants.FAULT_VERSIONMISMATCH, fault.getFaultCode());            return;        }        fail("Didn't catch expected fault");    }        public void testXMLP6() throws Exception {        Call call = new Call(RPC_ENDPOINT);        call.setSOAPVersion(SOAPConstants.SOAP12_CONSTANTS);        SOAPHeaderElement unknownHeader =                new SOAPHeaderElement("http://example.org",                                      "unknown",                                      "Nobody understands me!");        unknownHeader.setMustUnderstand(true);        call.addHeader(unknownHeader);        try {            call.invoke(new QName(TEST_NS, "echoVoid"), null);                } catch (AxisFault fault) {            // Got the expected Fault - make sure it looks right            assertEquals(Constants.FAULT_SOAP12_MUSTUNDERSTAND,                         fault.getFaultCode());            return;        }        fail("Didn't catch expected fault");            }        public void testXMLP7() throws Exception {        URL url = new URL(DOC_ENDPOINT);        test.wsdl.soap12.additional.Soap12AddTestDocBindingStub binding;        try {            binding = (test.wsdl.soap12.additional.Soap12AddTestDocBindingStub)                          new test.wsdl.soap12.additional.WhiteMesaSoap12AddTestSvcLocator().getSoap12AddTestDocPort(url);        }        catch (javax.xml.rpc.ServiceException jre) {            if(jre.getLinkedCause()!=null)                jre.getLinkedCause().printStackTrace();            throw new junit.framework.AssertionFailedError("JAX-RPC ServiceException caught: " + jre);        }        assertNotNull("binding is null", binding);        // Time out after a minute        binding.setTimeout(60000);        // Test operation        try {            binding.echoSenderFault(STRING_VAL);        } catch (java.rmi.RemoteException e) {            if (e instanceof AxisFault) {                AxisFault af = (AxisFault)e;                assertEquals(Constants.FAULT_SOAP12_SENDER,                             af.getFaultCode());                return; // success            }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -