|
Concurrently Accessing Multiple Web Service Instances, by Joe Verzulli
WSJ Vol 02 Issue 03 - pg.63
Listing 1
IBookstore multiBookstore;
String urls =
{"http://host1.com:8080/soap/servlet/rpcrouter",
"http://host2.com:8080/soap/servlet/rpcrouter"}
multiBookstore =
(IBookstore) MultiServiceProxy.newInstance(
Bookstore_ServiceProxy.class,
urls,
listener);
multiBookstore.getPrice("OOSC2");
Listing 2
class SampleIncrementalListener
implements IIncrementalServiceListener
{
public void result(ServiceResultEvent r)
{
System.out.println("Got result
"
+ r.getValue()
+ " from Web service "
+ "at URL " + r.getURL());
}
}
.
.
.
// The following code is in the client that will
// contact multiple web services.
IIncrementalServiceListener listener =
new SampleIncrementalListener();
multiBookstore =
(IBookstore) MultiServiceProxy.newInstance(
Bookstore_ServiceProxy.class,
urls,
listener);
multiBookstore.getPrice("OOSC2");
System.out.println("Back from "
+ "multiBookstore.getPrice()");
Listing 3
public static synchronized Object newInstance(
Class webServiceProxyClass,
String urls[],
IServiceListener listeners[])
{
return Proxy.newProxyInstance(
webServiceProxyClass.getClassLoader(),
webServiceProxyClass.getInterfaces(),
new MultiServiceProxy(
webServiceProxyClass,
urls,
listeners));
}
|