title: Iterating through SOAP requests from a properties file
body: <p>I am writing a java plugin that I plan to use to test a number of web services. These SOAPs for the web services are located in a properties file, and are grouped under which WSDL they fall under (Subscriber, Network, User, etc...). Also, there are some regexs associated with each web service to test the response against.</p>
  
  <p><code>Properties Example</code></p>
  
  <pre><code>#Web services to be tested and regexes to test responses
   #List of web service groups used (WSDLs)
   webservice.list = SubscriberMgmt,NetworkMgmt
  
   # &lt; -- SubscriberMgmt -- &gt;
   #getSubscriberDevices
   webservice.subscriber = &lt;soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://ws.blah.blah.com"&gt;&lt;soapenv:Header/&gt;&lt;soapenv:Body&gt;&lt;ws:getSubscriberDevices&gt;&lt;PhoneNumber&gt;&lt;/PhoneNumber&gt;&lt;LastName&gt;&lt;/LastName&gt;&lt;MACAddress&gt;&lt;/MACAddress&gt;&lt;ExternalId&gt;&lt;/ExternalId&gt;&lt;AccountExternalId&gt;john&lt;/AccountExternalId&gt;&lt;IPAddress&gt;&lt;/IPAddress&gt;&lt;/ws:getSubscriberDevices&gt;&lt;/soapenv:Body&gt;&lt;/soapenv:Envelope&gt;
   webservice.SubscriberMgmt.regex = subscriberId="(.+?)"
   webservice.SubscriberMgmt.regex.1 = externalId="(.+?)"
  
   #getMpegResultsById
   webservice.subscriber.1 = &lt;soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://ws.blah.blah.com"&gt;&lt;soapenv:Header/&gt;&lt;soapenv:Body&gt;&lt;ws:getMpegResultsById&gt;&lt;SubscriberId&gt;100016&lt;/SubscriberId&gt;&lt;Duration&gt;2880&lt;/Duration&gt;&lt;/ws:getMpegResultsById&gt;&lt;/soapenv:Body&gt;&lt;/soapenv:Envelope&gt; 
   webservice.SubscriberMgmt.1.regex = id="(.+?)"
   webservice.SubscriberMgmt.1.regex.1 = externalId="(.+?)"
  </code></pre>
  
  <p>I currently have code to connect using each WSDL from the properties file, so say when the 'webservicegroup' variable is SubscriberMgmt, I'd like to test the .subscriber web service(s) and check the responses if it contains the corresponding regex(es). (the 'data' variable only corresponds to one SOAP request from the property file at the moment)</p>
  
  <pre><code>//Soap Request
          try
          {
              for(String webservicegroup : webserviceList)
              {
                  URL url = new URL("http://" + server + "/webservices/" + webservicegroup);
                  URLConnection conn = url.openConnection();
                  conn.setDoOutput(true);
                  conn.setRequestProperty("Content-type", "text/xml; charset=utf-8");
                  conn.setRequestProperty("SOAPAction", "\"\"");
                  String loginEnc = new BASE64Encoder().encodeBuffer((username + ":" + password).getBytes());
                  loginEnc = loginEnc.replaceAll("\n", "");
                  conn.setRequestProperty("Authorization", "Basic " + loginEnc);
                  conn.setConnectTimeout(timeout);
                  conn.setReadTimeout(timeout);
  
                  OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
  
                  //Send request
                  wr.write(data);
                  wr.flush();
                  wr.close();
                  BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
  
                  //Save response
                  String line;
  
                  while ((line = in.readLine()) != null)
                  {
                      response += line;
                  }
                  in.close();
              }
          }
  </code></pre>
  
  <p>Any ideas on the best way of doing this? Any help is greatly appreciated</p>