1 8 9 package org.uddi4j.transport; 10 11 import java.net.URL ; 12 import java.util.Vector ; 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 ; 20 21 27 public class ApacheSOAPTransport extends TransportBase { 28 29 private boolean debug = false; 30 private SOAPHTTPConnection connection; 31 32 35 public ApacheSOAPTransport() throws TransportException { 36 connection = new SOAPHTTPConnection(); 37 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 connection.setUserName(System.getProperty("http.basicAuthUserName")); 45 connection.setPassword(System.getProperty("http.basicAuthPassword")); 46 47 String proxyPortString = System.getProperty("http.proxyPort"); 48 if (proxyPortString!=null) { 49 try { 50 connection.setProxyPort(new Integer (proxyPortString).intValue()); 51 } catch (Exception e) { 52 } 53 } 54 55 } 56 57 58 67 public Element send(Element el, URL url) throws TransportException { 68 debug = logEnabled(); 69 70 Envelope sendEnv = new Envelope(); 71 Body sendBody = new Body(); 72 73 Vector bodyEntry = new Vector (); 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 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 ) responseBody.getBodyEntries().firstElement(); 95 if (debug) { 96 System.err.println( 97 "\nResponse body:\n" + DOMWriter.nodeToString(base)); 98 } 99 } catch (Exception e) { 100 throw new TransportException(e); 101 } 102 103 return base; 104 } 105 } 106 | Popular Tags |