Changeset 9505
- Timestamp:
- 2005-03-30T14:17:32+12:00 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ant-install-branch/gsdl3/src/java/org/greenstone/gsdl3/comms/SOAPCommunicator.java
r4035 r9505 26 26 import java.net.MalformedURLException; 27 27 import java.util.Vector; 28 import org.apache.soap.SOAPException; 29 import org.apache.soap.Fault; 30 import org.apache.soap.Constants; 31 import org.apache.soap.rpc.Call; 32 import org.apache.soap.rpc.Parameter; 33 import org.apache.soap.rpc.Response; 28 // import org.apache.soap.SOAPException; 29 // import org.apache.soap.Fault; 30 // import org.apache.soap.Constants; 31 // import org.apache.soap.rpc.Call; 32 // import org.apache.soap.rpc.Parameter; 33 // import org.apache.soap.rpc.Response; 34 import org.apache.axis.client.Call; 35 import org.apache.axis.client.Service; 36 import org.apache.axis.message.SOAPBodyElement; 37 import javax.xml.namespace.QName; 34 38 35 39 import org.w3c.dom.Node; … … 57 61 public SOAPCommunicator() { 58 62 59 call_ = new Call(); 63 60 64 // Set Encoding Style to standard SOAP encoding 61 65 //call_.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC); 62 66 // set Encoding Style to use literal XML 63 call_.setEncodingStyleURI(Constants.NS_URI_LITERAL_XML);67 //call_.setEncodingStyleURI(Constants.NS_URI_LITERAL_XML); 64 68 } 65 69 66 70 public boolean configure(Element site_elem) { 67 71 72 68 73 String type = site_elem.getAttribute(GSXML.TYPE_ATT); 69 74 if (!type.equals(GSXML.COMM_TYPE_SOAP_JAVA)) { … … 81 86 return false; 82 87 } 83 call_.setTargetObjectURI(remote_site_name_); 84 call_.setMethodName("process"); 85 88 try { 89 Service service = new Service(); 90 call_ = (Call) service.createCall(); 91 92 //call_.setTargetObjectURI(remote_site_name_); 93 //call_.setMethodName("process"); 94 call_.setTargetEndpointAddress( new java.net.URL(remote_site_address_) ); 95 // call_.setOperationStyle(org.apache.axis.enum.Style.MESSAGE_STR); 96 //call_.setOperationUse(org.apache.axis.enum.Use.LITERAL_STR); 97 //call_.setOperationName(new QName("http://soapinterop.org/", "process")); 98 } catch (Exception e) { 99 System.err.println("SOAPCommunicator.configure() Error: Exception occurred "+e); 100 return false; 101 } 86 102 return true; 87 103 } 88 104 89 90 105 public Element process(Element message) { 91 106 92 107 NodeList requests = message.getElementsByTagName(GSXML.REQUEST_ELEM); 93 108 if (requests.getLength()==0) { … … 95 110 return null; 96 111 } 97 112 98 113 // if the communicator is part of a site, it needs to edit the to and from fields, otherwise it just passes the message on, as is 99 114 // for now, use local_site_name_ as the flag. … … 110 125 } 111 126 } 127 // else do nothing to the requests, just pass it on 128 129 // the soap impl needs a namespace for the top level element 130 Element message_to_send = message; 131 if (message.getNamespaceURI() == null) { 132 message_to_send = GSXML.duplicateWithNewNameNS(message.getOwnerDocument(), message, "gs3:"+message.getTagName(), "urn:foo", true); 133 //System.err.println("**"+new XMLConverter().getPrettyString(new_message)); 134 } 135 136 // do the soap query 137 Element result = null; 138 try { 139 SOAPBodyElement[] input = new SOAPBodyElement[1]; 140 input[0] = new SOAPBodyElement(message_to_send); 141 Vector output = (Vector) call_.invoke( input ); 142 SOAPBodyElement elem = (SOAPBodyElement) output.get(0); 143 result = elem.getAsDOM(); 144 } catch (Exception e) { 145 e.printStackTrace(); 146 return null; 147 } 148 149 if (local_site_name_ != null) {// have to modify the from field 150 151 NodeList responses = result.getElementsByTagName(GSXML.RESPONSE_ELEM); 152 for (int i=0;i<responses.getLength(); i++) { 153 Element e = (Element)responses.item(i); 154 String from = e.getAttribute(GSXML.FROM_ATT); 155 from = GSPath.prependLink(from, remote_site_name_); 156 e.setAttribute(GSXML.FROM_ATT, from); 157 } 158 } // else return as is 159 160 return result; 161 } 162 163 public static void main (String [] args) { 164 SOAPCommunicator comm = new SOAPCommunicator(); 165 XMLConverter converter = new XMLConverter(); 166 String message = "<site name=\"localsite\" address=\"http://kanuka.cs.waikato.ac.nz:7070/axis/services/localsite\" type=\"soap\"/>"; 167 Element site_elem = converter.getDOM(message).getDocumentElement(); 168 comm.configure(site_elem); 169 message = "<message><request type=\"describe\" to=\"\" lang=\"en\"/></message>"; 170 //message = "<message><request type=\"describe\" to=\"\" lang=\"en\"/></message>"; 171 Element request_elem = converter.getDOM(message).getDocumentElement(); 172 Element response = comm.process(request_elem); 173 174 System.err.println("response was "+converter.getPrettyString(response)); 175 } 176 /* 177 public Element process(Element message) { 178 179 NodeList requests = message.getElementsByTagName(GSXML.REQUEST_ELEM); 180 if (requests.getLength()==0) { 181 // no requests 182 return null; 183 } 184 185 // if the communicator is part of a site, it needs to edit the to and from fields, otherwise it just passes the message on, as is 186 // for now, use local_site_name_ as the flag. 187 if (local_site_name_!=null) { // no local site 188 189 for (int i=0;i<requests.getLength(); i++) { 190 Element e = (Element)requests.item(i); 191 String to = e.getAttribute(GSXML.TO_ATT); 192 to = GSPath.removeFirstLink(to); // remove the server name, should check that it is present 193 e.setAttribute(GSXML.TO_ATT, to); 194 String from = e.getAttribute(GSXML.FROM_ATT); 195 from = GSPath.appendLink(from, local_site_name_); 196 e.setAttribute(GSXML.FROM_ATT, from); 197 } 198 } 112 199 // else do nothing to the message, just pass it on 113 200 … … 116 203 117 204 // Set Method Parameters - use literal xml 118 Parameter param = new Parameter("xml_in",119 org.w3c.dom.Element.class,120 message,121 Constants.NS_URI_LITERAL_XML);205 // Parameter param = new Parameter("xml_in", 206 // org.w3c.dom.Element.class, 207 // message, 208 // Constants.NS_URI_LITERAL_XML); 122 209 123 Vector param_list = new Vector ();124 param_list.addElement (param);125 call_.setParams (param_list);126 127 // Set the URL for the Web Service128 URL url = new URL(remote_site_address_);210 // Vector param_list = new Vector (); 211 // param_list.addElement (param); 212 // call_.setParams (param_list); 213 214 // // Set the URL for the Web Service 215 // URL url = new URL(remote_site_address_); 129 216 130 217 // Invoke the Service … … 167 254 } 168 255 } 169 256 */ 170 257 } 171 258
Note:
See TracChangeset
for help on using the changeset viewer.