You are viewing a plain text version of this content. The canonical link for it is here.
Posted to soap-dev@xml.apache.org by du...@apache.org on 2001/05/25 21:03:50 UTC
cvs commit: xml-soap/java/samples/bidbuy/server/registry DeploymentDescriptor.xml RegistryService.java deploy.bat
duftler 01/05/25 12:03:50
Added: java/samples/bidbuy bidbuy.wsdl readme.html registry.wsdl
java/samples/bidbuy/client ApacheSoapV2.java reg.lst
rfq.java vInterface.java
java/samples/bidbuy/server/bid BidService.java
DeploymentDescriptor.xml deploy.bat
java/samples/bidbuy/server/registry DeploymentDescriptor.xml
RegistryService.java deploy.bat
Log:
Added BidBuy interop sample.
The non-ApacheSOAP specific code was taken from Axis. (With pointers and
help from Doug Davis).
The Apache SOAP specific code was written by me (Matt Duftler).
The documentation was written by Bill Nagy.
Revision Changes Path
1.1 xml-soap/java/samples/bidbuy/bidbuy.wsdl
Index: bidbuy.wsdl
===================================================================
<?xml version="1.0" encoding="utf-8"?>
<definitions xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:s0="http://www.soapinterop.org/Bid" targetNamespace="http://www.soapinterop.org/Bid" xmlns="http://schemas.xmlsoap.org/wsdl/">
<types>
<s:schema targetNamespace="http://www.soapinterop.org/Bid">
<s:complexType name="PurchaseOrder">
<s:sequence>
<s:element minOccurs="1" maxOccurs="1" name="poID" type="s:string" />
<s:element minOccurs="1" maxOccurs="1" name="createDate" type="s:dateTime" />
<s:element minOccurs="1" maxOccurs="1" name="shipTo" type="s0:Address" />
<s:element minOccurs="1" maxOccurs="1" name="billTo" type="s0:Address" />
<s:element minOccurs="1" maxOccurs="1" name="items" type="s0:ArrayOfLineItem" />
</s:sequence>
</s:complexType>
<s:complexType name="Address">
<s:sequence>
<s:element minOccurs="1" maxOccurs="1" name="name" type="s:string" />
<s:element minOccurs="1" maxOccurs="1" name="address" type="s:string" />
<s:element minOccurs="1" maxOccurs="1" name="city" type="s:string" />
<s:element minOccurs="1" maxOccurs="1" name="state" type="s:string" />
<s:element minOccurs="1" maxOccurs="1" name="zipCode" type="s:string" />
</s:sequence>
</s:complexType>
<s:complexType name="LineItem">
<s:sequence>
<s:element minOccurs="1" maxOccurs="1" name="name" type="s:string" />
<s:element minOccurs="1" maxOccurs="1" name="quantity" type="s:int" />
<s:element minOccurs="1" maxOccurs="1" name="price" type="s:decimal" />
</s:sequence>
</s:complexType>
<s:complexType name="ArrayOfLineItem">
<s:complexContent mixed="false">
<s:restriction base="soapenc:Array">
<s:attribute n1:arrayType="s0:LineItem[]" ref="soapenc:arrayType" xmlns:n1="http://schemas.xmlsoap.org/wsdl/" />
</s:restriction>
</s:complexContent>
</s:complexType>
<s:element name="double" type="s:double" />
<s:element name="string" nillable="true" type="s:string" />
</s:schema>
</types>
<message name="RequestForQuoteSoapIn">
<part name="ProductName" type="s:string" />
<part name="Quantity" type="s:int" />
</message>
<message name="RequestForQuoteSoapOut">
<part name="RequestForQuoteResult" type="s:double" />
</message>
<message name="SimpleBuySoapIn">
<part name="Address" type="s:string" />
<part name="ProductName" type="s:string" />
<part name="Quantity" type="s:int" />
</message>
<message name="SimpleBuySoapOut">
<part name="SimpleBuyResult" type="s:string" />
</message>
<message name="BuySoapIn">
<part name="PO" type="s0:PurchaseOrder" />
</message>
<message name="BuySoapOut">
<part name="BuyResult" type="s:string" />
</message>
<message name="PingSoapIn" />
<message name="PingSoapOut" />
<message name="RequestForQuoteHttpGetIn">
<part name="ProductName" type="s:string" />
<part name="Quantity" type="s:string" />
</message>
<message name="RequestForQuoteHttpGetOut">
<part name="Body" element="s0:double" />
</message>
<message name="SimpleBuyHttpGetIn">
<part name="Address" type="s:string" />
<part name="ProductName" type="s:string" />
<part name="Quantity" type="s:string" />
</message>
<message name="SimpleBuyHttpGetOut">
<part name="Body" element="s0:string" />
</message>
<message name="PingHttpGetIn" />
<message name="PingHttpGetOut" />
<message name="RequestForQuoteHttpPostIn">
<part name="ProductName" type="s:string" />
<part name="Quantity" type="s:string" />
</message>
<message name="RequestForQuoteHttpPostOut">
<part name="Body" element="s0:double" />
</message>
<message name="SimpleBuyHttpPostIn">
<part name="Address" type="s:string" />
<part name="ProductName" type="s:string" />
<part name="Quantity" type="s:string" />
</message>
<message name="SimpleBuyHttpPostOut">
<part name="Body" element="s0:string" />
</message>
<message name="PingHttpPostIn" />
<message name="PingHttpPostOut" />
<portType name="BidBuySoap">
<operation name="RequestForQuote">
<input message="s0:RequestForQuoteSoapIn" />
<output message="s0:RequestForQuoteSoapOut" />
</operation>
<operation name="SimpleBuy">
<input message="s0:SimpleBuySoapIn" />
<output message="s0:SimpleBuySoapOut" />
</operation>
<operation name="Buy">
<input message="s0:BuySoapIn" />
<output message="s0:BuySoapOut" />
</operation>
<operation name="Ping">
<input message="s0:PingSoapIn" />
<output message="s0:PingSoapOut" />
</operation>
</portType>
<portType name="BidBuyHttpGet">
<operation name="RequestForQuote">
<input message="s0:RequestForQuoteHttpGetIn" />
<output message="s0:RequestForQuoteHttpGetOut" />
</operation>
<operation name="SimpleBuy">
<input message="s0:SimpleBuyHttpGetIn" />
<output message="s0:SimpleBuyHttpGetOut" />
</operation>
<operation name="Ping">
<input message="s0:PingHttpGetIn" />
<output message="s0:PingHttpGetOut" />
</operation>
</portType>
<portType name="BidBuyHttpPost">
<operation name="RequestForQuote">
<input message="s0:RequestForQuoteHttpPostIn" />
<output message="s0:RequestForQuoteHttpPostOut" />
</operation>
<operation name="SimpleBuy">
<input message="s0:SimpleBuyHttpPostIn" />
<output message="s0:SimpleBuyHttpPostOut" />
</operation>
<operation name="Ping">
<input message="s0:PingHttpPostIn" />
<output message="s0:PingHttpPostOut" />
</operation>
</portType>
<binding name="BidBuySoap" type="s0:BidBuySoap">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="rpc" />
<operation name="RequestForQuote">
<soap:operation soapAction="http://www.soapinterop.org/RequestForQuote" style="rpc" />
<input>
<soap:body use="encoded" namespace="http://www.soapinterop.org/Bid" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
</input>
<output>
<soap:body use="encoded" namespace="http://www.soapinterop.org/Bid" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
</output>
</operation>
<operation name="SimpleBuy">
<soap:operation soapAction="http://www.soapinterop.org/SimpleBuy" style="rpc" />
<input>
<soap:body use="encoded" namespace="http://www.soapinterop.org/Bid" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
</input>
<output>
<soap:body use="encoded" namespace="http://www.soapinterop.org/Bid" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
</output>
</operation>
<operation name="Buy">
<soap:operation soapAction="http://www.soapinterop.org/Buy" style="rpc" />
<input>
<soap:body use="encoded" namespace="http://www.soapinterop.org/Bid" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
</input>
<output>
<soap:body use="encoded" namespace="http://www.soapinterop.org/Bid" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
</output>
</operation>
<operation name="Ping">
<soap:operation soapAction="http://www.soapinterop.org/Ping" style="rpc" />
<input>
<soap:body use="encoded" namespace="http://www.soapinterop.org/Bid" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
</input>
<output>
<soap:body use="encoded" namespace="http://www.soapinterop.org/Bid" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
</output>
</operation>
</binding>
<binding name="BidBuyHttpGet" type="s0:BidBuyHttpGet">
<http:binding verb="GET" />
<operation name="RequestForQuote">
<http:operation location="/RequestForQuote" />
<input>
<http:urlEncoded />
</input>
<output>
<mime:mimeXml part="Body" />
</output>
</operation>
<operation name="SimpleBuy">
<http:operation location="/SimpleBuy" />
<input>
<http:urlEncoded />
</input>
<output>
<mime:mimeXml part="Body" />
</output>
</operation>
<operation name="Ping">
<http:operation location="/Ping" />
<input>
<http:urlEncoded />
</input>
<output />
</operation>
</binding>
<binding name="BidBuyHttpPost" type="s0:BidBuyHttpPost">
<http:binding verb="POST" />
<operation name="RequestForQuote">
<http:operation location="/RequestForQuote" />
<input>
<mime:content type="application/x-www-form-urlencoded" />
</input>
<output>
<mime:mimeXml part="Body" />
</output>
</operation>
<operation name="SimpleBuy">
<http:operation location="/SimpleBuy" />
<input>
<mime:content type="application/x-www-form-urlencoded" />
</input>
<output>
<mime:mimeXml part="Body" />
</output>
</operation>
<operation name="Ping">
<http:operation location="/Ping" />
<input>
<mime:content type="application/x-www-form-urlencoded" />
</input>
<output />
</operation>
</binding>
</definitions>
1.1 xml-soap/java/samples/bidbuy/readme.html
Index: readme.html
===================================================================
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<META name="GENERATOR" content="IBM WebSphere Homepage Builder V4.0.0 for Linux">
</HEAD>
<BODY bgcolor="#ffffff">
<H2 align="center">BidBuy Interoperability Sample</H2>
<P align="center">Apache SOAP specific code authored by: Matthew
J. Duftler <<A href="mailto:duftler@us.ibm.com">duftler@us.ibm.com</A>></P>
<P>This directory contains code which implements
a scenario developed for the SOAP interoperability
face-to-face summarized <A href="http://www.apache.org/~dug/interop_f2f_04_19_01.html">here</A>. This README only describes how to run the
sample, and doesn't attempt to repeat any
of the information contained within that
summary or in its associated links. You can
also look at sample <A href="registry.wsdl">Registry</A> and <A href="bidbuy.wsdl">BidBuy</A> service WSDL files.<BR>
<I>
Note: This sample was completed long after
the interop session had occurred, and efforts
have been made to increase compatibility
significantly.</I></P>
<H3>Acknowledgements</H3>
<P>Thanks go out to Doug Davis and the rest
of the Axis development team for use of their
BidBuy Client GUI as well as for detailed
help on developing the sample.</P>
<H3>Client-Side</H3>
<P>The client portion of this scenario utilizes
a GUI created by the developers who are working
on the <A href="http://xml.apache.org/axis">Axis</A> project. The GUI, whose fully-qualified
class name is samples.bidbuy.client.rfq,
delegates all of its actions to an implementation
of a samples.bidbuy.client.vInterface. For
Apache SOAP, this interface is implemented
in the samples.bidbuy.client.ApacheSoapV2
class.</P>
<P>To run the client, make sure that you classpath
contains soap.jar and the directory which
contains the samples directory, then enter:</P>
<PRE>java samples.bidbuy.client.rfq</PRE>
<P>Note: There is a file called reg.lst, located
in the samples/bidbuy/client/registry directory,
which contains information about all known
registries of BidBuy services. The client
will look in the start-up directory for this
file, and if it can't find it, you will have
to manually add the registries via the GUI.</P>
<H3>Server-Side</H3>
<P>The server portion of this scenario consists
of 2 services: one that implements the RequestForQuote
services, and another that implements the
Buy and SimpleBuy services.</P>
<P>To deploy the first service, change to the
samples/bidbuy/server/registry directory
and enter:</P>
<PRE>java.org.apache.soap.server.ServiceManagerClient http://<B><I>soap-server</I></B>:<B><I>soap-port</I></B>/soap/servlet/rpcrouter deploy DeploymentDescriptor.xml</PRE>
<P>where <B><I>soap-server</I></B> and <B><I>soap-port</I></B> are the hostname and port of the machine
where the rpcrouter servlet is deployed.
Alternatively, you could run deploy.bat from
that directory, but it assumes localhost:8080.</P>
<P>To deploy the second service, change to the
samples/bidbuy/server/bid directory and enter:</P>
<PRE>java org.apache.soap.server.ServiceManagerClient http://<B><I>soap-server</I></B>:<B><I>soap-port</I></B>/soap/servlet/rpcrouter deploy DeploymentDescriptor.xml</PRE>
<P>where <B><I>soap-server</I></B> and <B><I>soap-port</I></B> are the hostname and port of the machine
where the rpcrouter servlet is deployed.
Again, you could alternatively run deploy.bat
from that directory, but it assumes localhost:8080.</P>
<H3>Trying it Out</H3>
<P>You can use the client and the server to
talk to one another on the same machine,
you can use the client to talk to other servers,
or you can have other clients talk to your
server. (There is nothing that binds the
client and the server together, the are just
bundled that way for convenience.)<BR>
<I>
Note: The servers listed in reg.lst are scattered
all over the Internet, so you will need external
access to be able to use them.</I></P>
<P>To try out the sample, start up the client
as indicated above and select a Registration
Server from the list at the top of the GUI,
or enter a new one. (Even if there is a name
in the box at the top, you will need to pick
one from the list.) The client will then
talk to the selected registry and after a
couple of seconds will retrieve the list
of registered BidBuy services. Place a checkmark
next to one or more of the services that
you wish to talk to, and click on the <I>Request RFQs</I> button. Assuming that everything is working
correctly, you should get numbers appearing
in the Quote column of the services which
you selected after a second or two. You can
then select one of the services that you
received a quote from and issue a <I>Simple Buy</I> or <I>PO Buy</I> request to it using the bottom portion of
the interface.</P>
<P>If you want to add or remove BidBuy services
from the list on your client, you can use
the <I>Add Bid Server</I> and <I>Remove Server</I> buttons, respectively.</P>
<P><B>WARNING: The <I>Register Server</I> and <I>Unregister Server</I> buttons will modify the actual registries,
so unless you are putting up a server for
other people to test against, or unless you
are acting against your own registry, DO
NOT USE THEM!</B></P>
<P>Last updated 5/24/2001 by Bill Nagy <<A href="mailto:nagy@watson.ibm.com">nagy@watson.ibm.com</A>>.</P>
</BODY>
</HTML>
1.1 xml-soap/java/samples/bidbuy/registry.wsdl
Index: registry.wsdl
===================================================================
<?xml version="1.0" encoding="utf-8"?>
<definitions xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:s0="http://www.soapinterop.org/Registry" targetNamespace="http://www.soapinterop.org/Registry" xmlns="http://schemas.xmlsoap.org/wsdl/">
<types>
<s:schema targetNamespace="http://www.soapinterop.org/Registry">
<s:complexType name="Service">
<s:sequence>
<s:element minOccurs="1" maxOccurs="1" name="serviceName" type="s:string" />
<s:element minOccurs="1" maxOccurs="1" name="serviceUrl" type="s:string" />
<s:element minOccurs="1" maxOccurs="1" name="serviceType" type="s:string" />
<s:element minOccurs="1" maxOccurs="1" name="serviceWsdl" type="s:string" />
</s:sequence>
</s:complexType>
<s:complexType name="ArrayOfService">
<s:complexContent mixed="false">
<s:restriction base="soapenc:Array">
<s:attribute n1:arrayType="s0:Service[]" ref="soapenc:arrayType" xmlns:n1="http://schemas.xmlsoap.org/wsdl/" />
</s:restriction>
</s:complexContent>
</s:complexType>
</s:schema>
</types>
<message name="LookupSoapIn">
<part name="ServiceType" type="s:string" />
</message>
<message name="LookupSoapOut">
<part name="LookupResult" type="s0:ArrayOfService" />
</message>
<message name="LookupAsStringSoapIn">
<part name="ServiceType" type="s:string" />
</message>
<message name="LookupAsStringSoapOut">
<part name="LookupAsStringResult" type="s:string" />
</message>
<message name="RegisterSoapIn">
<part name="ServiceName" type="s:string" />
<part name="ServiceUrl" type="s:string" />
<part name="ServiceType" type="s:string" />
<part name="ServiceWsdl" type="s:string" />
</message>
<message name="RegisterSoapOut" />
<message name="UnregisterSoapIn">
<part name="ServiceName" type="s:string" />
</message>
<message name="UnregisterSoapOut" />
<portType name="RegistryServiceSoap">
<operation name="Lookup">
<input message="s0:LookupSoapIn" />
<output message="s0:LookupSoapOut" />
</operation>
<operation name="LookupAsString">
<input message="s0:LookupAsStringSoapIn" />
<output message="s0:LookupAsStringSoapOut" />
</operation>
<operation name="Register">
<input message="s0:RegisterSoapIn" />
<output message="s0:RegisterSoapOut" />
</operation>
<operation name="Unregister">
<input message="s0:UnregisterSoapIn" />
<output message="s0:UnregisterSoapOut" />
</operation>
</portType>
<binding name="RegistryServiceSoap" type="s0:RegistryServiceSoap">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document" />
<operation name="Lookup">
<soap:operation soapAction="http://www.soapinterop.org/Lookup" style="rpc" />
<input>
<soap:body use="encoded" namespace="http://www.soapinterop.org/Registry" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
</input>
<output>
<soap:body use="encoded" namespace="http://www.soapinterop.org/Registry" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
</output>
</operation>
<operation name="LookupAsString">
<soap:operation soapAction="http://www.soapinterop.org/LookupAsString" style="rpc" />
<input>
<soap:body use="encoded" namespace="http://www.soapinterop.org/Registry" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
</input>
<output>
<soap:body use="encoded" namespace="http://www.soapinterop.org/Registry" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
</output>
</operation>
<operation name="Register">
<soap:operation soapAction="http://www.soapinterop.org/Register" style="rpc" />
<input>
<soap:body use="encoded" namespace="http://www.soapinterop.org/Registry" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
</input>
<output>
<soap:body use="encoded" namespace="http://www.soapinterop.org/Registry" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
</output>
</operation>
<operation name="Unregister">
<soap:operation soapAction="http://www.soapinterop.org/Unregister" style="rpc" />
<input>
<soap:body use="encoded" namespace="http://www.soapinterop.org/Registry" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
</input>
<output>
<soap:body use="encoded" namespace="http://www.soapinterop.org/Registry" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
</output>
</operation>
</binding>
</definitions>
1.1 xml-soap/java/samples/bidbuy/client/ApacheSoapV2.java
Index: ApacheSoapV2.java
===================================================================
package samples.bidbuy.client;
import java.io.*;
import java.math.*;
import java.net.*;
import java.util.*;
import org.apache.soap.*;
import org.apache.soap.encoding.*;
import org.apache.soap.encoding.soapenc.*;
import org.apache.soap.rpc.*;
import org.apache.soap.util.xml.*;
import samples.bidbuy.shared.*;
/**
* @author Matthew J. Duftler (duftler@us.ibm.com)
*/
public class ApacheSoapV2 implements vInterface
{
SOAPMappingRegistry smr = new SOAPMappingRegistry();
{
PurchaseOrderSerializer poSer = new PurchaseOrderSerializer();
AddressSerializer addrSer = new AddressSerializer();
LineItemSerializer lineItemSer = new LineItemSerializer();
DoubleDeserializer doubleDeser = new DoubleDeserializer();
StringDeserializer stringDeser = new StringDeserializer();
ServiceSerializer serviceSer = new ServiceSerializer();
ArraySerializer arraySer = new ArraySerializer();
smr.mapTypes(Constants.NS_URI_SOAP_ENC,
new QName("http://www.soapinterop.org/Bid", "PurchaseOrder"),
PurchaseOrder.class,
poSer,
poSer);
smr.mapTypes(Constants.NS_URI_SOAP_ENC,
new QName("http://www.soapinterop.org/Bid", "Address"),
Address.class,
addrSer,
addrSer);
smr.mapTypes(Constants.NS_URI_SOAP_ENC,
new QName("http://www.soapinterop.org/Bid", "LineItem"),
LineItem.class,
lineItemSer,
lineItemSer);
smr.mapTypes(Constants.NS_URI_SOAP_ENC,
new QName("http://www.soapinterop.org/Registry", "Service"),
Service.class,
serviceSer,
serviceSer);
smr.mapTypes(Constants.NS_URI_SOAP_ENC,
new QName ("", "LookupResult"),
null,
null,
arraySer);
smr.mapTypes(Constants.NS_URI_SOAP_ENC,
new QName ("", "LookupAsStringResult"),
null,
null,
stringDeser);
smr.mapTypes(Constants.NS_URI_SOAP_ENC,
new QName ("", "RequestForQuoteResult"),
null,
null,
doubleDeser);
smr.mapTypes(Constants.NS_URI_SOAP_ENC,
new QName ("", "SimpleBuyResult"),
null,
null,
stringDeser);
smr.mapTypes(Constants.NS_URI_SOAP_ENC,
new QName ("", "BuyResult"),
null,
null,
stringDeser);
}
public void register(String registryURL, Service s) throws Exception
{
URL url = new URL(registryURL);
// Build the call.
Call call = new Call();
call.setTargetObjectURI("http://www.soapinterop.org/Registry");
call.setMethodName("Register");
call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
call.setSOAPMappingRegistry(smr);
Vector params = new Vector();
params.addElement(new Parameter("ServiceName",
String.class,
s.getServiceName(),
null));
params.addElement(new Parameter("ServiceURL",
String.class,
s.getServiceUrl(),
null));
params.addElement(new Parameter("ServiceType",
String.class,
s.getServiceType(),
null));
params.addElement(new Parameter("ServiceWSDL",
String.class,
s.getServiceWsdl(),
null));
call.setParams(params);
Response resp = call.invoke(url, "http://www.soapinterop.org/Register");
// Check the response.
if (resp.generatedFault())
{
Fault fault = resp.getFault();
throw new SOAPException(fault.getFaultCode(),
fault.getFaultString());
}
}
public void unregister(String registryURL, String name) throws Exception
{
URL url = new URL(registryURL);
// Build the call.
Call call = new Call();
call.setTargetObjectURI("http://www.soapinterop.org/Registry");
call.setMethodName("Unregister");
call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
call.setSOAPMappingRegistry(smr);
Vector params = new Vector();
params.addElement(new Parameter("ServiceName", String.class, name, null));
call.setParams(params);
Response resp = call.invoke(url, "http://www.soapinterop.org/Unregister");
// Check the response.
if (resp.generatedFault())
{
Fault fault = resp.getFault();
throw new SOAPException(fault.getFaultCode(),
fault.getFaultString());
}
}
public Boolean ping(String serverURL) throws Exception
{
URL url = new URL(serverURL);
// Build the call.
Call call = new Call();
call.setTargetObjectURI("http://www.soapinterop.org/Bid");
call.setMethodName("Ping");
call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
call.setSOAPMappingRegistry(smr);
Response resp = call.invoke(url, "http://www.soapinterop.org/Ping");
// Check the response.
if (resp.generatedFault())
{
Fault fault = resp.getFault();
throw new SOAPException(fault.getFaultCode(),
fault.getFaultString());
}
else
{
return new Boolean(true);
}
}
public Vector lookupAsString(String registryURL) throws Exception
{
URL url = new URL(registryURL);
// Build the call.
Call call = new Call();
call.setTargetObjectURI("http://www.soapinterop.org/Registry");
call.setMethodName("LookupAsString");
call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
call.setSOAPMappingRegistry(smr);
Vector params = new Vector();
params.addElement(new Parameter("ServiceType", String.class, "Bid", null));
call.setParams(params);
Response resp = call.invoke(url,
"http://www.soapinterop.org/LookupAsString");
// Check the response.
if (resp.generatedFault())
{
Fault fault = resp.getFault();
throw new SOAPException(fault.getFaultCode(),
fault.getFaultString());
}
String res = (String)resp.getReturnValue().getValue();
StringTokenizer lineParser = new StringTokenizer(res, "\n");
Vector services = new Vector();
while (lineParser.hasMoreTokens())
{
String line = (String)lineParser.nextElement();
StringTokenizer wordParser = new StringTokenizer(line, "\t");
Service service = null;
for (int i = 0; wordParser.hasMoreTokens() && i < 4; i++)
{
switch(i)
{
case 0 : service = new Service();
if (services == null) services = new Vector();
services.add(service);
service.setServiceName((String)wordParser.nextToken());
break ;
case 1 : service.setServiceUrl((String)wordParser.nextToken());
break ;
case 2 : service.setServiceType((String)wordParser.nextToken());
break ;
case 3 : service.setServiceWsdl((String)wordParser.nextToken());
break ;
}
}
}
return services;
}
public Service[] lookup(String registryURL) throws Exception
{
URL url = new URL(registryURL);
// Build the call.
Call call = new Call();
call.setTargetObjectURI("http://www.soapinterop.org/Registry");
call.setMethodName("Lookup");
call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
call.setSOAPMappingRegistry(smr);
Vector params = new Vector();
params.addElement(new Parameter("ServiceType", String.class, "Bid", null));
call.setParams(params);
Response resp = call.invoke(url,
"http://www.soapinterop.org/Lookup");
// Check the response.
if (resp.generatedFault())
{
Fault fault = resp.getFault();
throw new SOAPException(fault.getFaultCode(),
fault.getFaultString());
}
return (Service[])resp.getReturnValue().getValue();
}
public double requestForQuote(String serverURL) throws Exception
{
URL url = new URL(serverURL);
// Build the call.
Call call = new Call();
call.setTargetObjectURI("http://www.soapinterop.org/Bid");
call.setMethodName("RequestForQuote");
call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
call.setSOAPMappingRegistry(smr);
Vector params = new Vector();
params.addElement(new Parameter("ProductName",
String.class,
"widget",
null));
params.addElement(new Parameter("Quantity",
int.class,
new Integer(10),
null));
call.setParams(params);
Response resp = call.invoke(url,
"http://www.soapinterop.org/RequestForQuote");
// Check the response.
if (resp.generatedFault())
{
Fault fault = resp.getFault();
throw new SOAPException(fault.getFaultCode(),
fault.getFaultString());
}
else
{
String result = resp.getReturnValue().getValue().toString();
return new Double(result).doubleValue();
}
}
public String simpleBuy(String serverURL, int quantity) throws Exception
{
URL url = new URL(serverURL);
// Build the call.
Call call = new Call();
call.setTargetObjectURI("http://www.soapinterop.org/Bid");
call.setMethodName("SimpleBuy");
call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
call.setSOAPMappingRegistry(smr);
Vector params = new Vector();
params.addElement(new Parameter("Address",
String.class,
"123 Main St.",
null));
params.addElement(new Parameter("ProductName",
String.class,
"widget",
null));
params.addElement(new Parameter("Quantity",
int.class,
new Integer(quantity),
null));
call.setParams(params);
Response resp = call.invoke(url,
"http://www.soapinterop.org/SimpleBuy");
// Check the response.
if (resp.generatedFault())
{
Fault fault = resp.getFault();
throw new SOAPException(fault.getFaultCode(),
fault.getFaultString());
}
else
{
return (String)resp.getReturnValue().getValue();
}
}
public String buy(String serverURL, int quantity, int numItems, double price)
throws Exception
{
LineItem[] lineItems = new LineItem[numItems];
for (int i = 0; i < numItems; i++)
{
lineItems[i] = new LineItem("Widget" + i,
quantity,
new BigDecimal(price));
}
PurchaseOrder po = new PurchaseOrder("PO1",
new Date(),
new Address("Mr Big",
"40 Wildwood Lane",
"Weston",
"CT",
"06883"),
new Address("Mr Big's Dad",
"40 Wildwood Lane",
"Weston",
"CT",
"06883"),
lineItems);
return buy(serverURL, po);
}
public String buy(String serverURL, PurchaseOrder po) throws Exception
{
URL url = new URL(serverURL);
// Build the call.
Call call = new Call();
call.setTargetObjectURI("http://www.soapinterop.org/Bid");
call.setMethodName("Buy");
call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
call.setSOAPMappingRegistry(smr);
Vector params = new Vector();
params.addElement(new Parameter("PO",
PurchaseOrder.class,
po,
null));
call.setParams(params);
Response resp = call.invoke(url,
"http://www.soapinterop.org/Buy");
// Check the response.
if (resp.generatedFault())
{
Fault fault = resp.getFault();
throw new SOAPException(fault.getFaultCode(),
fault.getFaultString());
}
else
{
return (String)resp.getReturnValue().getValue();
}
}
}
1.1 xml-soap/java/samples/bidbuy/client/reg.lst
Index: reg.lst
===================================================================
http://nagoya.apache.org:5089/soap/servlet/rpcrouter
http://localhost:8080/axis/RegistryService.jws
http://localhost:81/axis/RegistryService.jws
http://131.107.72.13/BigDog/RegistryService.soap
http://localhost:81/BigDog/RegistryService.soap
http://localhost:82/soap/servlet/rpcrouter
http://localhost:4040/soap/servlet/rpcrouter
http://localhost:4040
http://localhost:8080
http://localhost:8080/soap/servlet/rpcrouter
1.1 xml-soap/java/samples/bidbuy/client/rfq.java
Index: rfq.java
===================================================================
package samples.bidbuy.client;
import javax.swing.* ;
import java.awt.* ;
import java.awt.event.* ;
import java.net.* ;
import javax.swing.table.* ;
import javax.swing.text.* ;
import javax.swing.event.* ;
import java.util.* ;
import java.io.* ;
import java.text.* ;
import javax.swing.border.* ;
import samples.bidbuy.shared.*;
public class rfq extends JPanel {
private vInterface vv = new ApacheSoapV2();
private String regServerURL = null ;
private TitledBorder regServerBorder = null ;
private JComboBox regServerList = null ;
private JButton removeButton = null ;
private JTable serverTable = null ;
private DefaultTableModel tableModel = null ;
private JPanel regListPanel = null ;
private JButton refreshButton = null ;
private JButton pingButton = null ;
private JButton selectAllButton = null ;
private JButton deselectAllButton = null ;
private JButton requestButton = null ;
private JButton registerButton = null ;
private JButton addServerButton = null ;
private JButton removeServerButton = null ;
private JButton unregisterServerButton = null ;
private JPanel purchasePanel = null ;
private JComboBox buyList = null ;
private JTextField tServer, tQuantity, tAddress ;
private JComboBox tNumItems ;
public boolean doAxis = true ;
private static int CHECK_COLUMN = 0 ;
private static int NAME_COLUMN = 1 ;
private static int URL_COLUMN = 2 ;
private static int TYPE_COLUMN = 3 ;
private static int WSDL_COLUMN = 4 ;
private static int STATE_COLUMN = 5 ;
private static int QUOTE_COLUMN = 6 ;
private static int NUM_COLUMNS = 7 ;
class MyTableModel extends DefaultTableModel {
public MyTableModel(Object[] obj, int x) { super( obj, x); }
public Class getColumnClass(int col) {
if ( col == CHECK_COLUMN ) return( Boolean.class );
return( super.getColumnClass(col) );
}
};
public rfq() {
setLayout( new BorderLayout() );
// Do the Registration Server list area
//////////////////////////////////////////////////////////////////////////
JPanel regSelectPanel = new JPanel();
regSelectPanel.setLayout( new BoxLayout(regSelectPanel, BoxLayout.X_AXIS) );
regSelectPanel.setBorder( new EmptyBorder(5,5,5,5) );
regSelectPanel.add( new JLabel( "Registration Server: " ) );
regSelectPanel.add( regServerList = new JComboBox() );
regSelectPanel.add( Box.createRigidArea(new Dimension(5,0)) );
regSelectPanel.add( removeButton = new JButton("Remove") );
loadRegList();
regServerList.setEditable( true );
regServerList.addActionListener( new ActionListener() {
public void actionPerformed(ActionEvent event) {
String act = event.getActionCommand();
if ( act.equals( "comboBoxChanged" ) ) {
String name = (String) regServerList.getSelectedItem();
if ( name != null && !name.equals("") ) {
chooseRegServer( name );
addRegistrationServer( name );
}
else
clearTable();
}
};
});
removeButton.setEnabled( true );
removeButton.addActionListener( new ActionListener() {
public void actionPerformed(ActionEvent event) {
if ( "Remove".equals(event.getActionCommand()) ) {
String name = (String) regServerList.getSelectedItem();
regServerList.removeItem( name );
saveRegList();
}
};
});
add( regSelectPanel, BorderLayout.NORTH );
// Do the List Of Registration Servers Table
//////////////////////////////////////////////////////////////////////////
regListPanel = new JPanel();
regListPanel.setLayout( new BorderLayout() );
regServerBorder = new TitledBorder(" Product Servers ");
regListPanel.setBorder( regServerBorder );
regListPanel.add( new JLabel( "Select the servers you want to request " +
"a price from:"), BorderLayout.NORTH );
tableModel = new MyTableModel( new Object[] {"", "Name", "URL", "Type",
"WSDL", "State", "Quote",
""}, 0 );
serverTable = new JTable( 0, NUM_COLUMNS );
serverTable.setModel( tableModel );
serverTable.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
TableColumn col = serverTable.getColumnModel().getColumn(CHECK_COLUMN);
col.setMaxWidth( 10 );
// col = serverTable.getColumnModel().getColumn(STATE_COLUMN);
// col.setMaxWidth( col.getPreferredWidth()/2 );
// col = serverTable.getColumnModel().getColumn(QUOTE_COLUMN);
// col.setMaxWidth( col.getPreferredWidth()/2 );
col = serverTable.getColumnModel().getColumn(TYPE_COLUMN);
col.setMaxWidth( col.getPreferredWidth()/2 );
tableModel.addTableModelListener( new TableModelListener() {
public void tableChanged(TableModelEvent event) {
int type = event.getType();
if ( type == TableModelEvent.UPDATE && event.getColumn() == 0 )
enableButtons();
};
});
regListPanel.add( new JScrollPane(serverTable), BorderLayout.CENTER );
JPanel btns = new JPanel();
// btns.setLayout( new BoxLayout( btns, BoxLayout.X_AXIS ) );
btns.setLayout( new GridBagLayout() );
GridBagConstraints c = new GridBagConstraints();
c.anchor = GridBagConstraints.WEST ;
c.gridwidth = 1 ;
c.fill = GridBagConstraints.HORIZONTAL ;
// row 1
btns.add( refreshButton = new JButton( "Refresh List" ), c );
btns.add( Box.createRigidArea(new Dimension(5,0)), c );
btns.add( selectAllButton = new JButton( "Select All" ), c );
btns.add( Box.createRigidArea(new Dimension(5,0)), c );
btns.add( requestButton = new JButton( "Request RFQs" ), c );
c.weightx = 1.0 ;
btns.add( Box.createHorizontalGlue(), c );
c.weightx = 0.0 ;
btns.add( registerButton = new JButton( "Register Server" ), c );
btns.add( Box.createRigidArea(new Dimension(5,0)), c );
c.gridwidth = GridBagConstraints.REMAINDER ;
btns.add( addServerButton = new JButton( "Add Bid Server" ), c );
// row 2
c.gridwidth = 1 ;
c.gridx = 2 ;
btns.add( deselectAllButton = new JButton( "Deselect All" ), c );
c.gridx = GridBagConstraints.RELATIVE ;
btns.add( Box.createRigidArea(new Dimension(5,0)), c );
btns.add( pingButton = new JButton( "Ping" ), c );
c.weightx = 1.0 ;
btns.add( Box.createRigidArea(new Dimension(5,0)), c );
c.weightx = 0.0 ;
btns.add( unregisterServerButton = new JButton( "Unregister Server" ), c );
btns.add( Box.createRigidArea(new Dimension(5,0)), c );
// btns.add( Box.createRigidArea(new Dimension(5,0)), c );
c.gridwidth = GridBagConstraints.REMAINDER ;
btns.add( removeServerButton = new JButton( "Remove Server" ), c );
regListPanel.add( btns, BorderLayout.SOUTH );
refreshButton.setEnabled( false );
refreshButton.addActionListener( new ActionListener() {
public void actionPerformed(ActionEvent event) {
if ( "Refresh List".equals(event.getActionCommand()) ) {
refreshList();
}
};
});
selectAllButton.setEnabled( false );
selectAllButton.addActionListener( new ActionListener() {
public void actionPerformed(ActionEvent event) {
if ( "Select All".equals(event.getActionCommand()) ) {
for ( int i = 0 ; i < tableModel.getRowCount() ; i++ ){
tableModel.setValueAt(new Boolean(true),i,CHECK_COLUMN);
}
}
};
});
deselectAllButton.setEnabled( false );
deselectAllButton.addActionListener( new ActionListener() {
public void actionPerformed(ActionEvent event) {
if ( "Deselect All".equals(event.getActionCommand()) ) {
for ( int i = 0 ; i < tableModel.getRowCount() ; i++ ){
tableModel.setValueAt(new Boolean(false),i,CHECK_COLUMN);
}
}
};
});
pingButton.setEnabled( false );
pingButton.addActionListener( new ActionListener() {
public void actionPerformed(ActionEvent event) {
if ( "Ping".equals(event.getActionCommand()) ) {
ping();
}
};
});
requestButton.setEnabled( false );
requestButton.addActionListener( new ActionListener() {
public void actionPerformed(ActionEvent event) {
if ( "Request RFQs".equals(event.getActionCommand()) ) {
requestRFQs();
}
};
});
registerButton.setEnabled( false );
registerButton.addActionListener( new ActionListener() {
public void actionPerformed(ActionEvent event) {
if ( "Register Server".equals(event.getActionCommand()) )
registerNewServer();
};
});
addServerButton.setEnabled( true );
addServerButton.addActionListener( new ActionListener() {
public void actionPerformed(ActionEvent event) {
if ( "Add Bid Server".equals(event.getActionCommand()) )
promptForServer();
};
});
removeServerButton.setEnabled( false );
removeServerButton.addActionListener( new ActionListener() {
public void actionPerformed(ActionEvent event) {
if ( "Remove Server".equals(event.getActionCommand()) )
removeServers();
};
});
unregisterServerButton.setEnabled( false );
unregisterServerButton.addActionListener( new ActionListener() {
public void actionPerformed(ActionEvent event) {
if ( "Unregister Server".equals(event.getActionCommand()) )
unregisterServer();
};
});
// Purchase data
//////////////////////////////////////////////////////////////////////////
GridBagLayout layout = new GridBagLayout();
// GridBagConstraints c = new GridBagConstraints();
c = new GridBagConstraints();
purchasePanel = new JPanel(layout);
purchasePanel.setBorder( new TitledBorder("Purchase") );
JButton tSimpleBuy ;
JButton tPOBuy ;
c.anchor = GridBagConstraints.WEST ;
c.gridwidth = GridBagConstraints.REMAINDER ;
purchasePanel.add( new JLabel("Select the purchase server from the " +
"combo box" ),c );
c.anchor = GridBagConstraints.EAST ;
c.gridwidth = 1 ;
purchasePanel.add( new JLabel("Server:"), c );
c.anchor = GridBagConstraints.WEST ;
c.gridwidth = GridBagConstraints.REMAINDER ;
purchasePanel.add( buyList = new JComboBox(), c );
c.gridwidth = 1 ;
c.anchor = GridBagConstraints.EAST ;
purchasePanel.add( new JLabel("Quantity:"),c );
c.anchor = GridBagConstraints.WEST ;
c.gridwidth = GridBagConstraints.REMAINDER ;
purchasePanel.add( tQuantity = new JTextField(6), c );
tQuantity.setText("1");
c.anchor = GridBagConstraints.EAST ;
c.gridwidth = 1 ;
purchasePanel.add( new JLabel("# Line Items:"),c );
c.anchor = GridBagConstraints.WEST ;
c.gridwidth = GridBagConstraints.REMAINDER ;
purchasePanel.add( tNumItems = new JComboBox(), c );
c.anchor = GridBagConstraints.WEST ;
c.gridwidth = 1 ;
purchasePanel.add( tSimpleBuy = new JButton( "Simple Buy" ) );
c.anchor = GridBagConstraints.WEST ;
c.gridwidth = GridBagConstraints.REMAINDER ;
purchasePanel.add( tPOBuy = new JButton( "PO Buy" ) );
for ( int j = 1 ; j < 20 ; j++ )
tNumItems.addItem( ""+j );
tSimpleBuy.addActionListener( new ActionListener() {
public void actionPerformed(ActionEvent event) {
if ( "Simple Buy".equals(event.getActionCommand()) ) {
simpleBuy();
}
};
});
tPOBuy.addActionListener( new ActionListener() {
public void actionPerformed(ActionEvent event) {
if ( "PO Buy".equals(event.getActionCommand()) ) {
poBuy();
}
};
});
JSplitPane splitPane = new JSplitPane( 0, regListPanel,
new JScrollPane(purchasePanel));
add( splitPane, BorderLayout.CENTER );
setSize(getPreferredSize());
splitPane.setDividerLocation( 200 );
purchasePanel.setEnabled( false );
}
public void addRegistrationServer( String name ) {
int count, i ;
if ( name == null || "".equals(name) ) return ;
count = regServerList.getItemCount();
for ( i = 0 ; i < count ; i++ )
if ( name.equals( regServerList.getItemAt(i) ) ) return ;
regServerList.addItem( name );
saveRegList();
}
public void chooseRegServer(String name) {
regServerURL = name ;
regServerBorder.setTitle( " Product Servers at ' " + name + " ' " );
regListPanel.repaint();
refreshList();
}
public void enableButtons() {
boolean flag ;
int i ;
int total = tableModel.getRowCount();
int count = 0 ;
for ( i = 0 ; i < total ; i++ ) {
flag = ((Boolean)tableModel.getValueAt(i,CHECK_COLUMN)).booleanValue();
if ( flag ) count++ ;
}
selectAllButton.setEnabled( total > 0 && count != total );
deselectAllButton.setEnabled( total > 0 && count > 0 );
pingButton.setEnabled( count > 0 );
requestButton.setEnabled( count > 0 );
removeServerButton.setEnabled( count > 0 );
unregisterServerButton.setEnabled( count > 0 );
}
public void clearTable() {
while ( tableModel.getRowCount() > 0 )
tableModel.removeRow(0);
enableButtons();
}
public void refreshList() {
clearTable();
Vector services = null ;
try {
services = vv.lookupAsString(regServerURL);
}
catch( Exception e ) {
System.err.println("---------------------------------------------");
e.printStackTrace();
JOptionPane.showMessageDialog(this, e.toString(), "Error",
JOptionPane.INFORMATION_MESSAGE );
}
for ( int i = 0 ; services != null && i < services.size() ; i++ ) {
Service s = (Service) services.elementAt(i);
addServer( s );
}
buyList.removeAllItems();
purchasePanel.setEnabled( false );
refreshButton.setEnabled( true );
registerButton.setEnabled( true );
enableButtons();
}
public void ping() {
Boolean flag ;
int i;
for ( i = 0 ; i < tableModel.getRowCount() ; i++ ) {
flag = (Boolean) tableModel.getValueAt( i, CHECK_COLUMN );
if ( flag.booleanValue() ) {
String url = (String) tableModel.getValueAt( i, URL_COLUMN );
Boolean value = new Boolean(false);
try {
value = vv.ping( url );
tableModel.setValueAt( value.booleanValue() ? "Alive" : "Down",
i, STATE_COLUMN );
serverTable.repaint();
}
catch( Exception e ) {
JOptionPane.showMessageDialog(this, e.toString(), "Error",
JOptionPane.INFORMATION_MESSAGE );
}
}
}
}
public void unregisterServer() {
Boolean flag ;
int i;
for ( i = 0 ; i < tableModel.getRowCount() ; i++ ) {
flag = (Boolean) tableModel.getValueAt( i, CHECK_COLUMN );
if ( flag.booleanValue() ) {
String name = (String) tableModel.getValueAt( i, NAME_COLUMN );
String regServer = (String) regServerList.getSelectedItem() ;
Boolean value = new Boolean(false);
try {
vv.unregister( regServer, name);
}
catch( Exception e ) {
JOptionPane.showMessageDialog(this, e.toString(), "Error",
JOptionPane.INFORMATION_MESSAGE );
}
}
}
refreshList();
}
public void requestRFQs() {
Boolean flag ;
int i, j;
// buyList.removeAllItems();
for ( i = 0 ; i < tableModel.getRowCount() ; i++ ) {
flag = (Boolean) tableModel.getValueAt( i, CHECK_COLUMN );
if ( flag.booleanValue() ) {
String url = (String) tableModel.getValueAt( i, URL_COLUMN );
double value = 0.0 ;
try {
value = vv.requestForQuote( url );
tableModel.setValueAt( new Double(value), i, QUOTE_COLUMN );
serverTable.repaint();
String str = (String) tableModel.getValueAt(i, NAME_COLUMN);
for ( j = 0 ; j < buyList.getItemCount(); j++ )
if ( ((String)buyList.getItemAt(j)).equals(str) ) break ;
if ( j == buyList.getItemCount() )
buyList.addItem( str );
}
catch( Exception e ) {
JOptionPane.showMessageDialog(this, e.toString(), "Error",
JOptionPane.INFORMATION_MESSAGE );
}
}
}
// buyList.setSelectedIndex(-1);
purchasePanel.setEnabled( true );
}
public void removeServers() {
Boolean flag ;
int i, j;
for ( i = tableModel.getRowCount()-1 ; i >= 0 ; i-- ) {
flag = (Boolean) tableModel.getValueAt( i, CHECK_COLUMN );
if ( flag.booleanValue() )
tableModel.removeRow( i );
}
enableButtons();
}
public void simpleBuy() {
try {
String url = null ;
int total = tableModel.getRowCount();
String name = (String) buyList.getSelectedItem();
for ( int i = 0 ; i < total ; i++ ) {
String val = (String) tableModel.getValueAt(i, NAME_COLUMN) ;
if ( val.equals(name) ) {
url = (String) tableModel.getValueAt(i, URL_COLUMN);
break ;
}
}
String address = "123 Main Street, Any Town, USA" ;
String product = "soap" ;
int quantity = Integer.parseInt((String) tQuantity.getText());
String value = null ;
value = vv.simpleBuy( url, quantity );
JOptionPane.showMessageDialog(this, value, "Receipt",
JOptionPane.INFORMATION_MESSAGE );
}
catch( Exception e ) {
JOptionPane.showMessageDialog(this, e.toString(), "Error",
JOptionPane.INFORMATION_MESSAGE );
}
}
public void poBuy() {
try {
String url = null ;
int total = tableModel.getRowCount();
String name = (String) buyList.getSelectedItem();
double price = 0 ;
for ( int i = 0 ; i < total ; i++ ) {
String val = (String) tableModel.getValueAt(i, NAME_COLUMN) ;
Double dval ;
if ( val.equals(name) ) {
url = (String) tableModel.getValueAt(i, URL_COLUMN);
dval = (Double) tableModel.getValueAt(i, QUOTE_COLUMN);
price = dval.doubleValue();
break ;
}
}
// String address = (String) tAddress.getText();
String product = "soap" ;
int quantity = Integer.parseInt((String) tQuantity.getText());
int numItems = Integer.parseInt((String) tNumItems.getSelectedItem());
String value = null ;
value = vv.buy( url, quantity, numItems, price );
JOptionPane.showMessageDialog(this, value, "Receipt",
JOptionPane.INFORMATION_MESSAGE );
}
catch( Exception e ) {
e.printStackTrace();
JOptionPane.showMessageDialog(this, e.toString(), "Error",
JOptionPane.INFORMATION_MESSAGE );
}
}
public void registerNewServer() {
Component parent = this ;
while ( parent != null && !(parent instanceof JFrame) )
parent = parent.getParent();
final JDialog j = new JDialog((JFrame)parent, "Register Server", true );
Container pane = j.getContentPane();
final JTextField fName = new JTextField(20),
fURL = new JTextField(20),
fType = new JTextField(20),
fWsdl = new JTextField(20);
JButton regButton, cancelButton ;
pane.setLayout( new GridBagLayout() );
GridBagConstraints c = new GridBagConstraints();
c.anchor = GridBagConstraints.WEST ;
c.gridwidth = 1 ;
pane.add( new JLabel( "Service Name" ), c );
c.anchor = GridBagConstraints.WEST ;
c.gridwidth = GridBagConstraints.REMAINDER ;
pane.add( fName, c );
c.anchor = GridBagConstraints.WEST ;
c.gridwidth = 1 ;
pane.add( new JLabel( "Service URL" ), c );
c.anchor = GridBagConstraints.WEST ;
c.gridwidth = GridBagConstraints.REMAINDER ;
pane.add( fURL, c );
c.anchor = GridBagConstraints.WEST ;
c.gridwidth = 1 ;
pane.add( new JLabel( "Service Type" ), c );
c.anchor = GridBagConstraints.WEST ;
c.gridwidth = GridBagConstraints.REMAINDER ;
pane.add( fType, c );
c.anchor = GridBagConstraints.WEST ;
c.gridwidth = 1 ;
pane.add( new JLabel( "WSDL URL" ), c );
c.anchor = GridBagConstraints.WEST ;
c.gridwidth = GridBagConstraints.REMAINDER ;
pane.add( fWsdl, c );
c.anchor = GridBagConstraints.WEST ;
c.gridwidth = 1 ;
pane.add( regButton = new JButton( "Register" ), c );
c.anchor = GridBagConstraints.WEST ;
c.gridwidth = 1 ;
pane.add( Box.createHorizontalStrut(3), c );
c.anchor = GridBagConstraints.WEST ;
c.gridwidth = 1 ;
pane.add( cancelButton = new JButton( "Cancel" ), c );
fType.setText( "Bid" );
regButton.addActionListener( new ActionListener() {
public void actionPerformed(ActionEvent event) {
if ( "Register".equals(event.getActionCommand()) ) {
Service s = new Service();
s.setServiceName( fName.getText() );
s.setServiceUrl( fURL.getText() );
s.setServiceType( fType.getText() );
s.setServiceWsdl( fWsdl.getText() );
register( s );
j.dispose();
}
};
});
cancelButton.addActionListener( new ActionListener() {
public void actionPerformed(ActionEvent event) {
if ( "Cancel".equals(event.getActionCommand()) ) {
j.dispose();
}
};
});
j.pack();
Point p = new Point( parent.getLocation() );
Dimension d = parent.getSize();
p.setLocation( (int)(p.getX() + d.getWidth()/2),
(int)(p.getY() + d.getHeight()/2) );
d = j.getSize();
j.setLocation( (int)(p.getX() - d.getWidth()/2),
(int)(p.getY() - d.getHeight()/2) );
j.show();
}
public void promptForServer() {
Component parent = this ;
while ( parent != null && !(parent instanceof JFrame) )
parent = parent.getParent();
final JDialog j = new JDialog((JFrame)parent, "Add Bid Server", true );
Container pane = j.getContentPane();
final JTextField fName = new JTextField(20),
fURL = new JTextField(20),
fType = new JTextField(20),
fWsdl = new JTextField(20);
JButton addButton, cancelButton ;
pane.setLayout( new GridBagLayout() );
GridBagConstraints c = new GridBagConstraints();
c.anchor = GridBagConstraints.WEST ;
c.gridwidth = 1 ;
pane.add( new JLabel( "Service Name" ), c );
c.anchor = GridBagConstraints.WEST ;
c.gridwidth = GridBagConstraints.REMAINDER ;
pane.add( fName, c );
c.anchor = GridBagConstraints.WEST ;
c.gridwidth = 1 ;
pane.add( new JLabel( "Service URL" ), c );
c.anchor = GridBagConstraints.WEST ;
c.gridwidth = GridBagConstraints.REMAINDER ;
pane.add( fURL, c );
c.anchor = GridBagConstraints.WEST ;
c.gridwidth = 1 ;
pane.add( new JLabel( "Service Type" ), c );
c.anchor = GridBagConstraints.WEST ;
c.gridwidth = GridBagConstraints.REMAINDER ;
pane.add( fType, c );
c.anchor = GridBagConstraints.WEST ;
c.gridwidth = 1 ;
pane.add( new JLabel( "WSDL URL" ), c );
c.anchor = GridBagConstraints.WEST ;
c.gridwidth = GridBagConstraints.REMAINDER ;
pane.add( fWsdl, c );
c.anchor = GridBagConstraints.WEST ;
c.gridwidth = 1 ;
pane.add( addButton = new JButton( "Add" ), c );
c.anchor = GridBagConstraints.WEST ;
c.gridwidth = 1 ;
pane.add( Box.createHorizontalStrut(3), c );
c.anchor = GridBagConstraints.WEST ;
c.gridwidth = 1 ;
pane.add( cancelButton = new JButton( "Cancel" ), c );
fType.setText( "Bid" );
addButton.addActionListener( new ActionListener() {
public void actionPerformed(ActionEvent event) {
if ( "Add".equals(event.getActionCommand()) ) {
Service s = new Service();
s.setServiceName( fName.getText() );
s.setServiceUrl( fURL.getText() );
s.setServiceType( fType.getText() );
s.setServiceWsdl( fWsdl.getText() );
addServer( s );
j.dispose();
}
};
});
cancelButton.addActionListener( new ActionListener() {
public void actionPerformed(ActionEvent event) {
if ( "Cancel".equals(event.getActionCommand()) ) {
j.dispose();
}
};
});
j.pack();
Point p = new Point( parent.getLocation() );
Dimension d = parent.getSize();
p.setLocation( (int)(p.getX() + d.getWidth()/2),
(int)(p.getY() + d.getHeight()/2) );
d = j.getSize();
j.setLocation( (int)(p.getX() - d.getWidth()/2),
(int)(p.getY() - d.getHeight()/2) );
j.show();
}
public void addServer(Service s) {
Object[] objs = new Object[NUM_COLUMNS] ;
objs[0] = new Boolean(false);
objs[1] = s.getServiceName();
objs[2] = s.getServiceUrl();
objs[3] = s.getServiceType();
objs[4] = s.getServiceWsdl();
objs[5] = null ;
objs[6] = null ;
tableModel.addRow( objs );
}
public void register(Service s) {
try {
vv.register( (String) regServerList.getSelectedItem(), s );
refreshList();
}
catch( Exception e ) {
JOptionPane.showMessageDialog(this, e.toString(), "Error",
JOptionPane.INFORMATION_MESSAGE );
}
}
public void loadRegList() {
try {
FileReader fr = new FileReader( "reg.lst" );
LineNumberReader lnr = new LineNumberReader( fr );
String line = null ;
while ( (line = lnr.readLine()) != null )
addRegistrationServer( line );
fr.close();
}
catch( Exception e ) {
e.printStackTrace();
}
}
public void saveRegList() {
try {
FileOutputStream fos = new FileOutputStream( "reg.lst" );
PrintWriter pw = new PrintWriter( fos );
int count = regServerList.getItemCount();
int i ;
for ( i = 0 ; i < count ; i++ )
pw.println( (String) regServerList.getItemAt(i) );
pw.close();
fos.close();
}
catch( Exception e ) {
e.printStackTrace();
}
}
public static void main(String[] args) {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
JFrame window = new JFrame("Request For Quote Client") {
protected void processWindowEvent(WindowEvent event) {
switch( event.getID() ) {
case WindowEvent.WINDOW_CLOSING: exit();
break ;
default: super.processWindowEvent(event);
break ;
}
}
private void exit() {
System.exit(0);
}
};
window.getContentPane().add( new rfq() );
window.pack();
window.setSize( new Dimension(800, 500) );
window.setVisible( true );
}
catch( Throwable exp ) {
exp.printStackTrace();
}
}
}
1.1 xml-soap/java/samples/bidbuy/client/vInterface.java
Index: vInterface.java
===================================================================
package samples.bidbuy.client;
import java.util.*;
import samples.bidbuy.shared.*;
public interface vInterface {
public void register(String registryURL, Service s) throws Exception ;
public void unregister(String registryURL, String name) throws Exception ;
public Boolean ping(String serverURL) throws Exception ;
public Vector lookupAsString(String registryURL) throws Exception ;
public double requestForQuote(String serverURL) throws Exception ;
public String simpleBuy(String serverURL, int quantity ) throws Exception ;
public String buy(String serverURL, int quantity, int numItems, double price)
throws Exception;
}
1.1 xml-soap/java/samples/bidbuy/server/bid/BidService.java
Index: BidService.java
===================================================================
package samples.bidbuy.server.bid;
import samples.bidbuy.shared.*;
/**
* Big/PurchaseOrder Service
*/
public class BidService {
static int nextReceiptNumber = 9000;
/**
* Request a quote for a given quantity of a specified product
* @param productName name of product
* @param quantity number desired
* @return Total amount in US$ for complete purchase
*/
public double RequestForQuote(String productName, int quantity) {
if (quantity < 100) {
return 1.0 * quantity;
} if (quantity < 1000) {
return 0.8 * quantity;
} else {
return 0.7 * quantity;
}
}
/**
* Purchase a given quantity of a specified product
* @param productName name of product
* @param quantity number desired
* @param price desired price (!!!)
* @param customerId who you are
* @param shipTo where you want the goods to go
* @param date where you want the goods to go
* @return Receipt
*/
public String SimpleBuy(String address, String productName, int quantity) {
return "Receipt #" + (nextReceiptNumber++) + '\n' +
"==============\n" +
"Quantity=" + quantity + '\n' +
"Product Name=" + productName + '\n' +
"Address=" + address + '\n' +
"Price=$" + RequestForQuote(productName, quantity) + "\n\n" +
"Courtesy of Apache SOAP";
}
/**
* Process a purchase order.
* @return Receipt
*/
public String Buy(PurchaseOrder po) {
return "Receipt #" + (nextReceiptNumber++) + '\n' +
"==============\n" + po + "\n\n" +
"Courtesy of Apache SOAP";
}
/**
* Let the world know that we are still alive...
*/
public void Ping() {
}
}
1.1 xml-soap/java/samples/bidbuy/server/bid/DeploymentDescriptor.xml
Index: DeploymentDescriptor.xml
===================================================================
<isd:service xmlns:isd="http://xml.apache.org/xml-soap/deployment"
id="http://www.soapinterop.org/Bid">
<isd:provider type="java"
scope="Application"
methods="RequestForQuote SimpleBuy Buy Ping">
<isd:java class="samples.bidbuy.server.bid.BidService" 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="http://www.soapinterop.org/Bid" qname="x:PurchaseOrder"
javaType="samples.bidbuy.shared.PurchaseOrder"
xml2JavaClassName="samples.bidbuy.shared.PurchaseOrderSerializer"/>
<isd:map encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:x="http://www.soapinterop.org/Bid" qname="x:Address"
javaType="samples.bidbuy.shared.Address"
xml2JavaClassName="samples.bidbuy.shared.AddressSerializer"/>
<isd:map encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:x="http://www.soapinterop.org/Bid" qname="x:LineItem"
javaType="samples.bidbuy.shared.LineItem"
xml2JavaClassName="samples.bidbuy.shared.LineItemSerializer"/>
<isd:map encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:x="" qname="x:Address"
xml2JavaClassName="org.apache.soap.encoding.soapenc.StringDeserializer"/>
<isd:map encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:x="" qname="x:ProductName"
xml2JavaClassName="org.apache.soap.encoding.soapenc.StringDeserializer"/>
<isd:map encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:x="" qname="x:Quantity"
xml2JavaClassName="org.apache.soap.encoding.soapenc.IntDeserializer"/>
<isd:map encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:x="" qname="x:PO"
xml2JavaClassName="samples.bidbuy.shared.PurchaseOrderSerializer"/>
<isd:map encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:x="" qname="x:poID"
xml2JavaClassName="org.apache.soap.encoding.soapenc.StringDeserializer"/>
<isd:map encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:x="" qname="x:createDate"
xml2JavaClassName="org.apache.soap.encoding.soapenc.DateSerializer"/>
<isd:map encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:x="" qname="x:shipTo"
xml2JavaClassName="samples.bidbuy.shared.AddressSerializer"/>
<isd:map encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:x="" qname="x:billTo"
xml2JavaClassName="samples.bidbuy.shared.AddressSerializer"/>
<isd:map encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:x="" qname="x:items"
xml2JavaClassName="org.apache.soap.encoding.soapenc.ArraySerializer"/>
<isd:map encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:x="" qname="x:name"
xml2JavaClassName="org.apache.soap.encoding.soapenc.StringDeserializer"/>
<isd:map encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:x="" qname="x:address"
xml2JavaClassName="org.apache.soap.encoding.soapenc.StringDeserializer"/>
<isd:map encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:x="" qname="x:city"
xml2JavaClassName="org.apache.soap.encoding.soapenc.StringDeserializer"/>
<isd:map encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:x="" qname="x:state"
xml2JavaClassName="org.apache.soap.encoding.soapenc.StringDeserializer"/>
<isd:map encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:x="" qname="x:zipCode"
xml2JavaClassName="org.apache.soap.encoding.soapenc.StringDeserializer"/>
<isd:map encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:x="" qname="x:quantity"
xml2JavaClassName="org.apache.soap.encoding.soapenc.IntDeserializer"/>
<isd:map encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:x="" qname="x:price"
xml2JavaClassName="org.apache.soap.encoding.soapenc.DecimalDeserializer"/>
</isd:mappings>
</isd:service>
1.1 xml-soap/java/samples/bidbuy/server/bid/deploy.bat
Index: deploy.bat
===================================================================
@echo off
echo This test assumes a server URL of http://localhost:8080/soap/servlet/rpcrouter
echo Deploying the bid service...
java org.apache.soap.server.ServiceManagerClient http://localhost:8080/soap/servlet/rpcrouter deploy DeploymentDescriptor.xml
echo .
1.1 xml-soap/java/samples/bidbuy/server/registry/DeploymentDescriptor.xml
Index: DeploymentDescriptor.xml
===================================================================
<isd:service xmlns:isd="http://xml.apache.org/xml-soap/deployment"
id="http://www.soapinterop.org/Registry">
<isd:provider type="java"
scope="Application"
methods="Unregister Register Lookup LookupAsString">
<isd:java class="samples.bidbuy.server.registry.RegistryService" 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="http://www.soapinterop.org/Registry" qname="x:Service"
javaType="samples.bidbuy.shared.Service"
java2XMLClassName="samples.bidbuy.shared.ServiceSerializer"
xml2JavaClassName="samples.bidbuy.shared.ServiceSerializer"/>
<isd:map encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:x="" qname="x:ServiceName"
xml2JavaClassName="org.apache.soap.encoding.soapenc.StringDeserializer"/>
<isd:map encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:x="" qname="x:ServiceUrl"
xml2JavaClassName="org.apache.soap.encoding.soapenc.StringDeserializer"/>
<isd:map encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:x="" qname="x:ServiceType"
xml2JavaClassName="org.apache.soap.encoding.soapenc.StringDeserializer"/>
<isd:map encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:x="" qname="x:ServiceWsdl"
xml2JavaClassName="org.apache.soap.encoding.soapenc.StringDeserializer"/>
</isd:mappings>
</isd:service>
1.1 xml-soap/java/samples/bidbuy/server/registry/RegistryService.java
Index: RegistryService.java
===================================================================
package samples.bidbuy.server.registry;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Vector;
import java.io.FileInputStream ;
import java.io.FileOutputStream ;
import java.io.ObjectInputStream ;
import java.io.ObjectOutputStream ;
import samples.bidbuy.shared.*;
public class RegistryService {
private static Hashtable registry = new Hashtable();
/**
* Find a named service in a list
* @param list of services
* @param name to search for
* @return service found (or null)
*/
public RegistryService() {
load();
}
public void load() {
try {
FileInputStream fis = new FileInputStream("bid.reg");
ObjectInputStream ois = new ObjectInputStream( fis );
registry = (Hashtable) ois.readObject();
ois.close();
fis.close();
} catch(java.io.FileNotFoundException fnfe){
// nop
} catch(Exception e){
e.printStackTrace();
}
}
public void save() {
try {
FileOutputStream fos = new FileOutputStream("bid.reg");
ObjectOutputStream oos = new ObjectOutputStream( fos );
oos.writeObject( registry );
oos.close();
fos.close();
} catch(Exception e){
e.printStackTrace();
}
}
private Service find(Vector list, String name) {
Enumeration e = list.elements();
while (e.hasMoreElements()) {
Service s = (Service) e.nextElement();
if (s.getServiceName().equals(name)) return s;
}
return null;
}
/**
* Unregister a serivce
* @param server name
*/
public void Unregister(String name) {
Enumeration e1 = registry.keys();
while (e1.hasMoreElements()) {
Vector list = (Vector) registry.get(e1.nextElement());
Enumeration e2 = list.elements();
while (e2.hasMoreElements()) {
Service s = (Service) e2.nextElement();
if (s.getServiceName().equals(name)) {
list.remove(s);
save();
}
}
}
}
/**
* Register a new serivce
* @param server name
* @param url of endpoint
* @param stype
* @param wsdl
*/
public void Register(String name, String url, String stype, String wsdl) {
Vector list = (Vector)registry.get(stype);
if (list == null) registry.put(stype, list=new Vector());
Service service = find(list, name);
if (service==null)
list.add(service=new Service());
service.setServiceName(name);
service.setServiceUrl(url);
service.setServiceType(stype);
service.setServiceWsdl(wsdl);
save();
}
/**
* Return the current list of services as an array
* @param Service Name
* @return List of servers that implement that service
*/
public Service[] Lookup(String stype) {
if (!registry.containsKey(stype)) return new Service[] {};
Vector list = (Vector)registry.get(stype);
Service[] result = new Service[list.size()];
list.copyInto(result);
return result;
}
/*
* Return the current list of services as a string
*/
public String LookupAsString(String stype) {
Service[] services = Lookup(stype);
String result = "";
for (int i=0; i<services.length; i++) {
Service service = services[i];
result += service.getServiceName() + "\t" +
service.getServiceUrl() + "\t" +
service.getServiceType() + "\t" +
service.getServiceWsdl() + "\n";
}
return result;
}
}
1.1 xml-soap/java/samples/bidbuy/server/registry/deploy.bat
Index: deploy.bat
===================================================================
@echo off
echo This test assumes a server URL of http://localhost:8080/soap/servlet/rpcrouter
echo Deploying the registry service...
java org.apache.soap.server.ServiceManagerClient http://localhost:8080/soap/servlet/rpcrouter deploy DeploymentDescriptor.xml
echo .