|
C:\uddi\inspireit\uddi\examples\LoggingExample.java
|
1 package inspireit.uddi.examples;
2
3 import java.net.*;
4
5 import inspireit.uddi.base.*;
6 import inspireit.uddi.collections.*;
7 import inspireit.uddi.request.*;
8 import inspireit.uddi.request.base.*;
9 import inspireit.uddi.response.*;
10 import inspireit.uddi.response.base.*;
11
12 /**
13 * This example is derived from the FindBusinessExample example. It shows how
14 * logging can be activated and a specific logging system to be used. If Log4J
15 * logging is experimented, the Log4J JAR archives needs to be located in the
16 * CLASSPATH.
17 *
18 * @author Bertrand Fontaine, <a href="http://www.inspireit.biz" target="INSPIREIT">INSPIRE IT</a>
19 */
20 public class LoggingExample {
21
22 public LoggingExample(String queryURL) throws Exception {
23 // define the appropriate UDDI profile
24 UDDIProfile profile = new UDDIProfile();
25 profile.setQueryURL(new URL(queryURL));
26 profile.setVersion(UDDIConstants.UDDI_V2);
27
28 // activates the logging of the XML conversation between the client and the registry
29 profile.setProperty("inspireit.uddi.logEnabled","true");
30
31 // uncomment one of the following lines for either Log4J or XML-based logging
32 // check out the result in inspireit-uddi.log and inspireit-uddi.err
33 // profile.setProperty("inspireit.uddi.logging.provider","inspireit.logging.Log4JLogger");
34 profile.setProperty("inspireit.uddi.logging.provider","inspireit.logging.XMLLogger");
35
36 UDDIQuerier querier = UDDIQuerier.getQuerier(profile);
37
38 try {
39 // find max. 5 businesses starting with "S", sorted by name descending
40 int max = 5;
41 Name name = new Name("S%");
42 FindQualifiers findQualifiers = new FindQualifiers();
43 findQualifiers.add(FindQualifier.sortByNameDesc);
44
45 BusinessList businessList = querier.findBusiness(name, findQualifiers, max);
46 BusinessInfos businessInfos = businessList.getBusinessInfos();
47 BusinessInfo businessInfo[] = businessInfos.toArray();
48
49 for(int i=0; i< businessInfo.length; i++) {
50 BusinessInfo bi = businessInfo[i];
51 Names names = bi.getNames();
52 Name _name[] = names.toArray();
53 System.out.println("BusinessInfo #" + i + ": " + _name[0]);
54 }
55 } catch(UDDIException e) {
56 e.printStackTrace();
57 }
58 }
59
60 public static void main(String args[]) throws Exception {
61 if (args.length != 1) {
62 System.out.println("LoggingExample usage: java LoggingExample <queryURL>");
63 System.exit(0);
64 }
65
66 new LoggingExample(args[0]);
67 return;
68 }
69 }
70