1 27 28 package mypackage; 29 30 import javax.xml.soap.*; 31 import java.net.*; 32 import java.util.*; 33 import java.io.*; 34 35 36 public class UddiPing { 37 public static void main(String [] args) { 38 try { 39 if (args.length != 2) { 41 System.err.println("Usage: asant run " + 42 "-Dbusiness-name=<name>"); 43 System.exit(1); 44 } 45 46 Properties myprops = new Properties(); 49 myprops.load(new FileInputStream(args[0])); 50 51 Properties props = System.getProperties(); 52 53 Enumeration propNames = myprops.propertyNames(); 54 while (propNames.hasMoreElements()) { 55 String s = (String ) propNames.nextElement(); 56 props.setProperty(s, myprops.getProperty(s)); 57 } 58 59 SOAPConnectionFactory soapConnectionFactory = 62 SOAPConnectionFactory.newInstance(); 63 SOAPConnection connection = 64 soapConnectionFactory.createConnection(); 65 MessageFactory messageFactory = MessageFactory.newInstance(); 66 SOAPFactory soapFactory = SOAPFactory.newInstance(); 67 68 SOAPMessage message = messageFactory.createMessage(); 70 71 SOAPHeader header = message.getSOAPHeader(); 73 header.detachNode(); 74 75 SOAPBody body = message.getSOAPBody(); 77 78 SOAPBodyElement findBusiness = 80 body.addBodyElement(soapFactory.createName("find_business", 81 "", 82 "urn:uddi-org:api_v2")); 83 findBusiness.addAttribute(soapFactory.createName("generic"), "2.0"); 84 findBusiness.addAttribute(soapFactory.createName("maxRows"), "100"); 85 86 SOAPElement businessName = 87 findBusiness.addChildElement(soapFactory.createName("name")); 88 businessName.addTextNode(args[1]); 89 90 message.saveChanges(); 91 92 System.out.println("\n----- Request Message ----\n"); 94 message.writeTo(System.out); 95 96 URL endpoint = new URL(System.getProperties().getProperty("URL")); 98 99 SOAPMessage reply = connection.call(message, endpoint); 101 102 System.out.println("\n\nReceived reply from: " + endpoint); 103 System.out.println("\n------ Reply Message -----\n"); 104 105 reply.writeTo(System.out); 107 108 SOAPBody replyBody = reply.getSOAPBody(); 110 111 118 System.out.println("\n\nContent extracted from " + 119 "the reply message:\n"); 120 121 Iterator businessListIterator = 122 replyBody.getChildElements(soapFactory.createName( 123 "businessList", 124 "", 125 "urn:uddi-org:api_v2")); 126 127 131 SOAPBodyElement businessList = 132 (SOAPBodyElement) businessListIterator.next(); 133 134 140 Iterator businessInfosIterator = 141 businessList.getChildElements(soapFactory.createName( 142 "businessInfos", 143 "", 144 "urn:uddi-org:api_v2")); 145 146 150 SOAPElement businessInfos = 151 (SOAPElement) businessInfosIterator.next(); 152 153 159 Iterator businessInfoIterator = 160 businessInfos.getChildElements(soapFactory.createName( 161 "businessInfo", 162 "", 163 "urn:uddi-org:api_v2")); 164 165 if (!businessInfoIterator.hasNext()) { 166 System.out.println("No businesses found " + 167 "matching the name \"" + args[1] + "\"."); 168 } else { 169 while (businessInfoIterator.hasNext()) { 170 SOAPElement businessInfo = 171 (SOAPElement) businessInfoIterator.next(); 172 173 Iterator nameIterator = 176 businessInfo.getChildElements(soapFactory.createName( 177 "name", 178 "", 179 "urn:uddi-org:api_v2")); 180 181 while (nameIterator.hasNext()) { 182 businessName = (SOAPElement) nameIterator.next(); 183 System.out.println("Company name: " + 184 businessName.getValue()); 185 } 186 187 Iterator descriptionIterator = 188 businessInfo.getChildElements(soapFactory.createName( 189 "description", 190 "", 191 "urn:uddi-org:api_v2")); 192 193 while (descriptionIterator.hasNext()) { 194 SOAPElement businessDescription = 195 (SOAPElement) descriptionIterator.next(); 196 System.out.println("Description: " + 197 businessDescription.getValue()); 198 } 199 200 System.out.println(""); 201 } 202 } 203 204 connection.close(); 206 } catch (Exception ex) { 207 ex.printStackTrace(); 208 } 209 } 210 } 211 | Popular Tags |