Package org.openxri.xml

Examples of org.openxri.xml.XRDS


    boolean signed = checkSigned(request);

    // the goal is to get a complete XRDS document

    XRDS xrds = null;

    // let our URIMapper tell us what to do

    URIMapperResult data = this.uriMapper.parseRequest(new URIMapperRequest(request));

    String namespace = (data == null) ? null : data.getNamespace();
    String query = (data == null) ? null : data.getQuery();

    if (namespace != null && namespace.trim().equals("")) namespace = null;
    if (query != null && query.trim().equals("")) query = null;

    String path = request.getRequestURI().substring(request.getContextPath().length() + 1);

    // use the Server to get an XRDS

    try {

      // got a namespace but no query? that means the client wants a self-describing XRDS

      if (namespace != null && query == null) {

        // ask the Server to give us a self-describing XRDS for the namespace

        log.debug("Looking up self-describing descriptor.");

        xrds = this.server.lookupSelfDescribing(namespace, signed);
      }

      // got a namespace and a query? that means the client wants normal authority resolution

      if (namespace != null && query != null) {

        // ask the Server to give us an XRDS for the namespace and query

        log.debug("Looking up descriptor by namespace and query.");

        xrds = this.server.lookupByNamespace(namespace, query, signed);
      }

      // got neither a namespace nor a query? try getting an XRDS by path

      if (namespace == null && query == null) {

        // ask the Server to give us an XRDS for the path

        log.debug("Looking up descriptor by path.");

        xrds = this.server.lookupByPath(path, signed);
      }
    } catch (Exception ex) {

      log.warn("Internal server problem during resolution.", ex);
      response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, ex.getMessage());
      return;
    }

    // if we were not able to get an XRDS, let the plugin handle the request

    if (xrds == null || xrds.getNumXRD() < 1) {

      if (this.plugin == null) {

        log.warn("No plugin installed.");
        response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Invalid request.");
        return;
      }

      log.debug("Forwarding request to plugin.");

      boolean ret = this.plugin.processCustomRequest(request, response);

      // did the plugin handle the request?

      if (ret == true) {

        log.debug("Plugin successfully handled the request.");
        return;
      } else {

        log.warn("Plugin failed to handle the request.");
        response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Plugin failed to handle the request.");
        return;
      }
    }

    // send out the result

    String body = xrds.toString();

    log.debug("Resolution successful. Sending descriptor.");
    response.setStatus(HttpServletResponse.SC_OK);
    response.setContentType(Tags.CONTENT_TYPE_XRDS + "; charset=UTF-8");
    response.getOutputStream().write(body.getBytes("UTF-8"));
View Full Code Here


      ResolverState state) throws PartialResolutionException {
    log.trace("resolveAuthToXRDS(s'" + qxri + "', flags: " + flags + ")");
    if (proxyURI != null)
      return resolveViaProxy(qxri, null, null, false, flags, state);

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

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

    if (proxyURI != null) {
      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

        + ", 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);
    } 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);
      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

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.