📄 11.txt
字号:
例程11-1
01 package samples.guidgen;
02
03 import Java.io.*;
04 import Java.net.*;
05 import Java.util.*;
06 import org.apache.soap.*;
07 import org.apache.soap.rpc.*;
08
09
10 public class GuidGenClient1 {
11 public static void main (String[] args) throws Exception {
12
13 URL url = new URL("http://www.itfinity.net/soap/guid/Default.asp");
14 // Build the call.
15 Call call = new Call ();
16 call.setTargetObjectURI ("http://www.itfinity.net/soap/guid/guid.xsd");
17 call.setMethodName ("NextGUID");
18 call.setEncodingStyleURI("http://schemas.xmlsoap.org/soap/encoding/");
19
20 // make the call: note that the action URI is empty because the
21 // XML-SOAP rpc router does not need this. This may change in the
22 // future.
23 Response resp = call.invoke (/* router URL */ url,
24 /* actionURI */ "http://www.itfinity.net/soap/guid/Default.asp" );
25
26 // Check the response.
27 if (resp.generatedFault ()) {
28 Fault fault = resp.getFault ();
29 System.out.println ("Ouch, the call failed: ");
30 System.out.println (" Fault Code = " + fault.getFaultCode ());
31 System.out.println (" Fault String = " + fault.getFaultString ());
32 } else {
33 Parameter result = resp.getReturnValue ();
34 System.out.println (result.getValue ());
35 }
36 }
37 }
例程11-2
001 package samples.guidgen;
002
003 import Java.io.*;
004 import Java.util.*;
005 import Java.net.*;
006 import org.w3c.dom.*;
007 import org.apache.soap.util.xml.*;
008 import org.apache.soap.*;
009 import org.apache.soap.encoding.*;
010 import org.apache.soap.encoding.soapenc.*;
011 import org.apache.soap.rpc.*;
012 import org.apache.soap.transport.http.SOAPHTTPConnection;
013
014 /**
015 * Client to speak to MS SOAP implemented GUIDGen service at
016 * http://www.itfinity.net/soap/guid/details.html
017 *
018 * @author Sanjiva Weerawarana (sanjiva@watson.ibm.com)
019 */
020 public class GuidGenClient {
021 public static final String DEFAULT_SERVICE_URL =
022 "http://www.itfinity.net/soap/guid/Default.asp";
023
024 public static void main(String[] args) throws Exception {
025 String serviceURL = null;
026 boolean goodUsage = true;
027 String proxyHost = null;
028 int proxyPort = -1;
029
030 // parse command line arguments
031 for (int i = 0; i < args.length; i++) {
032 if ("-p".equalsIgnoreCase(args[i])) {
033 goodUsage = false;
034 if (args.length > i) {
035 i++;
036 int pos = args[i].indexOf(':');
037 if (pos != -1) {
038 try {
039 proxyPort = Integer.parseInt(args[i].substring(pos + 1));
040 proxyHost = args[i].substring(0, pos);
041 goodUsage = true;
042 } catch(NumberFormatException nfe) {
043 }
044 }
045 }
046 } else if (serviceURL == null)
047 serviceURL = args[i];
048 else {
049 goodUsage = false;
050 break;
051 }
052 }
053
054 if (!goodUsage) {
055 System.err.println ("Usage: Java samples.guidgen.GuidGenClient " +
056 "[service-URL] [-p <HTTP proxy hostname:port>]");
057 System.exit (1);
058 }
059
060 if (serviceURL == null)
061 serviceURL = DEFAULT_SERVICE_URL;
062 URL url = new URL (serviceURL);
063
064 // define deserializers for the return things (without xsi:type)
065 SOAPMappingRegistry smr = new SOAPMappingRegistry ();
066 StringDeserializer sd = new StringDeserializer ();
067 smr.mapTypes (Constants.NS_URI_SOAP_ENC,
068 new QName ("", "Result"), null, null, sd);
069
070 // create the transport and set parameters
071 SOAPHTTPConnection st = new SOAPHTTPConnection();
072 if (proxyHost != null) {
073 st.setProxyHost(proxyHost);
074 st.setProxyPort(proxyPort);
075 }
076
077 // build the call.
078 Call call = new Call ();
079 call.setSOAPTransport(st);
080 call.setSOAPMappingRegistry (smr);
081 call.setTargetObjectURI ("http://www.itfinity.net/soap/guid/guid.xsd");
082 call.setMethodName("NextGUID");
083 call.setEncodingStyleURI ("http://schemas.xmlsoap.org/soap/encoding/");
084
085 // invoke it
086 System.err.println ("Invoking GUID generator service at: ");
087 System.err.println ("\t" + serviceURL);
088 Response resp;
089 try {
090 resp = call.invoke (url, DEFAULT_SERVICE_URL);
091 } catch (SOAPException e) {
092 System.err.println("Caught SOAPException (" +
093 e.getFaultCode () + "): " +
094 e.getMessage ());
095 return;
096 }
097
098 // check response
099 if (!resp.generatedFault()) {
100 Parameter ret = resp.getReturnValue();
101 Object value = ret.getValue();
102
103 System.out.println ("Next GUID is: " + value);
104 }
105 else {
106 Fault fault = resp.getFault ();
107 System.err.println ("Generated fault: ");
108 System.out.println (" Fault Code = " + fault.getFaultCode());
109 System.out.println (" Fault String = " + fault.getFaultString());
110 }
111 }
112 }
例程11-3
01 package samples.interop;
02
03 import Java.math.BigDecimal;
04 import Java.util.Date;
05
06 /** An implementation of the interop echo service as defined at
07 * http://www.xmethods.net/ilab.
08 *
09 * @author Glen Daniels (gdaniels@macromedia.com)
10 */
11 public class EchoTestService
12 {
13 public void nop()
14 {
15 }
16
17 public int echoInteger(int i)
18 {
19 return i;
20 }
21
22 public float echoFloat(float f)
23 {
24 return f;
25 }
26
27 public String echoString(String str)
28 {
29 return str;
30 }
31
32 public Data echoStruct(Data data)
33 {
34 return data;
35 }
36
37 public int [] echoIntegerArray(int [] ii)
38 {
39 return ii;
40 }
41
42 public float [] echoFloatArray(float [] ff)
43 {
44 return ff;
45 }
46
47 public String [] echoStringArray(String [] ss)
48 {
49 return ss;
50 }
51
52 public Data [] echoStructArray(Data [] ds)
53 {
54 return ds;
55 }
56
57 public void echoVoid()
58 {
59 }
60
61 public byte[] echoBase64(byte[] b64)
62 {
63 return b64;
64 }
65
66 public Date echoDate(Date d)
67 {
68 return d;
69 }
70
71 public BigDecimal echoDecimal(BigDecimal d)
72 {
73 return d;
74 }
75
76 public boolean echoBoolean(boolean b)
77 {
78 return b;
79 }
80 }
例程11-4
<isd:service xmlns:isd="http://xml.apache.org/xml-soap/deployment"
id="http://soapinterop.org/"
checkMustUnderstands="true">
<isd:provider type="Java"
scope="Application"
methods="nop echoInteger echoString echoFloat echoStruct
echoIntegerArray echoFloatArray echoStringArray echoStructArray
echoVoid echoBase64 echoDate echoDecimal echoBoolean">
<isd:Java class="samples.interop.EchoTestService" static="false"/>
</isd:provider>
<isd:faultListener>org.apache.soap.server.DOMFaultListener</isd:faultListener>
<isd:mappings>
<isd:map encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:x="" qname="x:inputInteger"
xml2JavaClassName="org.apache.soap.encoding.soapenc.IntDeserializer"/>
<isd:map encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:x="" qname="x:inputFloat" xml2JavaClassName=
"org.apache.soap.encoding.soapenc.FloatDeserializer"/>
<isd:map encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:x="" qname="x:inputString" xml2JavaClassName=
"org.apache.soap.encoding.soapenc.StringDeserializer"/>
<isd:map encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:x="" qname="x:inputStruct"
xml2JavaClassName="samples.interop.DataSerializer"/>
<isd:map encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:x="" qname="x:inputIntegerArray"
xml2JavaClassName="org.apache.soap.encoding.soapenc.ArraySerializer"/>
<isd:map encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:x="" qname="x:inputFloatArray"
xml2JavaClassName="org.apache.soap.encoding.soapenc.ArraySerializer"/>
<isd:map encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:x="" qname="x:inputStringArray"
xml2JavaClassName="org.apache.soap.encoding.soapenc.ArraySerializer"/>
<isd:map encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:x="" qname="x:inputStructArray"
xml2JavaClassName="org.apache.soap.encoding.soapenc.ArraySerializer"/>
<isd:map encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:x="http://soapinterop.org/xsd" qname="x:SOAPStruct"
JavaType="samples.interop.Data"
Java2XMLClassName="samples.interop.DataSerializer"
xml2JavaClassName="samples.interop.DataSerializer"/>
<isd:map encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:x="" qname="x:inputBase64" xml2JavaClassName=
"org.apache.soap.encoding.soapenc.Base64Serializer"/>
<isd:map encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:x="" qname="x:inputDate"
xml2JavaClassName="org.apache.soap.encoding.soapenc.DateSerializer"/>
<isd:map encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:x="" qname="x:inputDecimal" xml2JavaClassName=
"org.apache.soap.encoding.soapenc.DecimalDeserializer"/>
<isd:map encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:x="" qname="x:inputBoolean" xml2JavaClassName=
"org.apache.soap.encoding.soapenc.BooleanDeserializer"/>
</isd:mappings>
</isd:service>
例程11-5
001 package samples.interop;
002
003 import Java.util.Vector;
004 import org.apache.soap.*;
005 import org.apache.soap.encoding.SOAPMappingRegistry;
006 import org.apache.soap.encoding.soapenc.*;
007 import org.apache.soap.rpc.*;
008 import org.apache.soap.messaging.*;
009 import Java.net.URL;
010 import org.apache.soap.util.xml.*;
011 import Java.io.*;
012 import org.w3c.dom.*;
013 import org.apache.soap.util.*;
014 import Java.lang.reflect.*;
015 import Java.util.Date;
016 import Java.math.BigDecimal;
017
018 /** A quick-and-dirty client for the Interop echo test services as defined
019 * at http://www.xmethods.net/ilab.
020 *
021 * Defaults to the Apache endpoint, but you can point it somewhere else via
022 * the command line:
023 *
024 * EchoTestClient http://some.other.place/
025 *
026 * DOES NOT SUPPORT DIFFERENT SOAPACTION URIS YET.
027 *
028 * @author Glen Daniels (gdaniels@macromedia.com)
029 * @author Sam Ruby (rubys@us.ibm.com)
030 */
031 public class EchoTestClient
032 {
033 SOAPMappingRegistry smr = new SOAPMappingRegistry();
034
035 public static final String DEFAULT_URL =
036 "http://nagoya.apache.org:5089/soap/servlet/rpcrouter";
037 public static final String ACTION_URI = "http://soapinterop.org/";
038 public static final String OBJECT_URI = "http://soapinterop.org/xsd";
039 public Header header = null;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -