Ignore:
Timestamp:
2005-05-04T16:12:38+12:00 (19 years ago)
Author:
kjdon
Message:

makeConnection moved to Misc, some methods now throw GSExceptions

File:
1 edited

Legend:

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

    r9798 r9813  
    22
    33// Greenstone classes
     4import org.greenstone.gsdl3.core.GSException;
    45import org.greenstone.gsdl3.util.*;
    56
     
    6061       
    6162    /** gets a document by sending a request to iVia, then processes it and creates a documentNode around the text */
    62     protected Element getNodeContent(String doc_id) {
     63    protected Element getNodeContent(String doc_id)
     64    throws GSException {
    6365
    6466    String url_string = ivia_server_url+"/cgi-bin/view_record?theme=gsdl3&record_id="+doc_id;
     
    6668    StringBuffer buffer = new StringBuffer();
    6769    try {
    68         BufferedReader reader = makeConnection(url_string);
     70        BufferedReader reader = Misc.makeHttpConnection(url_string);
    6971            String line;
    7072        while((line = reader.readLine())!= null) {
    7173        buffer.append(line);
    7274        }
    73     } catch (Exception e) {
    74         System.err.println("IViaRetrieve Error:exception happened");
    75         e.printStackTrace();
    76     }
    77    
     75    } catch (java.net.MalformedURLException e) {
     76        throw new GSException("Malformed URL: "+url_string, GSXML.ERROR_TYPE_SYSTEM);
     77    } catch (java.io.IOException e) {
     78        throw new GSException("IOException during connection to "+url_string+": "+e.toString(),GSXML.ERROR_TYPE_SYSTEM);
     79    }
     80
    7881    String node_content = buffer.toString();
    7982
     
    175178    }
    176179
    177     protected BufferedReader makeConnection(String url_string) {
    178     BufferedReader reader = null;
    179     try {
    180         URL url = new URL(url_string);
    181         HttpURLConnection connection = (HttpURLConnection)url.openConnection();
    182         InputStream input = connection.getInputStream();
    183         reader = new BufferedReader(new InputStreamReader(input)); 
    184     } catch (java.net.MalformedURLException e) {
    185         System.err.println("IViaRetrieve: Malformed URL: "+url_string);
    186     } catch (java.io.IOException e) {
    187         System.err.println("IViaRetrieve Error: An error occurred during IO to url "+url_string);
    188     }
    189     return reader;
    190     }
    191 
    192180    protected String translateId(String oid){
    193181    int p = oid.lastIndexOf('.');
     
    221209    protected Element getMetadataList (String doc_id,
    222210                       boolean all_metadata,
    223                        ArrayList metadata_names){
     211                       ArrayList metadata_names)
     212    throws GSException {
    224213   
    225214    Element meta_list = this.doc.createElement(GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER);
     
    242231    String url_string = ivia_server_url+"/cgi-bin/view_record_set?theme=gsdl3&record_id_list="+doc_id+"&field_list="+field_list.toString();
    243232    try {
    244         BufferedReader reader = makeConnection(url_string);
     233        BufferedReader reader = Misc.makeHttpConnection(url_string);
    245234        String line;
    246235        while  ((line = reader.readLine()) != null) {
     
    255244        GSXML.addMetadata(this.doc, meta_list, name, value);
    256245        }
    257     } catch (Exception e) {
    258         System.err.println("IViaRetrieve Error:exception happened");
    259         e.printStackTrace();
     246    } catch (java.net.MalformedURLException e) {
     247        throw new GSException("Malformed URL: "+url_string, GSXML.ERROR_TYPE_SYSTEM);
     248    } catch (java.io.IOException e) {
     249        throw new GSException("IOException: "+e.toString(), GSXML.ERROR_TYPE_SYSTEM);
    260250    }
    261251    return meta_list;
Note: See TracChangeset for help on using the changeset viewer.