Package org.openxri.xml

Examples of org.openxri.xml.XRDS


        + ", sepMediaType=" + sepMediaType + ", flags:" + flags + ")");

    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);     
    }
    return xrds;
  }
View Full Code Here


      ResolverFlags flags, ResolverState state)
      throws PartialResolutionException {
    log.trace("resolveSEPToXRD('" + qxri + "', sepType=" + sepType
        + ", sepMediaType=" + sepMediaType + ", flags: " + flags + ")");

    XRDS xrds = resolveSEPToXRDS(qxri, sepType, sepMediaType, flags, state);
    return xrds.getFinalXRD();
  }
View Full Code Here

      throws PartialResolutionException {
    log.trace("resolveSEPToXRD('" + qxri + "', trustType=" + trustType
        + ", sepType=" + sepType + ", sepMediaType=" + sepMediaType
        + ", followRefs=" + followRefs + ")");

    XRDS xrds = resolveSEPToXRDS(qxri, trustType, sepType, sepMediaType,
        followRefs, state);
    return xrds.getFinalXRD();
  }
View Full Code Here

  public XRDS resolveAuthority(XRI qxri, ResolverFlags flags, ResolverState state)
    throws PartialResolutionException
  {
    log.trace("resolveAuthority(s'" + qxri + "', flags: " + flags + ")");

    XRDS xrdsOut = new XRDS();
    xrdsOut.setRef("xri://" + qxri.getAuthorityPath().toString());

    // determine the authority type
    AuthorityPath ap = qxri.getAuthorityPath();
    try {
      XRDS newXRDS;
      if (ap instanceof XRIAuthority)
        newXRDS = resolveXRIAuth(qxri, (XRIAuthority)ap, flags, state);
      else if (ap instanceof IRIAuthority)
        newXRDS = resolveIRIAuth((IRIAuthority) ap, flags, state);
      else
View Full Code Here

      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);
      throw new PartialResolutionException(xrdsOut);
    }

    XRISegment segment = xriAuth.getXRISegment();
View Full Code Here

  protected XRDS resolveIRIAuth(IRIAuthority iriAuth, ResolverFlags flags, ResolverState state)
    throws PartialResolutionException
  {
    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).getInputStream();
    } 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);
    }

    return xrdsOut;
  }
