KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > uddi4j > transport > ApacheSOAPTransport


1 /*
2  * The source code contained herein is licensed under the IBM Public License
3  * Version 1.0, which has been approved by the Open Source Initiative.
4  * Copyright (C) 2001, International Business Machines Corporation
5  * All Rights Reserved.
6  *
7  */

8
9 package org.uddi4j.transport;
10
11 import java.net.URL JavaDoc;
12 import java.util.Vector JavaDoc;
13
14 import org.apache.soap.Body;
15 import org.apache.soap.Envelope;
16 import org.apache.soap.messaging.Message;
17 import org.apache.soap.transport.http.SOAPHTTPConnection;
18 import org.apache.soap.util.xml.DOMWriter;
19 import org.w3c.dom.Element JavaDoc;
20
21 /**
22  * Transport implementation for Apache SOAP stack.
23  *
24  * @author David Melgar (dmelgar@us.ibm.com)
25  * @author Ozzy (ozzy@hursley.ibm.com)
26  */

27 public class ApacheSOAPTransport extends TransportBase {
28
29     private boolean debug = false;
30     private SOAPHTTPConnection connection;
31
32     /**
33      * Default constructor
34     */

35     public ApacheSOAPTransport() throws TransportException {
36         connection = new SOAPHTTPConnection();
37         // Initialize variables based on system properties
38
connection = new SOAPHTTPConnection();
39         connection.setProxyHost(System.getProperty("http.proxyHost"));
40         connection.setProxyUserName(System.getProperty("http.proxyUserName"));
41         connection.setProxyPassword(System.getProperty("http.proxyPassword"));
42
43         //ADDED BY KJ
44
connection.setUserName(System.getProperty("http.basicAuthUserName"));
45         connection.setPassword(System.getProperty("http.basicAuthPassword"));
46
47         String JavaDoc proxyPortString = System.getProperty("http.proxyPort");
48         if (proxyPortString!=null) {
49              try {
50                     connection.setProxyPort(new Integer JavaDoc(proxyPortString).intValue());
51              } catch (Exception JavaDoc e) {
52              }
53         }
54         
55     }
56
57
58     /**
59      * Sends a Element to URL.
60      *
61      * @param el Element to send
62      * @param url Destination URL
63      * @return An element representing a XML DOM tree containing the UDDI response.
64      * @exception TransportException
65      * Thrown if a problem occurs during transmission
66      */

67     public Element JavaDoc send(Element JavaDoc el, URL JavaDoc url) throws TransportException {
68         debug = logEnabled();
69
70         Envelope sendEnv = new Envelope();
71         Body sendBody = new Body();
72
73         Vector JavaDoc bodyEntry = new Vector JavaDoc();
74         bodyEntry.add(el);
75         sendBody.setBodyEntries(bodyEntry);
76
77         sendEnv.setBody(sendBody);
78
79         Message soapMessage = new Message();
80
81         soapMessage.setSOAPTransport(connection);
82
83         Element JavaDoc base = null;
84
85         try {
86             if (debug) {
87                 System.err.println(
88                     "\nRequest body:\n" + DOMWriter.nodeToString(el));
89             }
90             soapMessage.send(url, "", sendEnv);
91             Envelope responseEnv = soapMessage.receiveEnvelope();
92
93             Body responseBody = responseEnv.getBody();
94             base = (Element JavaDoc) responseBody.getBodyEntries().firstElement();
95             if (debug) {
96                 System.err.println(
97                     "\nResponse body:\n" + DOMWriter.nodeToString(base));
98             }
99         } catch (Exception JavaDoc e) {
100             throw new TransportException(e);
101         }
102
103         return base;
104     }
105 }
106
Popular Tags