1 8 9 package org.uddi4j.transport; 10 11 import java.io.ByteArrayInputStream ; 12 import java.io.IOException ; 13 import java.net.URL ; 14 import java.util.Properties ; 15 import java.util.Vector ; 16 import javax.xml.parsers.DocumentBuilder ; 17 import javax.xml.parsers.DocumentBuilderFactory ; 18 import javax.xml.parsers.ParserConfigurationException ; 19 20 import org.apache.axis.AxisFault; 21 import org.apache.axis.Message; 22 import org.apache.axis.client.Call; 23 import org.apache.axis.client.Service; 24 import org.apache.axis.message.SOAPBodyElement; 25 import org.w3c.dom.Document ; 26 import org.w3c.dom.Element ; 27 import org.xml.sax.SAXException ; 28 29 40 public class ApacheAxisTransport extends TransportBase { 41 50 public Element send(Element el, URL url) throws TransportException { 51 52 Element base = null; 53 boolean debug = logEnabled(); 54 Call call = null; 55 56 try { 57 Service service = new Service(); 58 call = (Call) service.createCall(); 59 60 call.setUsername(System.getProperty("http.basicAuthUserName")); 61 call.setPassword(System.getProperty("http.basicAuthPassword")); 62 63 call.setTargetEndpointAddress(url); 64 66 Vector result = null; 67 68 String str = null; 72 73 str = org.apache.axis.utils.XMLUtils.ElementToString(el); 74 SOAPBodyElement body = 75 new SOAPBodyElement( 76 new java.io.ByteArrayInputStream (str.getBytes())); 77 78 81 Object [] params = new Object [] { body }; 82 83 if (debug) { 84 System.err.println("\nRequest message:\n" + params[0]); 85 } 86 87 result = (Vector ) call.invoke(params); 88 89 base = stringToElement(((SOAPBodyElement) result.elementAt(0)).toString()); 90 } catch (AxisFault fault) { 91 try { 92 Message m = call.getResponseMessage(); 93 base = stringToElement(m.getSOAPEnvelope().getFirstBody().toString()); 94 } catch (Exception e) { 95 throw new TransportException(e); 96 } 97 } catch (Exception e) { 98 throw new TransportException(e); 99 } 100 if (debug && base != null) { 101 System.err.println( 102 "\nResponse message:\n" 103 + org.apache.axis.utils.XMLUtils.ElementToString(base)); 104 } 105 106 return base; 107 } 108 109 public Element stringToElement(String s) throws ParserConfigurationException , IOException , SAXException { 110 DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); 111 docBuilderFactory.setNamespaceAware(true); 112 DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder(); 113 Document doc = docBuilder.parse(new ByteArrayInputStream (s.getBytes())); 114 return doc.getDocumentElement(); 115 } 116 117 } 118 | Popular Tags |