Package org.openxri.xml

Examples of org.openxri.xml.XRD


      XRDS xrds = resolveViaProxy(qxri, null, null, false, flags, state);
      return xrds.getFinalXRD();
    }

    XRDS xrds = resolveAuthority(qxri, flags, state);
    XRD finalXRD = xrds.getFinalXRD();
    if (flags.isUric()) {
      constructURIinXRD(finalXRD, qxri);
    }
    return finalXRD;
  }
View Full Code Here


    if (proxyURI != null)
      return resolveViaProxy(qxri, sepType, sepMediaType, true, flags, state);

    XRDS xrds = resolveAuthority(qxri, flags, state);
    XRD finalXRD = xrds.getFinalXRD();

    selectServiceFromXRD(xrds, finalXRD, qxri, sepType, sepMediaType, flags, state);
    if (flags.isUric()) {
      constructURIinXRD(xrds.getFinalXRD(), qxri);     
    }
View Full Code Here

    log.trace("resolveSEPToURIList('" + qxri + "', sepType=" + sepType
        + ", sepMediaType=" + sepMediaType + ", flags: " + flags + ")");

    // no need to do uric
    flags.setUric(false);
    XRD xrd = resolveSEPToXRD(qxri, sepType, sepMediaType, flags, state);
    if (xrd == null)
      return new ArrayList();

    if (xrd.getSelectedServices().getList().size() < 1) {
      log.error("SEP Selection succeeded but no Service found!?");
      return new ArrayList();
    }

    Service topService = (Service) xrd.getSelectedServices().getList().get(0);

    ArrayList urisOut = new ArrayList();
    ArrayList uris = topService.getPrioritizedURIs();
    for (int i = 0; uris != null && i < uris.size(); i++) {
      SEPUri uri = (SEPUri) uris.get(i);
View Full Code Here

    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

    log.debug("XRI: " + xri);

    String resolveXri = (xri.startsWith("=") || xri.startsWith("@")) ? xri : "=" + xri;
    resolveXri = resolveXri.replace("-", "*");
    XRD xrd = null;

    log.debug("XRI: " + xri);

    // resolve the XRI

    try {

      xrd = resolver.resolveAuthToXRD(new XRI(resolveXri), resolverFlags, new ResolverState());
    } catch (PartialResolutionException ex) {

      log.error("Problem while resolving " + resolveXri + ": " + ex.getMessage(), ex);
      sendResponse(response, HttpServletResponse.SC_NOT_FOUND);
      return;
    }

    if (xrd == null || (! Status.SUCCESS.equals(xrd.getStatusCode()))) {

      log.error("No XRD or bad status code for " + resolveXri + ": " + (xrd != null ? xrd.getStatusCode() : null));
      sendResponse(response, HttpServletResponse.SC_NOT_FOUND);
      return;
    }

    // construct the XRD

    StringBuffer buffer = new StringBuffer();
    buffer.append("<XRD xmlns=\"http://docs.oasis-open.org/ns/xri/xrd-1.0\">\n");

    buffer.append("<Subject>acct:" + xri + "@xri2xrd.net</Subject>\n");

    String canonical;

    if (xrd.getCanonicalID() != null) {

      buffer.append("<Alias>http://xri2xrd.net/" + xrd.getCanonicalID().getValue() + "</Alias>\n");
      buffer.append("<Alias>http://xri2xrd.net/" + xri + "</Alias>\n");
      buffer.append("<Alias>acct:" + xrd.getCanonicalID().getValue() + "@xri2xrd.net</Alias>\n");
      buffer.append("<Alias>acct:" + xri + "@xri2xrd.net</Alias>\n");

      canonical = xrd.getCanonicalID().getValue();
    } else {

      buffer.append("<Alias>http://xri2xrd.net/" + xri + "</Alias>\n");
      buffer.append("<Alias>acct:" + xri + "@xri2xrd.net</Alias>\n");

      canonical = resolveXri;
    }

    if (! xri.equals(resolveXri)) {

      buffer.append("<Alias>http://xri2xrd.net/" + resolveXri + "</Alias>\n");
      buffer.append("<Alias>acct:" + resolveXri + "@xri2xrd.net</Alias>\n");
    }

    appendLink(buffer, "http://webfinger.net/rel/profile-page", "http://xri2xrd.net/" + canonical, "text/html");
    appendLink(buffer, "describedby", "http://xri2xrd.net/" + canonical, "text/html");

    for (int i=0; i<xrd.getNumServices(); i++) {

      Service service = (Service) xrd.getServiceAt(i);

      if (service == null) continue;

      SEPMediaType mediaType = (service.getNumMediaTypes() > 0) ? service.getMediaTypeAt(0) : null;

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

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.