KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > samples > jaxm > UddiPing


1 /*
2  * Copyright 2002-2004 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 at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * 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 and
14  * limitations under the License.
15  */

16 package samples.jaxm;
17
18 import javax.xml.messaging.URLEndpoint;
19 import javax.xml.soap.MessageFactory JavaDoc;
20 import javax.xml.soap.SOAPBody JavaDoc;
21 import javax.xml.soap.SOAPConnection JavaDoc;
22 import javax.xml.soap.SOAPConnectionFactory JavaDoc;
23 import javax.xml.soap.SOAPEnvelope JavaDoc;
24 import javax.xml.soap.SOAPMessage JavaDoc;
25
26 public class UddiPing {
27
28     public static void main(String JavaDoc[] args) throws Exception JavaDoc {
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 JavaDoc name, String JavaDoc url) throws Exception JavaDoc {
37         // Create the connection and the message factory.
38
SOAPConnectionFactory JavaDoc scf = SOAPConnectionFactory.newInstance();
39         SOAPConnection JavaDoc connection = scf.createConnection();
40         MessageFactory JavaDoc msgFactory = MessageFactory.newInstance();
41
42         // Create a message
43
SOAPMessage JavaDoc msg = msgFactory.createMessage();
44
45         // Create an envelope in the message
46
SOAPEnvelope JavaDoc envelope = msg.getSOAPPart().getEnvelope();
47
48         // Get hold of the the body
49
SOAPBody JavaDoc body = envelope.getBody();
50
51         javax.xml.soap.SOAPBodyElement JavaDoc 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 JavaDoc reply = connection.call(msg, endpoint);
63         //System.out.println("Received reply from: " + endpoint);
64
//reply.writeTo(System.out);
65
connection.close();
66     }
67 }
68
69
70
71
72
73
74
Popular Tags