Package org.archive.wayback.exception

Examples of org.archive.wayback.exception.ResourceNotAvailableException


    long offset = resultToOffset(result);
    File file = getLocalFile(fileName);
    if (file == null) {
     
      // TODO: this needs to be prettied up for end user consumption..
      throw new ResourceNotAvailableException("Cannot find ARC file ("
          + fileName + ")");
    } else {

      Resource r = ResourceFactory.getResource(file, offset);
      return r;
View Full Code Here


      r = ResourceFactory.getResource(new URL(fileUrl), offset);

    } catch (IOException e) {

      e.printStackTrace();
      throw new ResourceNotAvailableException("Unable to retrieve",
          e.getLocalizedMessage());
    }
    return r;
  }
View Full Code Here

      WARCReader reader = WARCReaderFactory.get(file,offset);
      r = WARCArchiveRecordToResource(reader.get(),reader);

    } else {
      throw new ResourceNotAvailableException("Unknown extension");
    }

    return r;
  }
View Full Code Here

      WARCReader reader = WARCReaderFactory.get(url, offset);
      r = WARCArchiveRecordToResource(reader.get(),reader);

    } else {
      throw new ResourceNotAvailableException("Unknown extension");
    }
    return r;
  }
View Full Code Here

 
  private static Resource ARCArchiveRecordToResource(ArchiveRecord rec,
      ARCReader reader) throws ResourceNotAvailableException, IOException {

    if (!(rec instanceof ARCRecord)) {
      throw new ResourceNotAvailableException("Bad ARCRecord format");
    }
    ArcResource ar = new ArcResource((ARCRecord) rec, reader);
    ar.parseHeaders();
    return ar;
  }
View Full Code Here

  private static Resource WARCArchiveRecordToResource(ArchiveRecord rec,
      WARCReader reader) throws ResourceNotAvailableException, IOException {

    if (!(rec instanceof WARCRecord)) {
      throw new ResourceNotAvailableException("Bad WARCRecord format");
    }
    WarcResource wr = new WarcResource((WARCRecord) rec, reader);
    wr.parseHeaders();
    return wr;
  }
