1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.juddi.example.wsdl2uddi;
18
19 import java.net.URL;
20 import java.util.Map;
21
22 import javax.xml.ws.BindingProvider;
23
24 import org.apache.juddi.samples.HelloWorld;
25 import org.apache.juddi.samples.HelloWorld_Service;
26 import org.apache.juddi.v3.client.config.UDDIClerk;
27 import org.apache.juddi.v3.client.config.UDDIClient;
28 import org.apache.juddi.v3.client.mapping.ServiceLocator;
29
30 public class Call {
31
32 public void call() {
33 try {
34 UDDIClient uddiClient = new UDDIClient("META-INF/wsdl2uddi-uddi.xml");
35 UDDIClerk clerk = uddiClient.getClerk("joe");
36
37
38 System.out.println("The clientside of a runtime lookup usually knows the serviceKey.");
39 System.out.println("To get updated binding information you should use the ServiceLocator with a live cache.");
40 String helloWorldServiceKey = "uddi:uddi.joepublisher.com:service_helloworld";
41
42 long startTime = System.currentTimeMillis();
43 ServiceLocator serviceLocator = new ServiceLocator(clerk);
44 System.out.println("Created Cache in " + (System.currentTimeMillis() - startTime) + " [milliseconds]");
45 System.out.println("Now adding a listener to the cache...");
46 startTime = System.currentTimeMillis();
47 serviceLocator.withLiveCache(new URL("http://localhost:18079"));
48 System.out.println("Add Listener to Cache in " + (System.currentTimeMillis() - startTime) + " [milliseconds]");
49
50
51 startTime = System.currentTimeMillis();
52 String endpoint = serviceLocator.lookupEndpoint(helloWorldServiceKey);
53 long duration = System.currentTimeMillis() - startTime;
54 System.out.println("1. UDDI Lookup - Elapsed time: " + duration + "[milliseconds] Endpoint=" + endpoint);
55
56
57 long startTime2 = System.currentTimeMillis();;
58 String endpoint2 = serviceLocator.lookupEndpoint(helloWorldServiceKey);
59 long duration2 = System.currentTimeMillis() - startTime2;
60 System.out.println("2. Cache Lookup - Elapsed time: " + duration2 + "[milliseconds] Endpoint=" + endpoint2);
61
62
63 HelloWorld_Service helloWorldService = new HelloWorld_Service();
64 HelloWorld helloWorld = helloWorldService.getHelloWorldImplPort();
65 Map<String, Object> requestContext = ((BindingProvider) helloWorld).getRequestContext();
66 requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpoint2);
67 String reply = helloWorld.sayHi("Judy");
68 System.out.println("*************** Service reply: " + reply);
69
70 Thread.sleep(10l);
71 serviceLocator.shutdown();
72
73
74
75 }
76 catch (Exception e) {
77 e.printStackTrace();
78 }
79 }
80
81 public static void main (String args[]) {
82 Call sp = new Call();
83 sp.call();
84 }
85 }