View Full Code Here

      ResolverState state) throws PartialResolutionException {
    log.trace("resolveViaProxy('" + qxri + ", serviceType=" + serviceType
        + ", serviceMediaType=" + serviceMediaType + ", flags: "
        + flags + ")");

    XRDS xrdsOut = new XRDS();

    // build the new URI for the proxy
    URI newURI = null;
    try {
      StringBuffer query = new StringBuffer();
      if (serviceType != null) {
        query.append("_xrd_t=");
        query.append(URLEncoder.encode(serviceType, "UTF-8"));
        query.append('&');
      }

      if (serviceMediaType != null) {
        query.append("_xrd_m=");
        query.append(URLEncoder.encode(serviceMediaType, "UTF-8"));
        query.append('&');
      }

      query.append("_xrd_r=");
      query.append(Tags.CONTENT_TYPE_XRDS);
      query.append(';');
      query.append(flags.getTrustParameters());
      query.append(";sep=");
      query.append(sepSelect);
      query.append(";ref=");
      query.append(flags.isRefs());
      query.append('&');

      if (proxyURI.getQuery() != null) {
        query.append(proxyURI.getQuery());
      }

      StringBuffer uriBuf = new StringBuffer();
      uriBuf.append(proxyURI.getScheme());
      uriBuf.append("://");
      uriBuf.append(proxyURI.getAuthority());
      uriBuf.append(proxyURI.getPath());
      if (uriBuf.charAt(uriBuf.length() - 1) != '/')
        uriBuf.append('/');

      StringBuffer qxriNoQuery = new StringBuffer(qxri.getAuthorityPath().toIRINormalForm());
      if (sepSelect) {
        qxriNoQuery.append(qxri.getXRIPath().toURINormalForm());
      }
     
      uriBuf.append(URLEncoder.encode(qxriNoQuery.toString(), "UTF-8"));
      uriBuf.append('?');
      uriBuf.append(query);

      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).getInputStream();
      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)) {
View Full Code Here

  protected XRDS processRedirects(XRI qxri, XRD parent, ResolverFlags flags, ResolverState state)
    throws PartialResolutionException
  {
    log.trace("processRedirects (qxri=" + qxri + ")");
   
    XRDS xrdsOut = new XRDS();
    XRDS tmpXRDS;
    List redirects = parent.getPrioritizedRedirects();
    Iterator it = redirects.iterator();
   
    // there must be some redirects!
    if (!it.hasNext())
View Full Code Here

   * @throws PartialResolutionException
   */
  protected XRDS fetchAuthXRDSHelper(XRI qxri, URI uri, XRD parent, Service parentService, XRISegment segment, ResolverFlags flags, ResolverState state, String parentXRI)
    throws PartialResolutionException
  {
    XRDS xrdsOut = new XRDS();
    String query = segment.getSubSegmentAt(0).toURINormalForm(true);

    URI newURI;
    try {
      newURI = constructAuthResURI(uri.toString(), segment.toURINormalForm(true));
      log.trace("fetchAuthXRDS - newURI = " + newURI);
    }
    catch (java.net.URISyntaxException oEx) {
      throw makeResolutionException(xrdsOut, query, Status.AUTH_RES_ERROR, "Invalid URI for authority resolution service");
    }

    ResolvedHttpResponse resp = null;
    XRDS tmpXRDS = null;
    // now that we've constructed the new URI, try to return the stream from it
    try {
      resp = getDataFromURI(newURI, segment.toString(), flags, state);
      InputStream in = resp.getInputStream();
      tmpXRDS = readXRDS(in);
      log.debug("fetchAuthXRDS - got XRDS = " + tmpXRDS.serializeDescriptorDOM(false, true));
    } catch (IOException e) {
      log.trace("fetchAuthXRDS - got IOException from URI " + newURI);
      throw makeResolutionException(xrdsOut, query, Status.NETWORK_ERROR, "Networking error encountered");
    } catch (Exception e) {
      log.trace("fetchAuthXRDS - " + e);
      throw makeResolutionException(xrdsOut, query, Status.AUTH_RES_ERROR, e.getMessage());
    }
   
    //// sanity checks
   
    // there should be at least one child element
    if (tmpXRDS.getNumChildren() < 1) {
      throw makeResolutionException(xrdsOut, query, Status.INVALID_XRDS, "Invalid XRDS document");
    }
   
    if (tmpXRDS.getNumChildren() > segment.getNumSubSegments()) {
      throw makeResolutionException(xrdsOut, query, Status.INVALID_XRDS, "Invalid XRDS document: too many XRD elements returned");     
    }
   

    XRD prevXRD = parent;
    Service prevService = parentService;
    ResolverFlags currentFlags = null; // this is for overriding by SamlBypassAuthority settings
    // 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);
      currentFlags = new ResolverFlags(flags); // clone flags
     
      // if SAML WAS requested and what we are resolving is allowed to bypass SAML,
      // we turn off the SAML flag to allow SAML failure of any kind for this administrative region
            if (currentFlags.isSaml() && isSAMLBypassAuthority(parentXRI)) {
              currentFlags.setSaml(false);
            }

      parseFetchedXRD(xrdsOut, xrd, prevXRD, segment.getSubSegmentAt(d), prevService, currentFlags);

            // write to cache if we have one
      if (cache != null && d == 0) {
        // do our caching here right after we got the first XRD
        String xriAuthority = XRI.fromURINormalForm(parentXRI + query).toURINormalForm();
        byte[] xrdsBuf = null;
        try {
          xrdsBuf = xrdsOut.toString().getBytes("UTF-8");
        } catch (UnsupportedEncodingException e) {}
       
        int cacheTTL = computeCacheTTL(xrd.getExpires(), resp);
        log.debug("writing cache entry " + xriAuthority + ", cacheTTL = " + cacheTTL);
       
        if (cacheTTL > 0) {
          cache.put(xriAuthority, currentFlags.isHttps(), currentFlags.isSaml(), xrdsBuf, cacheTTL);
        }
      }

      if(flags.isSaml() && d != (tmpXRDS.getNumChildren()-1))
      {
        //// perform service selection
        String authResMediaType = Tags.CONTENT_TYPE_XRDS + ";" + flags.getTrustParameters();
        List authResServices = selectServices(prevXRD.getServices(), null, null, authResMediaType, flags);
        if (authResServices.size() < 1) {
View Full Code Here

      throw ex;
    }

    // the big goal is to make an XRDS, consisting of one XRD

    XRDS xrds = new XRDS();
    boolean ret;

    // give subclasses a chance to init the XRDS before we begin

    ret = this.initXRDS(
        xrds,
        namespace,
        signed);

    // if a subclass returned true, it doesn't want us to do any more work

    if (ret == true) {

      log.debug("Subclass handled XRDS completely. Returning it without any more work.");
      return(xrds);
    }

    // generate an XRD for the namespace

    for (int i=0; i<1; i++) {

      try {

        // create a fresh XRD

        XRD xrd = new XRD();

        // give subclasses a chance to init the XRD

        ret = this.initXRD(
            xrd,
            namespaceAuthority,
            namespace,
            signed);

        // if a subclass returned true, it doesn't want us to do any more work

        if (ret == true) {

          log.debug("Subclass handled XRD completely. Returning it without any more work.");
          xrds.add(xrd);
          break;
        }

        // check if the authority overrides the LOOKUP pipeline. if not, use the default.

        ServerConfig serverConfig = ServerConfigFactory.getSingleton();
        PipelineRegistry pipelineRegistry = (serverConfig == null) ? null : serverConfig.getPipelineRegistry();
        Pipeline lookupPipeline = null;

        if (this.store instanceof StoreAttributable) {

          StoreAttributable storeAttributable = (StoreAttributable) this.store;

          String pipelineName = storeAttributable.getAuthorityAttributes(namespaceAuthority).get(Pipeline.ATTRIBUTE_OVERRIDE_LOOKUP_PIPELINE);
          if (pipelineRegistry != null && pipelineName != null) lookupPipeline = pipelineRegistry.getPipelineByName(pipelineName);
        }

        if (pipelineRegistry != null && lookupPipeline == null) lookupPipeline = pipelineRegistry.getDefaultLookupPipeline();

        // execute LOOKUP pipeline

        xrd = lookupPipeline.execute(
            this.store,
            xrd,
            null,
            null,
            namespace,
            namespaceAuthority,
            false);

        // let our subclasses finish the XRD before we append it to the XRDS

        this.finishXRD(
            xrd,
            namespaceAuthority,
            null,
            null,
            signed);

        // if we were not able to get a XRD, return a "not found" XRD

        if (xrd == null) {

          xrds.add(makeNotFoundXrd(namespace));
          break;
        }

        // append XRD to the XRDS

        xrds.add(xrd);
      } catch (Exception ex) {

        log.error(ex);
        xrds.add(makeExceptionXrd(namespace, ex));
        break;
      }
    }

    // let subclasses finish the XRDS before we send it out
View Full Code Here

TOP

Related Classes of org.openxri.xml.XRDS

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.