Package org.openxri.xml

Examples of org.openxri.xml.XRD


    String rootAuth = xriAuth.getRootAuthority();
    if (rootAuth == null) {
      throw new RuntimeException("First subsegment of '" + xriAuth + "' is null");
    }

    XRD rootXRD = getAuthority(rootAuth);
    if (rootXRD == null) {
      XRDS xrdsOut = new XRDS();
      // unknown root
      XRD err = createErrorXRD(
        xriAuth.toURINormalForm(),
        Status.UNKNOWN_ROOT,
        "Authority '" + rootAuth + "' is not configured"
      );
      xrdsOut.add(err);
View Full Code Here


    log.trace("resolveIRIAuth('" + iriAuth + "', flags: " + flags + ")");

    XRDS xrdsOut = new XRDS();

    if (flags.isSaml()) {
      XRD err = createErrorXRD(iriAuth.toURINormalForm(),
          Status.NOT_IMPLEMENTED,
          "SAML is not supported for an IRI authority");
      xrdsOut.add(err);
      throw new PartialResolutionException(xrdsOut);
    }

    // only use http for insecure and https for secure
    String scheme = flags.isHttps() ? "https" : "http";

    URI uri = null;
    try {
      uri = new URI(scheme, iriAuth.getIUserInfo(), iriAuth.getIHost(),
          iriAuth.getPort(), null, null, null);
    } catch (java.net.URISyntaxException e) {
      XRD err = createErrorXRD(iriAuth.toURINormalForm(),
          Status.INVALID_INPUT,
          "Unable to construct URI to resolve IRI authority: "
              + e.getMessage());
      xrdsOut.add(err);
      throw new PartialResolutionException(xrdsOut);
    }

    // now that we've constructed the new URI, try to return the stream from it
    InputStream in = null;
    try {
      in = getDataFromURI(uri, uri.toString(), flags, state);
    } catch (Exception e) {
      XRD err = createErrorXRD(iriAuth.toURINormalForm(),
          Status.NETWORK_ERROR,
          "Network error occurred while resolving IRI authority: "
              + e.getMessage());
      xrdsOut.add(err);
      throw new PartialResolutionException(xrdsOut);
    }

    if (in == null) {
      throw new RuntimeException(
          "resolveIRIAuth - getDataFromURI returned null");
    }

    // read the descriptors
    try {
      xrdsOut = readXRDS(in);
      if (xrdsOut.getNumChildren() != 1) {
        XRD err = createErrorXRD(iriAuth.toURINormalForm(),
            Status.UNEXPECTED_RESPONSE,
            "Expected 1 XRD from IRI authority, got "
                + xrdsOut.getNumChildren() + " instead");
        xrdsOut.add(err);
        throw new PartialResolutionException(xrdsOut);
      }
    } catch (XRIResolutionException e) {
      XRD err = createErrorXRD(iriAuth.toURINormalForm(),
          Status.UNEXPECTED_RESPONSE,
          "Error reading XRDS from server: " + e.getMessage());
      xrdsOut.add(err);
      throw new PartialResolutionException(xrdsOut);
    }

    // add the descriptor, but only if is is valid
    XRD xrd = xrdsOut.getDescriptorAt(0);
    if (!xrd.isValid()) {
      XRD err = createErrorXRD(iriAuth.toURINormalForm(),
          Status.UNEXPECTED_XRD, "XRD is invalid");
      xrdsOut.add(err);
      throw new PartialResolutionException(xrdsOut);
    }
View Full Code Here

      log.trace("resolveViaProxy - constructed proxy query URI '"
          + uriBuf + "'");

      newURI = new URI(uriBuf.toString());
    } catch (java.net.URISyntaxException oEx) {
      XRD err = createErrorXRD(qxri.getAuthorityPath().toURINormalForm(),
          Status.INVALID_INPUT,
          "Unable to construct URI to access proxy resolution service");
      xrdsOut.add(err);
      throw new PartialResolutionException(xrdsOut);
    } catch (UnsupportedEncodingException e) {
      // thrown from URLEncoder.encode() - this should never happen since the
      // US-ASCII encoding should be supported on every computer or so we hope :)
      XRD err = createErrorXRD(qxri.getAuthorityPath().toURINormalForm(),
          Status.INVALID_INPUT, "Charset not supported");
      xrdsOut.add(err);
      throw new PartialResolutionException(xrdsOut);
    } catch (Exception e) {
      XRD err = createErrorXRD(qxri.getAuthorityPath().toURINormalForm(),
          Status.PERM_FAIL,
          "Unexpected error while constructing proxy URI: "
              + e.getMessage());
      xrdsOut.add(err);
      throw new PartialResolutionException(xrdsOut);
    }

    InputStream in = null;
    try {
      // try to get the data from it
      in = getDataFromURI(newURI, qxri.toURINormalForm(), flags, state);
      XRDS xrds = readXRDS(in);
      XRD finalXRD = xrds.getFinalXRD();

      String code = finalXRD.getStatusCode();
      if ((flags.isRefs() && !code.equals(Status.SUCCESS) && !code
          .equals(Status.REF_NOT_FOLLOWED))
          || !code.equals(Status.SUCCESS)) {
        // got either a non-SUCCESS code or
        // followRefs is on but we got non-SUCCESS and non-REF_NOT_FOLLOWED
        throw new PartialResolutionException(xrds);
      }
      return xrds;
    } catch (PartialResolutionException e) {
      // re-throw
      throw e;
    } catch (Exception e) {
      XRD err = createErrorXRD(qxri.getAuthorityPath().toURINormalForm(),
          Status.PERM_FAIL, "Error fetching XRDS from proxy: "
              + e.getMessage());
      xrdsOut.add(err);
      throw new PartialResolutionException(xrdsOut);
    }
