/** * Creates an instance bound to url. If <code>acceptDeflate</code> is true then HTTP Request * headers will indicate to servers that this client can accept compressed documents. * * @param urlString Connect to this URL. * @param acceptCompress true if this client will accept compressed responses * @throws FileNotFoundException thrown if <code>urlString</code> is not a valid URL, or a * filename which exists on the system. */ public DConnect2(String urlString, boolean acceptCompress) throws FileNotFoundException { int ceIndex = urlString.indexOf('?'); if (ceIndex != -1) { this.urlString = urlString.substring(0, ceIndex); String expr = urlString.substring(ceIndex); int selIndex = expr.indexOf('&'); if (selIndex != -1) { this.projString = expr.substring(0, selIndex); this.selString = expr.substring(selIndex); } else { this.projString = expr; this.selString = ""; } } else { this.urlString = urlString; this.projString = this.selString = ""; } this.acceptCompress = acceptCompress; // capture encoded url this.urlStringEncoded = EscapeStrings.escapeURL(this.urlString); // Check out the URL to see if it is file:// try { URL testURL = new URL(urlString); if ("file".equals(testURL.getProtocol())) { filePath = testURL.getPath(); // See if .dds and .dods files exist File f = new File(filePath + ".dds"); if (!f.canRead()) { throw new FileNotFoundException("file not readable: " + urlString + ".dds"); } f = new File(filePath + ".dods"); if (!f.canRead()) { throw new FileNotFoundException("file not readable: " + urlString + ".dods"); } } /* Set the server version cause we won't get it from anywhere */ ver = new ServerVersion(ServerVersion.DAP2_PROTOCOL_VERSION, ServerVersion.XDAP); } catch (DAP2Exception ex) { throw new FileNotFoundException("Cannot set server version"); } catch (MalformedURLException e) { throw new FileNotFoundException("Malformed URL: " + urlString); } }
/** * Returns the DAS object from the dataset referenced by this object's URL. The DAS object is * referred to by appending `.das' to the end of a DODS URL. * * @return the DAS associated with the referenced dataset. * @throws MalformedURLException if the URL given to the constructor has an error * @throws IOException if an error connecting to the remote server * @throws ParseException if the DAS parser returned an error * @throws DASException on an error constructing the DAS * @throws DAP2Exception if an error returned by the remote server */ public DAS getDAS() throws IOException, ParseException, DAP2Exception { DASCommand command = new DASCommand(); if (filePath != null) { // url was file: File daspath = new File(filePath + ".das"); // See if the das file exists if (daspath.canRead()) { command.process(new FileInputStream(daspath)); } } else if (stream != null) { command.process(stream); } else { // assume url is remote try { openConnection(urlStringEncoded + ".das" + projString + selString, command); } catch (DAP2Exception de) { // if(de.getErrorCode() != DAP2Exception.NO_SUCH_FILE) // throw de; // rethrow } } return command.das; }
/** * Returns the `Data object' from the dataset referenced by this object's URL given the constraint * expression CE. Note that the Data object is really just a DDS object with data bound to the * variables. The DDS will probably contain fewer variables (and those might have different types) * than in the DDS returned by getDDS() because that method returns the entire DDS (but without * any data) while this method returns only those variables listed in the projection part of the * constraint expression. * * <p>Note that if CE is an empty String then the entire dataset will be returned, unless a * "sticky" CE has been specified in the constructor. * * @param CE The constraint expression to be applied to this request by the server. This is * combined with any CE given in the constructor. * @param statusUI the <code>StatusUI</code> object to use for GUI updates and user cancellation * notification (may be null). * @param btf The <code>BaseTypeFactory</code> to build the member variables in the DDS with. * @return The <code>DataDDS</code> object that results from applying the given CE, combined with * this object's sticky CE, on the referenced dataset. * @throws MalformedURLException if the URL given to the constructor has an error * @throws IOException if any error connecting to the remote server * @throws ParseException if the DDS parser returned an error * @throws DDSException on an error constructing the DDS * @throws DAP2Exception if any error returned by the remote server */ public DataDDS getData(String CE, StatusUI statusUI, BaseTypeFactory btf) throws MalformedURLException, IOException, ParseException, DDSException, DAP2Exception { DataDDS dds = new DataDDS(ver, btf); DataDDSCommand command = new DataDDSCommand(dds, statusUI); command.setURL(urlString + "?" + CE); if (filePath != null) { // url is file: File dodspath = new File(filePath + ".dods"); // See if the dods file exists if (dodspath.canRead()) { /* WARNING: any constraints are ignored in reading the file */ command.process(new FileInputStream(dodspath)); } } else if (stream != null) { command.process(stream); } else { String urls = urlStringEncoded + ".dods" + EscapeStrings.escapeURLQuery(getCompleteCE(CE)); openConnection(urls, command); } return command.dds; }
public void init() throws ServletException { final String CONFIG_PATH = getServletContext().getRealPath("/") + "config.ini"; final String APPLICATION_NAME = getServletContext().getServletContextName(); BasicConfigurator.configure(); FileInputStream config_file = null; File config = new File(CONFIG_PATH); if (config.canRead()) { log.debug("Parsing " + CONFIG_PATH); try { config_file = new FileInputStream(CONFIG_PATH); } catch (java.io.FileNotFoundException e) { throw new ServletException(e); } Properties config_prop = new Properties(); try { config_prop.load(config_file); } catch (java.io.IOException e) { throw new ServletException(e); } this.config = config_prop; log.debug("Parsing finished"); } else { log.fatal("Error, cannot read " + CONFIG_PATH); } log.debug("maximumRecords : " + this.config.getProperty("default_maximumRecords")); log.debug("srw_header_file: " + this.config.getProperty("srw_header_file")); log.debug("srw_diag: " + this.config.getProperty("srw_diag_file")); // log.debug("server_list: " + this.config.getProperty("server_list")); try { FileReader fis = new FileReader( getServletContext().getRealPath("/") + this.config.getProperty("srw_header_file")); BufferedReader in1 = new BufferedReader(fis); fis = new FileReader( getServletContext().getRealPath("/") + this.config.getProperty("srw_footer_file")); BufferedReader in2 = new BufferedReader(fis); fis = new FileReader( getServletContext().getRealPath("/") + this.config.getProperty("srw_diag_file")); BufferedReader in3 = new BufferedReader(fis); try { String line = null; while ((line = in1.readLine()) != null) { this.SRW_HEADER = this.SRW_HEADER + line; } while ((line = in2.readLine()) != null) { this.SRW_FOOTER = this.SRW_FOOTER + line; } while ((line = in3.readLine()) != null) { this.SRW_DIAG = this.SRW_DIAG + line; } } finally { in1.close(); in2.close(); in3.close(); } } catch (IOException ex) { ex.printStackTrace(); } }