Example #1
0
 private void checkSite(SiteInfo site) throws HandleException, net.handle.hdllib.HandleException {
   AbstractRequest req =
       new GenericRequest(
           Util.encodeString("0.SITE/status"), AbstractMessage.OC_GET_SITE_INFO, null);
   AbstractResponse response = resolverLowTimeout.sendRequestToSite(req, site);
   if (response == null || response.responseCode != AbstractMessage.RC_SUCCESS)
     throw new HandleException("non succesful request to primary " + site);
 }
Example #2
0
  @Override
  public String resolve(String doi) throws HandleException, NotFoundException {
    if (dummyMode) return "dummyMode";

    byte[] handle = Util.encodeString(doi);
    byte[][] types = {Util.encodeString("URL")};
    int[] indexes = new int[0];
    ResolutionRequest resReq = new ResolutionRequest(handle, types, indexes, null);
    resReq.authoritative = true; // always ask a primary server

    try {
      AbstractResponse response = resolver.processRequest(resReq);
      String msg = AbstractMessage.getResponseCodeMessage(response.responseCode);
      log4j.debug("response code from Handle request: " + msg);

      if (response.responseCode == AbstractMessage.RC_HANDLE_NOT_FOUND) {
        throw new NotFoundException("handle " + doi + " does not exist");
      }

      if (response.responseCode == AbstractMessage.RC_VALUES_NOT_FOUND) {
        throw new NotFoundException("handle " + doi + " does not have any URL");
      }

      if (response.responseCode != AbstractMessage.RC_SUCCESS) {
        throw new HandleException(msg);
      }

      HandleValue[] values = ((ResolutionResponse) response).getHandleValues();
      return values[0].getDataAsString();
    } catch (net.handle.hdllib.HandleException e) {
      if (e.getCode() == net.handle.hdllib.HandleException.SERVICE_NOT_FOUND) {
        throw new NotFoundException("prefix of handle " + doi + " does not exist");
      } else {
        String message = "tried to resolve handle " + doi + " but failed: " + e.getMessage();
        log4j.warn(message);
        throw new HandleException(message, e);
      }
    }
  }
Example #3
0
  private void checkPrimary(String serviceHandle)
      throws net.handle.hdllib.HandleException, HandleException {
    HandleValue[] values =
        resolver.resolveHandle(serviceHandle, new String[] {"HS_SITE"}, new int[0]);
    SiteInfo[] sites = Util.getSitesFromValues(values);

    boolean hasPrimary = false;
    for (SiteInfo site : sites) {
      if (site.isPrimary) {
        hasPrimary = true;
        checkSite(site);
      }
    }

    if (!hasPrimary)
      throw new HandleException("no primary handle server found for " + serviceHandle);
  }