View Full Code Here

   
    try {
      XRI ceidX = XRI.fromURINormalForm(ceid.getValue());

      log.info("verifyCEID - resolving CEID");
      XRD ceidXRD = resolveAuthToXRD(ceidX, flags, state);
      Status s = ceidXRD.getStatus();
      if (!s.getCID().equals(Status.CID_VERIFIED)) {
        log.debug("verifyCEID - XRD for CEID is not CID verified");
        return Status.CID_FAILED;
      }
     
      CanonicalID cid2 = ceidXRD.getCanonicalID();
      if (cid2 == null) {
        log.debug("verifyCEID - no CID in the XRD in CEID");
        return Status.CID_FAILED;       
      }
     
      XRI cidX2 = XRI.fromURINormalForm(cid2.getValue());
      if (!cidX2.toURINormalForm().equals(cidX.toURINormalForm())) {
        log.debug("verifyCEID - CEID's XRD's CID is not equivalent to the original CID");
        return Status.CID_FAILED;
      }
     
      /// look for an EquivID or CanonicalEquivID backpointer to the original CID
      CanonicalEquivID ceid2 = ceidXRD.getCanonicalEquivID();
      XRI ceidX2 = XRI.fromURINormalForm(ceid2.getValue());
      if (ceidX2.toURINormalForm().equals(cidX.toURINormalForm())) {
        log.debug("verifyCEID - CEID backpointer found");
        return Status.CID_VERIFIED;
      }

      for (int i = 0; i < ceidXRD.getNumEquivIDs(); i++) {
        EquivID e = ceidXRD.getEquivIDAt(i);
        XRI eX = XRI.fromURINormalForm(e.getValue());
        if (eX.toURINormalForm().equals(cidX.toURINormalForm())) {
          log.debug("verifyCEID - EquivID backpointer found");
          return Status.CID_VERIFIED;         
        }
View Full Code Here

    if (tmpXRDS.getNumChildren() > segment.getNumSubSegments()) {
      throw makeResolutionException(xrdsOut, query, Status.INVALID_XRDS, "Invalid XRDS document: too many XRD elements returned");     
    }
   

    XRD prevXRD = parent;

    // check each child
    for (int d = 0; d < tmpXRDS.getNumChildren(); d++) {
      if (!tmpXRDS.isXRDAt(d))
        throw makeResolutionException(xrdsOut, query, Status.INVALID_XRDS, "Authority XRDS document should not contain XRDS element");

      XRD xrd = tmpXRDS.getDescriptorAt(d);
      xrdsOut.add(xrd);

      // status is not success
      ServerStatus sstat = xrd.getServerStatus();
      Status stat;
      if (sstat == null) {
        // compatibility: if no ServerStatus, look for Status
        stat = xrd.getStatus();
        if (stat != null) {
          xrd.setServerStatus(new ServerStatus(stat.getCode(), stat.getText()));
        }
      }
      else {
        stat = new Status(sstat.getCode(), sstat.getText());
        xrd.setStatus(stat);
      }
     
      if (stat == null)
        throw makeResolutionException(xrdsOut, query, Status.INVALID_XRDS, "Missing ServerStatus or Status element in XRD");


      if (!stat.getCode().equals(Status.SUCCESS)) {
        throw new PartialResolutionException(xrdsOut);
      }

      // check the basic properties of the descriptor
      if (!xrd.isValid()) {       
        xrd.setStatus(new Status(Status.UNEXPECTED_RESPONSE, "XRD is not valid (stale?)"));
        throw new PartialResolutionException(xrdsOut);
      }

      if (flags.isCid()) {
        Status parentStatus = parent.getStatus();
        Status s = xrd.getStatus();
       
        String parentCIDStat = parentStatus.getCID();
        if (parentCIDStat.equals(Status.CID_FAILED)) {
          s.setCID(Status.CID_FAILED);
        }
View Full Code Here

   * @throws PartialResolutionException
   */
  protected XRDS fetchAuthXRDS(XRI qxri, XRD parent, List authResServices, XRISegment segment, ResolverFlags flags, ResolverState state) throws PartialResolutionException
  {
    XRDS xrdsOut = null;
    XRD errXRD = null;
    String query = segment.getSubSegmentAt(0).toURINormalForm(true);
   
    //// TODO verify synonyms

    ///// Try each URI in each selected service in turn
View Full Code Here

 
  protected void checkMaxRequests(XRDS xrdsOut, String query, ResolverState state)
    throws PartialResolutionException
  {
    if (maxRequests >= 0 && state.getNumRequests() >= maxRequests) {
      XRD finalXRD = xrdsOut.getFinalXRD();
      if (finalXRD == null) {
        finalXRD = createErrorXRD(query, Status.LIMIT_EXCEEDED, "Maximum of authority resolution requests exceeded");
        xrdsOut.add(finalXRD);
      } else {
        finalXRD.setStatus(new Status(Status.LIMIT_EXCEEDED,
            "Maximum of authority resolution requests exceeded"));
      }
      throw new PartialResolutionException(xrdsOut);
    }
   
View Full Code Here

 

  private PartialResolutionException
  makeResolutionException(XRDS targetXRDS, String query, String status, String message)
  {
    XRD x = createErrorXRD(query, status, message);
    targetXRDS.add(x);
    return new PartialResolutionException(targetXRDS);
  }
View Full Code Here

          String constructedURI = constructURI(uri, r.getAppend(), qxri);
          uri = new URI(constructedURI);
        }
      } catch (URISyntaxException e) {
        XRDS tmpXRDS = new XRDS();
        XRD err = createErrorXRD(r.getValue(), Status.INVALID_REDIRECT, "Invalid Redirect URI");
        tmpXRDS.add(err);
        xrdsOut.add(tmpXRDS);
        continue;
      }
     
      try {
        XRDS tmpXRDS = fetchRedirectXRDS(uri, parent, qxri, flags, state);
        xrdsOut.add(tmpXRDS);
       
        XRD finalXRD = tmpXRDS.getFinalXRD();
        tmpXRDS = new XRDS();
        List services = selectServiceFromXRD(tmpXRDS, finalXRD, qxri, sepType, sepMediaType, flags, state);
        xrdsOut.addAll(tmpXRDS);
        return services; // we're done!
      } catch (XRIResolutionException e) {
        XRDS tmpXRDS = new XRDS();
        XRD err = createErrorXRD(uri.toString(), Status.REDIRECT_ERROR, "Error fetching XRDS: " + e.getMessage());
        tmpXRDS.add(err);
        xrdsOut.add(tmpXRDS);
       
        // fall through to continue to the next
      }
View Full Code Here

      }
     
      if (!tmpXRDS.isXRDAt(0))
        throw makeResolutionException(xrdsOut, query, Status.INVALID_XRDS, "Authority XRDS document should not contain XRDS element");

      XRD xrd = tmpXRDS.getDescriptorAt(0);
      xrdsOut.add(xrd);


      ServerStatus sstat = xrd.getServerStatus();
      Status stat;
      if (sstat == null) {
        // compatibility: if no ServerStatus, look for Status
        stat = xrd.getStatus();
      }
      else {
        stat = new Status(sstat.getCode(), sstat.getText());
        xrd.setStatus(stat);
      }
     
      if (stat == null)
        throw makeResolutionException(xrdsOut, query, Status.INVALID_XRDS, "Missing ServerStatus or Status element in Redirect XRD");

      if (!stat.getCode().equals(Status.SUCCESS)) {
        throw new PartialResolutionException(xrdsOut);
      }

      // check the basic properties of the descriptor
      if (!xrd.isValid()) {       
        xrd.setStatus(new Status(Status.UNEXPECTED_RESPONSE, "XRD is not valid (stale?)"));
        throw new PartialResolutionException(xrdsOut);
      }
     
      String err = verifyRedirectXRD(xrd, parent);
      if (err != null) {
        xrd.setStatus(new Status(Status.REDIRECT_VERIFY_FAILED, err));
        throw new PartialResolutionException(xrdsOut);
      }
     
      // copy parent Status cid attribute if present
      stat.setCID(xrd.getCanonicalID() == null? Status.CID_ABSENT : parent.getStatus().getCID());
     
      // copy parent Status ceid attribute (without checking if present since it is supposed to be "off" for
      // non-final XRD, and we don't know whether this is a final XRD.)
      stat.setCEID(parent.getStatus().getCEID());
     
      try {
        if (xrd.getNumRedirects() > 0) {
          log.info("fetchRedirectXRDS - XRD at URI(" + uri + ") contains Redirect(s), following..");
          tmpXRDS = processRedirects(qxri, xrd, flags, state);
          xrdsOut.addAll(tmpXRDS);
        }
        else if (xrd.getNumRefs() > 0) {
          if (!flags.isRefs()) {
            throw makeResolutionException(
              xrdsOut,
              query,
              Status.REF_NOT_FOLLOWED,
View Full Code Here

TOP

Related Classes of org.openxri.xml.XRD

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.