- Timestamp:
- 2005-05-16T11:02:50+12:00 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl3/src/java/org/greenstone/gsdl3/service/IViaSearch.java
r9273 r9874 2 2 3 3 // Greenstone classes 4 import org.greenstone.gdbm.*;5 4 import org.greenstone.gsdl3.util.*; 6 5 … … 14 13 import java.util.HashMap; 15 14 import java.io.File; 16 import java.io.InputStream;17 15 import java.io.BufferedReader; 18 import java.io.InputStreamReader;19 import java.io.IOException;20 import java.net.HttpURLConnection;21 import java.net.URLConnection;22 import java.net.URL;23 16 import java.net.Authenticator; 24 import java.net.MalformedURLException;25 17 26 18 /** 27 19 * 28 20 * @author <a href="mailto:[email protected]">Katherine Don</a> 29 * @version $Revision$ 30 * Modified by <a href="mailto:[email protected]">Chi-Yu Huang</a> 21 * @author <a href="mailto:[email protected]">Chi-Yu Huang</a> 31 22 */ 32 23 … … 109 100 String results_num = null; 110 101 String doc_ids = null; 102 BufferedReader reader = null; 111 103 try { 112 104 ///system.err.println("IViaSearch, sending "+url_string); 113 BufferedReader reader = makeConnection(url_string);105 reader = Misc.makeHttpConnection(url_string); 114 106 results_num = reader.readLine(); 115 107 doc_ids = reader.readLine(); 116 } catch (Exception e) { 117 System.err.println("IViaSearch.TextQuery Error: exception happened during query"); 118 e.printStackTrace(); 108 } catch (java.net.MalformedURLException e) { 109 GSXML.addError(this.doc, result, "Malformed URL: "+url_string); 110 return result; 111 } catch (java.io.IOException e) { 112 GSXML.addError(this.doc, result, "IOException during connection to "+url_string+": "+e.toString()); 119 113 return result; 120 114 } … … 124 118 } else { 125 119 System.err.println("IViaSearch.TextQuery Error: badly formatted results line: "+results_num); 120 GSXML.addError(this.doc, result, "Error: badly formatted result from IVia server: "+results_num); 126 121 return result; 127 122 } … … 130 125 } else { 131 126 System.err.println("IViaSearch.TextQuery Error: badly formatted docs line: "+doc_ids); 127 GSXML.addError(this.doc, result, "Error: badly formatted result from IVia server: "+doc_ids); 132 128 return result; 133 129 } … … 150 146 } 151 147 152 protected BufferedReader makeConnection(String url_string) {153 BufferedReader reader = null;154 try {155 URL url = new URL(url_string);156 HttpURLConnection connection = (HttpURLConnection)url.openConnection();157 InputStream input = connection.getInputStream();158 reader = new BufferedReader(new InputStreamReader(input));159 } catch (java.net.MalformedURLException e) {160 System.err.println("IViaSearch Error: Malformed URL: "+url_string);161 } catch (java.io.IOException e) {162 System.err.println("IViaSearch Error: An error occurred during IO to url "+url_string);163 }164 return reader;165 }166 148 167 149 /**
Note:
See TracChangeset
for help on using the changeset viewer.