1 16 package org.apache.juddi.proxy; 17 18 import java.io.ByteArrayInputStream ; 19 import java.net.URL ; 20 import java.util.Vector ; 21 22 import org.apache.axis.AxisFault; 23 import org.apache.axis.Message; 24 import org.apache.axis.client.Call; 25 import org.apache.axis.client.Service; 26 import org.apache.axis.message.SOAPBodyElement; 27 import org.apache.axis.utils.XMLUtils; 28 import org.apache.commons.logging.Log; 29 import org.apache.commons.logging.LogFactory; 30 import org.apache.juddi.error.RegistryException; 31 import org.w3c.dom.Element ; 32 33 36 public class AxisTransport implements Transport 37 { 38 private static Log log = LogFactory.getLog(AxisTransport.class); 40 41 public Element send(Element request,URL endpointURL) 42 throws RegistryException 43 { 44 Service service = null; 45 Call call = null; 46 Element response = null; 47 48 log.debug("\nRequest message:\n" + XMLUtils.ElementToString(request)); 49 50 try { 51 service = new Service(); 52 call = (Call)service.createCall(); 53 call.setTargetEndpointAddress(endpointURL); 54 55 String requestString = XMLUtils.ElementToString(request); 56 SOAPBodyElement body = new SOAPBodyElement(new ByteArrayInputStream (requestString.getBytes("UTF-8"))); 57 Object [] soapBodies = new Object [] { body }; 58 59 Vector result = (Vector )call.invoke(soapBodies); 60 response = ((SOAPBodyElement)result.elementAt(0)).getAsDOM(); 61 } 62 catch (AxisFault fault) { 63 64 fault.printStackTrace(); 65 66 try { 67 Message msg = call.getResponseMessage(); 68 response = msg.getSOAPEnvelope().getFirstBody().getAsDOM(); 69 } 70 catch (Exception ex) { 71 throw new RegistryException(ex); 72 } 73 } 74 catch (Exception ex) { 75 throw new RegistryException(ex); 76 } 77 78 log.debug("\nResponse message:\n" + XMLUtils.ElementToString(response)); 79 80 81 return response; 82 } 83 84 public String send(String request,URL endpointURL) 85 throws RegistryException 86 { 87 Service service = null; 88 Call call = null; 89 String response = null; 90 91 log.debug("\nRequest message:\n" + request); 92 93 try { 94 95 service = new Service(); 96 call = (Call)service.createCall(); 97 call.setTargetEndpointAddress(endpointURL); 98 99 SOAPBodyElement body = new SOAPBodyElement(new ByteArrayInputStream (request.getBytes("UTF-8"))); 100 Object [] soapBodies = new Object [] { body }; 101 102 Vector result = (Vector )call.invoke(soapBodies); 103 response = ((SOAPBodyElement)result.elementAt(0)).getAsString(); 104 } 105 catch (AxisFault fault) { 106 107 fault.printStackTrace(); 108 109 try { 110 Message msg = call.getResponseMessage(); 111 response = msg.getSOAPEnvelope().getFirstBody().getAsString(); 112 } 113 catch (Exception ex) { 114 throw new RegistryException(ex); 115 } 116 } 117 catch (Exception ex) { 118 throw new RegistryException(ex); 119 } 120 121 log.debug("\nResponse message:\n" + response); 122 123 return response; 124 } 125 } 126 | Popular Tags |