Ignore:
Timestamp:
2005-05-03T09:49:20+12:00 (19 years ago)
Author:
kjdon
Message:

moved the makeConnetion to util.Misc, added error nodes to the result if there was an error

File:
1 edited

Legend:

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

    r9529 r9797  
    1313import java.util.HashMap;
    1414import java.io.File;
    15 import java.io.InputStream;
    1615import java.io.BufferedReader;
    17 import java.io.InputStreamReader;
    18 import java.io.IOException;
    19 import java.net.HttpURLConnection;
    20 import java.net.URLConnection;
    21 import java.net.URL;
    2216import java.net.Authenticator;
    23 import java.net.MalformedURLException;
    2417
    2518/**
     
    108101    String results_num = null;
    109102    String doc_ids = null;
     103    BufferedReader reader = null;
    110104    try {
    111105        ///system.err.println("IViaSearch, sending "+url_string);
    112         BufferedReader reader = makeConnection(url_string);
     106        reader = Misc.makeHttpConnection(url_string);
    113107        results_num = reader.readLine();
    114108        doc_ids = reader.readLine();
    115     } catch (Exception e) {
    116         System.err.println("IViaSearch.TextQuery Error: exception happened during query");
    117         e.printStackTrace();
     109    } catch (java.net.MalformedURLException e) {
     110        GSXML.addError(this.doc, result, "Malformed URL: "+url_string);
     111        return result;
     112    } catch (java.io.IOException e) {
     113        GSXML.addError(this.doc, result, "IOException during connection to "+url_string+": "+e.toString());
    118114        return result;
    119115    }
     
    123119    } else {
    124120        System.err.println("IViaSearch.TextQuery Error: badly formatted results line: "+results_num);
     121        GSXML.addError(this.doc, result, "Error: badly formatted result from IVia server: "+results_num);
    125122        return result;
    126123    }
     
    129126    } else {
    130127        System.err.println("IViaSearch.TextQuery Error: badly formatted docs line: "+doc_ids);
     128        GSXML.addError(this.doc, result, "Error: badly formatted result from IVia server: "+doc_ids);
    131129        return result;
    132130    }
     
    149147    }
    150148     
    151     protected BufferedReader makeConnection(String url_string) {
    152     BufferedReader reader = null;
    153     try {
    154         URL url = new URL(url_string);
    155         HttpURLConnection connection = (HttpURLConnection)url.openConnection();
    156         InputStream input = connection.getInputStream();
    157         reader = new BufferedReader(new InputStreamReader(input)); 
    158     } catch (java.net.MalformedURLException e) {
    159         System.err.println("IViaSearch Error: Malformed URL: "+url_string);
    160     } catch (java.io.IOException e) {
    161         System.err.println("IViaSearch Error: An error occurred during IO to url "+url_string);
    162     }
    163     return reader;
    164     }
    165149
    166150    /**
Note: See TracChangeset for help on using the changeset viewer.