| 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; |
| 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 |
// Create the connection and the message factory. |
| 38 |
SOAPConnectionFactory scf = SOAPConnectionFactory.newInstance(); |
| 39 |
SOAPConnection connection = scf.createConnection(); |
| 40 |
MessageFactory msgFactory = MessageFactory.newInstance(); |
| 41 |
|
| 42 |
// Create a message |
| 43 |
SOAPMessage msg = msgFactory.createMessage(); |
| 44 |
|
| 45 |
// Create an envelope in the message |
| 46 |
SOAPEnvelope envelope = msg.getSOAPPart().getEnvelope(); |
| 47 |
|
| 48 |
// Get hold of the the body |
| 49 |
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 |
//System.out.println("Received reply from: " + endpoint); |
| 64 |
//reply.writeTo(System.out); |
| 65 |
connection.close(); |
| 66 |
} |
| 67 |
} |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|