You are viewing a plain text version of this content. The canonical link for it is here.
Posted to soap-user@ws.apache.org by co...@kent.pnn.police.uk on 2002/08/01 15:43:08 UTC

Threaded Call object


Hi,
I have failed miserably to sort this out so I resort the the greater good   
    

      


;-)

I am trying to write a SOAP client that makes threaded RPC calls. The
works when I only inititate one thread but when I do two, the results of   
    

      


the Call.response always appear to be the same for each thread as if the   
    

      


Call object is global in scope and is being set to the last (or first)
thread Call.Response. If I run these as two separate clients (from
different DOS windows), they return different results - but still the
same for each internal Thread, so I don't think it is a server threading   
    

      


problem i.e. my rpc method that is being called isn't the problem but I   
    

      


am willing to be persuaded otherwise!

Can anyone help?????
Thanks
Conrad

Here is my code...

public class sSearch extends Thread {

 public static Document doc = new org.apache.xerces.dom.DocumentImpl();
 public static Document doc1 = new org.apache.xerces.dom.DocumentImpl();
 public static DocumentBuilderFactory factory;
 public static DocumentBuilder builder;
 public static Document doc_res;
 public static Element res;
 public static String str_test;
     


 public static URL url;
 public static Element e_q;
     


 public sSearch(Element e) throws MalformedURLException {
  this.e_q = e;
  this.url = new URL("http://...");
 }
     


 public void run() {
  try {
  Call call = new Call();
  call.setEncodingStyleURI(Constants.NS_URI_LITERAL_XML);
  call.setTargetObjectURI("urn:single-midas-search");
  call.setMethodName("getSearch");

  Vector params = new Vector();
  params.addElement(new Parameter("query", Element.class, e_q, null));
  call.setParams(params);
      


  Response response;
  response = call.invoke(url, "");
  if (!response.generatedFault()) {
   System.out.println("Search done");
   Parameter returnValue = response.getReturnValue();
   Element r = (Element) returnValue.getValue();
   System.out.println("importing stuff" + this.getName());
   Element e_temp_toappend = (Element) doc_res.importNode(r, true);
   res.appendChild(e_temp_toappend);

TransformerFactory t_factory = TransformerFactory.newInstance();
Transformer transformer = t_factory.newTransformer();
transformer.transform(new DOMSource(res), new StreamResult(System.out));

  } else {
   Fault fault = response.getFault();
   System.out.println("Error searching: " + fault.getFaultString());
  }
  } catch (SOAPException e) {
   System.out.println("A SOAP exception has occured");
   e.printStackTrace();
  } catch (Exception e) {
   System.out.println("A some exception has occured (not soap)");
   e.printStackTrace();
  }
 }

 public static void main (String [] args) {
  if (args.length != 3) {
   System.out.println("Usage: java sSearch [\"dbname\"] [\"surname\"]
[\"forename\"]");
   return;
  }

  try {
   factory = DocumentBuilderFactory.newInstance();
   builder = factory.newDocumentBuilder();
   doc_res = builder.newDocument();
   res = doc_res.createElement("all-results");
   str_test = "";

   String db = args[0];
   String surname = args[1];
   String forename = args[2];
       


   Element e_query = doc.createElement("query");
   Element e_terms = doc.createElement("search-terms");
       


   // create a new hit element
   Element e_database = doc.createElement("database");
   Element e_surname = doc.createElement("surname");
   Element e_forename = doc.createElement("forename");
   Element e_hits = doc.createElement("hits");
   Element e_force_number = doc.createElement("force_number");
       


   // create a new Text node attribute
   Text t_database = doc.createTextNode("stop_search.nsf");
   e_database.setAttribute("name", "stop_search.nsf");

   // append the text element to the database element
   e_database.appendChild(t_database);
        


   // append to query
   e_query.appendChild(e_database);
       


   Text t_surname = doc.createTextNode(surname);
   e_surname.appendChild(t_surname);
   e_terms.appendChild(e_surname);

   Text t_forename = doc.createTextNode(forename);
   e_forename.appendChild(t_forename);
   e_terms.appendChild(e_forename);

   Text t_hits = doc.createTextNode("20");
   e_hits.appendChild(t_hits);
   e_terms.appendChild(e_hits);

   e_query.appendChild(e_terms);

   Element e_query1 = doc1.createElement("query");
   Element e_terms1 = doc1.createElement("search-terms");
       


   // create a new hit element
   Element e_database1 = doc1.createElement("database");
   Element e_surname1 = doc1.createElement("surname");
   Element e_forename1 = doc1.createElement("forename");
   Element e_hits1 = doc1.createElement("hits");
   Element e_force_number1 = doc1.createElement("force_number");
       


   // create a new Text node attribute
   Text t_database1 = doc1.createTextNode("war_live.nsf");
   e_database1.setAttribute("name", "war_live.nsf");

   // append the text element to the database element
   e_database1.appendChild(t_database1);
        


   // append to query
   e_query1.appendChild(e_database1);
       


   Text t_surname1 = doc1.createTextNode(surname);
   e_surname1.appendChild(t_surname1);
   e_terms1.appendChild(e_surname1);
   Text t_forename1 = doc1.createTextNode(forename);
   e_forename1.appendChild(t_forename1);
   e_terms1.appendChild(e_forename1);
   Text t_hits1 = doc1.createTextNode("20");
   e_hits1.appendChild(t_hits1);
   e_terms1.appendChild(e_hits1);
   e_query1.appendChild(e_terms1);

   sSearch s = new sSearch(e_query);
   s.setName("stopsearch");
   s.start();
   sSearch s1 = new sSearch(e_query1);
   s1.setName("warrants");
   s1.start();

   s.join();
   s1.join();

/*
TransformerFactory t_factory = TransformerFactory.newInstance();
Transformer transformer = t_factory.newTransformer();
transformer.transform(new DOMSource(res), new StreamResult(System.out));
*/
  } catch (Exception e) {
   e.printStackTrace();
  }
 }
}

Conrad Crampton J
Internal Developments
Kent County Constabulary
11 Edinburgh Square
Sutton Road
Maidstone
Kent
ME15 9BZ
(01622 652869 (internal: 19 2869)