Changeset 9505


Ignore:
Timestamp:
2005-03-30T14:17:32+12:00 (19 years ago)
Author:
kjdon
Message:

trying to use axis instead of apache SOAP

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/ant-install-branch/gsdl3/src/java/org/greenstone/gsdl3/comms/SOAPCommunicator.java

    r4035 r9505  
    2626import java.net.MalformedURLException;
    2727import 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;
     34import org.apache.axis.client.Call;
     35import org.apache.axis.client.Service;
     36import org.apache.axis.message.SOAPBodyElement;
     37import javax.xml.namespace.QName;
    3438
    3539import org.w3c.dom.Node;
     
    5761    public SOAPCommunicator() {
    5862   
    59     call_ = new Call();
     63
    6064    // Set Encoding Style to standard SOAP encoding
    6165    //call_.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
    6266    // set Encoding Style to use literal XML
    63     call_.setEncodingStyleURI(Constants.NS_URI_LITERAL_XML);
     67    //call_.setEncodingStyleURI(Constants.NS_URI_LITERAL_XML);
    6468    }
    6569       
    6670    public boolean configure(Element site_elem) {
    6771
     72   
    6873    String type = site_elem.getAttribute(GSXML.TYPE_ATT);
    6974    if (!type.equals(GSXML.COMM_TYPE_SOAP_JAVA)) {
     
    8186        return false;
    8287    }
    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    }
    86102    return true;
    87103    }
    88104
    89 
    90105    public Element process(Element message) {
    91 
     106   
    92107    NodeList requests = message.getElementsByTagName(GSXML.REQUEST_ELEM);
    93108    if (requests.getLength()==0) {
     
    95110        return null;
    96111    }
    97    
     112
    98113    // 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
    99114    // for now, use local_site_name_ as the flag.
     
    110125        }
    111126    }
     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    }
    112199    // else do nothing to the message, just pass it on
    113200   
     
    116203
    117204        // 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);
    122209                       
    123         Vector param_list = new Vector ();
    124         param_list.addElement (param);
    125         call_.setParams (param_list);
    126        
    127         //  Set the URL for the Web Service
    128         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_);
    129216       
    130217        // Invoke the Service
     
    167254    }
    168255    }
    169    
     256    */
    170257}
    171258
Note: See TracChangeset for help on using the changeset viewer.