View Full Code Here

  throws IOException, ServletException {
    Resource resource = null;
    try {
      SearchResults results = collection.getResourceIndex().query(wbRequest);
      if(!(results instanceof CaptureSearchResults)) {
        throw new ResourceNotAvailableException("Bad results...");
      }
      CaptureSearchResults captureResults = (CaptureSearchResults) results;
 
      // TODO: check which versions are actually accessible right now?
      SearchResult closest = captureResults.getClosest(wbRequest);
View Full Code Here

  public Resource retrieveResource(CaptureSearchResult result)
    throws ResourceNotAvailableException {
   
    String fileName = result.getFile();
    if(fileName == null || fileName.length() < 1) {
      throw new ResourceNotAvailableException("No ARC/WARC name in search result...", fileName);
    }

    if(!fileName.endsWith(ArcWarcFilenameFilter.ARC_SUFFIX)
        && !fileName.endsWith(ArcWarcFilenameFilter.ARC_GZ_SUFFIX)
        && !fileName.endsWith(ArcWarcFilenameFilter.WARC_SUFFIX)
        && !fileName.endsWith(ArcWarcFilenameFilter.WARC_GZ_SUFFIX)) {
      fileName = fileName + ArcWarcFilenameFilter.ARC_GZ_SUFFIX;
    }
   
    String errMsg = "";
    Exception origException = null;

    for ( ResourceStore store : stores ) {
      try {
        Resource r = store.retrieveResource(result);

        if ( r != null ) {
          return r;
        }
       
      } catch (ResourceNotAvailableException e) {       
        LOGGER.info(e.toString());
        if (!errMsg.isEmpty()) {
          errMsg += " ";
        }
        origException = e;
        errMsg += e.getMessage();
       
        // if skipOnUnavailable, then don't try any more resource stores if the current one is unavailable
        if (failOnFirstUnavailable && (e.getStatus() == HttpServletResponse.SC_SERVICE_UNAVAILABLE)) {
          break;
        }
      }
    }

    throw new ResourceNotAvailableException(errMsg.isEmpty() ? "Unable to retrieve: "+fileName : errMsg, fileName, origException);
  }
View Full Code Here

    throws ResourceNotAvailableException {

    // extract ARC filename
    String fileName = result.getFile();
    if(fileName == null || fileName.length() < 1) {
      throw new ResourceNotAvailableException("No ARC/WARC name in search result...", fileName);
    }
   
        // If includeFilter is provided, filter out paths that don't contain the include filter
        if (includeFilter != null) {
          if (!fileName.contains(includeFilter)) {
            throw new ResourceNotAvailableException("Resource " + fileName + " not found in this store", fileName);
          }
        }   

    final long offset = result.getOffset();
    if(!fileName.endsWith(ArcWarcFilenameFilter.ARC_SUFFIX)
        && !fileName.endsWith(ArcWarcFilenameFilter.ARC_GZ_SUFFIX)
        && !fileName.endsWith(ArcWarcFilenameFilter.WARC_SUFFIX)
        && !fileName.endsWith(ArcWarcFilenameFilter.WARC_GZ_SUFFIX)) {
      fileName = fileName + ArcWarcFilenameFilter.ARC_GZ_SUFFIX;
    }
       
        String fileUrl;
        if ( regex != null && replace != null )
          {
            fileUrl = fileName.replaceAll( regex, replace );
          }
        else
          {
            fileUrl = prefix + fileName;
          }
       
    Resource r = null;
    try {
      int attempts = retries;
          while(attempts-- > 0) {
            try {
              r = ResourceFactory.getResource(fileUrl, offset);
              break;
            } catch (IOException e) {
              String message = e.getMessage();
              if(attempts > 0
                  && message.contains(HTTP_ERROR)
                  && message.contains(HTTP_502)) {
               
                LOGGER.info(String.format(
                    "Failed attempt for (%s) retrying with" +
                    " (%d) attempts left",fileUrl,attempts));
              } else {
                throw e;
              }
            }
          }

    } catch (IOException e) {
      String msg = fileUrl + " - " + e;
      LOGGER.info("Unable to retrieve:" + msg);
     
      throw new ResourceNotAvailableException(msg, fileUrl, e);
    }
    return r;
  }
View Full Code Here

  public Resource retrieveResource(CaptureSearchResult result)
    throws ResourceNotAvailableException {
    // extract ARC filename
    String fileName = result.getFile();
    if(fileName == null || fileName.length() < 1) {
      throw new ResourceNotAvailableException("No ARC/WARC name in search result...", fileName);
    }

    String urls[];
    try {
      urls = db.nameToUrls(fileName);
    } catch (IOException e1) {
      //e1.printStackTrace();
      throw new ResourceNotAvailableException(e1.getLocalizedMessage(), fileName);
    }
    if(urls == null || urls.length == 0) {
      String msg = "Unable to locate(" + fileName + ")";
      LOGGER.info(msg);
      throw new ResourceNotAvailableException(msg, fileName);
    }
   
    final long offset = result.getOffset();

    String errMsg = "Unable to retrieve";
    Exception origException = null;
   
    Resource r = null;
    // TODO: attempt multiple threads?
    for(String url : urls) {
       
      try {

        r = ResourceFactory.getResource(url, offset);
        // TODO: attempt to grab the first few KB? The underlying
        //     InputStreams support mark(), so we could reset() after.
        //      wait for now, currently this will parse HTTP headers,
        //      which means we've already read some
       
      } catch (IOException e) {
        errMsg = url + " - " + e;
        origException = e;
        LOGGER.info("Unable to retrieve " + errMsg);
      }
      if(r != null) {
        break;
      }
    }
    if(r == null) {
      throw new ResourceNotAvailableException(errMsg, fileName, origException);
    }
    return r;
  }
View Full Code Here

TOP

Related Classes of org.archive.wayback.exception.ResourceNotAvailableException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.