1/*2 * Copyright 2001-2010 The Apache Software Foundation.3 * 4 * Licensed under the Apache License, Version 2.0 (the "License");5 * you may not use this file except in compliance with the License.6 * You may obtain a copy of the License at7 * 8 * http://www.apache.org/licenses/LICENSE-2.09 * 10 * Unless required by applicable law or agreed to in writing, software11 * distributed under the License is distributed on an "AS IS" BASIS,12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13 * See the License for the specific language governing permissions and14 * limitations under the License.15 *16 */17package org.apache.juddi.example.wsdl2uddi;
1819import java.net.URL;
20import java.util.Map;
2122import javax.xml.ws.BindingProvider;
2324import org.apache.juddi.samples.HelloWorld;
25import org.apache.juddi.samples.HelloWorld_Service;
26import org.apache.juddi.v3.client.config.UDDIClerk;
27import org.apache.juddi.v3.client.config.UDDIClient;
28import org.apache.juddi.v3.client.mapping.ServiceLocator;
2930publicclassCall {
3132publicvoid call() {
33try {
34 UDDIClient uddiClient = newUDDIClient("META-INF/wsdl2uddi-uddi.xml");
35 UDDIClerk clerk = uddiClient.getClerk("joe");
3637//find the service in the UDDI registry38 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";
4142long startTime = System.currentTimeMillis();
43 ServiceLocator serviceLocator = newServiceLocator(clerk);
44 System.out.println("Created Cache in " + (System.currentTimeMillis() - startTime) + " [milliseconds]");
45 System.out.println("Now adding a listener to the cache..."); //expensive46 startTime = System.currentTimeMillis();
47 serviceLocator.withLiveCache(new URL("http://localhost:18079"));
48 System.out.println("Add Listener to Cache in " + (System.currentTimeMillis() - startTime) + " [milliseconds]");
4950//first time the lookup will have to contact UDDI51 startTime = System.currentTimeMillis();
52 String endpoint = serviceLocator.lookupEndpoint(helloWorldServiceKey);
53long duration = System.currentTimeMillis() - startTime;
54 System.out.println("1. UDDI Lookup - Elapsed time: " + duration + "[milliseconds] Endpoint=" + endpoint);
5556//second lookup should be lightning fast57long startTime2 = System.currentTimeMillis();;
58 String endpoint2 = serviceLocator.lookupEndpoint(helloWorldServiceKey);
59long duration2 = System.currentTimeMillis() - startTime2;
60 System.out.println("2. Cache Lookup - Elapsed time: " + duration2 + "[milliseconds] Endpoint=" + endpoint2);
6162//Invoke the endpoint using 'endpoint2'63 HelloWorld_Service helloWorldService = newHelloWorld_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//need to call shutdown to take down the LiveCache Callback Endpoint.70 Thread.sleep(10l);
71 serviceLocator.shutdown();
72//TODO JUDDI-61073//FindTModel findBindingTModel = WSDL2UDDI.createFindBindingTModelForPortType(portType, namespace);7475 }
76catch (Exception e) {
77 e.printStackTrace();
78 }
79 }
8081publicstaticvoid main (String args[]) {
82 Call sp = newCall();
83 sp.call();
84 }
85 }