[webservices] Problem in Java-WS library WaveformService stream method

Benjamin Sick benjamin.sick at geophys.uni-stuttgart.de
Fri Sep 5 02:36:44 PDT 2014


Hello,

there seems to be a bug in the WaveformService stream method.

Extending the waveform reading example from the tutorial to save the
response in a miniseed file results in a NullPointerException:

WaveformService waveFormService = serviceUtil.getWaveformService();
WaveformCriteria criteria = new WaveformCriteria();
criteria.add(network, station, location, channel, startDate, endDate);
FileOutputStream os = new FileOutputStream("test.mseed");
waveFormService.stream(os, criteria);
os.close();

The attached diff fixes the problem. However it looks like there is
unnecessary code duplication in the library. A preferable solution
IMHO would be to merge the methods fetch and stream.

Best Regards,
Benjamin Sick

-- 
Dipl.-Ing. Benjamin Sick
Institut für Geophysik
Universität Stuttgart

Email: benjamin.sick at geophys.uni-stuttgart.de
Website: http://www.geophys.uni-stuttgart.de/mitarbeiter/sick_benjamin.html
Phone: +49 711 685-87422
Fax: +49 711 685-87401
-------------- next part --------------
Index: WaveformService.java
===================================================================
--- WaveformService.java	(Revision 3895)
+++ WaveformService.java	(Arbeitskopie)
@@ -332,11 +332,21 @@
 		HttpURLConnection connection = null;
 		InputStream inputStream = null;
 		try {
-			connection = this.getConnection(new URL(this.baseUrl));
+			URL url = null;
+			if (this.authenticate) {
+				url = new URL(baseUrl + "queryauth");
+			} else {
+				url = new URL(baseUrl + "query");
+			}
+			connection = this.getConnection(url);
 
 			connection.setRequestProperty("Content-Type",
 					"application/x-www-form-urlencoded");
+			connection.setRequestMethod("POST");
 			connection.setDoOutput(true);
+			connection.setDoInput(true);
+			connection.setUseCaches(false);
+			connection.setAllowUserInteraction(false);
 			connection.connect();
 
 			OutputStream outputStream = connection.getOutputStream();


More information about the webservices mailing list