01: /*
02: * Copyright 2002-2004 The Apache Software Foundation.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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;
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
31: .println("Usage: UddiPing business-name uddi-url");
32: System.exit(1);
33: }
34: searchUDDI(args[0], args[1]);
35: }
36:
37: public static void searchUDDI(String name, String url)
38: throws Exception {
39: // Create the connection and the message factory.
40: SOAPConnectionFactory scf = SOAPConnectionFactory.newInstance();
41: SOAPConnection connection = scf.createConnection();
42: MessageFactory msgFactory = MessageFactory.newInstance();
43:
44: // Create a message
45: SOAPMessage msg = msgFactory.createMessage();
46:
47: // Create an envelope in the message
48: SOAPEnvelope envelope = msg.getSOAPPart().getEnvelope();
49:
50: // Get hold of the the body
51: SOAPBody body = envelope.getBody();
52:
53: javax.xml.soap.SOAPBodyElement bodyElement = body
54: .addBodyElement(envelope.createName("find_business",
55: "", "urn:uddi-org:api"));
56:
57: bodyElement.addAttribute(envelope.createName("generic"), "1.0")
58: .addAttribute(envelope.createName("maxRows"), "100")
59: .addChildElement("name").addTextNode(name);
60:
61: URLEndpoint endpoint = new URLEndpoint(url);
62: msg.saveChanges();
63:
64: SOAPMessage reply = connection.call(msg, endpoint);
65: //System.out.println("Received reply from: " + endpoint);
66: //reply.writeTo(System.out);
67: connection.close();
68: }
69: }
|