1 16 package samples.jaxm; 17 18 import javax.xml.messaging.URLEndpoint; 19 import javax.xml.soap.MessageFactory ; 20 import javax.xml.soap.SOAPBody ; 21 import javax.xml.soap.SOAPConnection ; 22 import javax.xml.soap.SOAPConnectionFactory ; 23 import javax.xml.soap.SOAPEnvelope ; 24 import javax.xml.soap.SOAPMessage ; 25 26 public class UddiPing { 27 28 public static void main(String [] args) throws Exception { 29 if (args.length != 2) { 30 System.err.println("Usage: UddiPing business-name uddi-url"); 31 System.exit(1); 32 } 33 searchUDDI(args[0], args[1]); 34 } 35 36 public static void searchUDDI(String name, String url) throws Exception { 37 SOAPConnectionFactory scf = SOAPConnectionFactory.newInstance(); 39 SOAPConnection connection = scf.createConnection(); 40 MessageFactory msgFactory = MessageFactory.newInstance(); 41 42 SOAPMessage msg = msgFactory.createMessage(); 44 45 SOAPEnvelope envelope = msg.getSOAPPart().getEnvelope(); 47 48 SOAPBody body = envelope.getBody(); 50 51 javax.xml.soap.SOAPBodyElement bodyElement = body.addBodyElement(envelope.createName("find_business", "", 52 "urn:uddi-org:api")); 53 54 bodyElement.addAttribute(envelope.createName("generic"), "1.0") 55 .addAttribute(envelope.createName("maxRows"), "100") 56 .addChildElement("name") 57 .addTextNode(name); 58 59 URLEndpoint endpoint = new URLEndpoint(url); 60 msg.saveChanges(); 61 62 SOAPMessage reply = connection.call(msg, endpoint); 63 connection.close(); 66 } 67 } 68 69 70 71 72 73 74 | Popular Tags |