Package org.openxri.resolve.exception

Examples of org.openxri.resolve.exception.PartialResolutionException


    try {
      XRI xri = new XRI(qxri);
      if (xri.isRelative()) {
        XRD err = createErrorXRD(qxri, Status.INVALID_QXRI,
            "QXRI is not absolute.");
        throw new PartialResolutionException(err);
      }
      return xri;
    } catch (XRIParseException e) {
      XRD err = createErrorXRD(qxri, Status.INVALID_QXRI,
          "QXRI parse error: " + e.getMessage());
      throw new PartialResolutionException(err);
    } catch (Exception e) {
      XRD err = createErrorXRD(qxri, Status.PERM_FAIL,
          "Unexpected error while parsing input: " + e.getMessage());
      throw new PartialResolutionException(err);
    }
  }
View Full Code Here


        throw new RuntimeException("Unknown authority type");
      xrdsOut.addAll(newXRDS);
      return xrdsOut;
    } catch (PartialResolutionException e) {
      xrdsOut.addAll(e.getPartialXRDS());
      throw new PartialResolutionException(xrdsOut);
    }
  }
View Full Code Here

        xriAuth.toURINormalForm(),
        Status.UNKNOWN_ROOT,
        "Authority '" + rootAuth + "' is not configured"
      );
      xrdsOut.add(err);
      throw new PartialResolutionException(xrdsOut);
    }

    XRISegment segment = xriAuth.getXRISegment();

    // resolve segment (list of subsegments not including root) against root XRD
View Full Code Here

    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

    } 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)) {
        // 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

        // fall through to continue to the next
      }
    }
   
    log.info("processRedirects - exhausted list of Redirects. Throwing PRE");
    throw new PartialResolutionException(xrdsOut);
  }
View Full Code Here

      xrd.setStatus(stat);
    }

    if (stat == null) {
      xrd.setStatus(new Status(Status.INVALID_XRDS, "Missing ServerStatus or Status element in XRD"));
      throw new PartialResolutionException(xrdsOut);
    }


    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 prevStatus = prevXRD.getStatus();
      Status s = xrd.getStatus();

      String prevCIDStat = prevStatus.getCID();
      if (prevCIDStat.equals(Status.CID_FAILED)) {
        s.setCID(Status.CID_FAILED);
      }
      else {
        s.setCID(verifyCID(prevXRD, xrd));
      }
    }

    // if we need to do trusted resolution checking
    if (flags.isSaml())
    {
      XRD xrdCopy = (XRD)xrd.clone();
      xrdCopy.clearDOM();

      // Each descriptor must be validated independently as well as
      // against the one that preceded (described) it in the
      // descriptor chain.

      boolean valid = isTrustedDescriptor(query, xrdCopy, prevService);

      // bail if the descriptor is not valid
      if (!valid) {
        xrd.setStatus(new Status(Status.UNVERIFIED_SIGNATURE, "Signature verification failed."));
        throw new PartialResolutionException(xrdsOut);
      }

    }

  }
View Full Code Here

        }
        catch (Exception e)
        {
          if (e instanceof PartialResolutionException) {
            String stat1 = null, stat2 = null, stat3 = null;
              PartialResolutionException pe = (PartialResolutionException)e;
              System.err.println(pe.getPartialXRDS().toString());

              assertTrue("Should contain 3 XRDs, got " + pe.getPartialXRDS().getNumChildren() + " instead",
                  pe.getPartialXRDS().getNumChildren() == 3);

            try {
              stat1 = pe.getPartialXRDS().getDescriptorAt(0).getStatusCode();
              stat2 = pe.getPartialXRDS().getDescriptorAt(1).getStatusCode();
              stat3 = pe.getPartialXRDS().getDescriptorAt(2).getStatusCode();
            }
            catch (Exception e1) {
              assertTrue("Got exception: " + e1.getMessage(), false);
            }
           
              assertTrue("First XRD should be successful", stat1.equals(Status.SUCCESS));
              assertTrue("Second XRD should be successful", stat2.equals(Status.SUCCESS));
              assertTrue("Third XRD should be a failure", stat3.equals(Status.AUTH_RES_NOT_FOUND));
          }
          else {
            fail("Got exception while trying to resolve via proxy " + e);
            e.printStackTrace();
          }
        }

        // should not work - too many descriptors
        /*** [wil] test disabled - proxy resolution currently does not validate the number of XRDs returned.
        try
        {
            XRD oDesc = oResolver.resolveAuthToXRD("xri://@!foo", new TrustType(), true);
            assertFalse("Should get a failure code for too many XRDs", oDesc.getStatusCode().equals(Status.SUCCESS));
        }
        catch (Exception oEx)
        {
            fail("Got exception while trying to resolve via proxy  " + oEx);
        }
        */

        // should work as (null response)
        try
        {
            XRD oDesc = oResolver.resolveAuthToXRD("xri://@!foo!nonexistent", new TrustType(), true);
            assertTrue(
                "Should not have obtained XRD from proxy",
                oDesc == null);
        }
        catch (Exception e)
        {
          if (e instanceof PartialResolutionException) {
            PartialResolutionException pe = (PartialResolutionException)e;
            String stat = null;
            try {
              stat = pe.getPartialXRDS().getDescriptorAt(0).getStatusCode();
            }
            catch (Exception e1) { assertTrue("got exception: " + e1.getMessage(), false); }
           
            assertTrue("First XRD should fail", stat.equals(Status.AUTH_RES_NOT_FOUND));
          }
View Full Code Here

        }
        catch (Exception e)
        {
          if (e instanceof PartialResolutionException) {
            String stat1 = null, stat2 = null, stat3 = null;
              PartialResolutionException pe = (PartialResolutionException)e;
              System.err.println(pe.getPartialXRDS().toString());

              assertTrue("Should contain 3 XRDs, got " + pe.getPartialXRDS().getNumChildren() + " instead",
                  pe.getPartialXRDS().getNumChildren() == 3);

            try {
              stat1 = pe.getPartialXRDS().getDescriptorAt(0).getStatusCode();
              stat2 = pe.getPartialXRDS().getDescriptorAt(1).getStatusCode();
              stat3 = pe.getPartialXRDS().getDescriptorAt(2).getStatusCode();
            }
            catch (Exception e1) {
              assertTrue("Got exception: " + e1.getMessage(), false);
            }
           
              assertTrue("First XRD should be successful", stat1.equals(Status.SUCCESS));
              assertTrue("Second XRD should be successful", stat2.equals(Status.SUCCESS));
              assertTrue("Third XRD should be a failure", stat3.equals(Status.AUTH_RES_NOT_FOUND));
          }
          else {
            fail("Got exception while trying to resolve via proxy " + e);
            e.printStackTrace();
          }
        }

        // should not work - too many descriptors
        /*** [wil] test disabled - proxy resolution currently does not validate the number of XRDs returned.
        try
        {
            XRD oDesc = oResolver.resolveAuthToXRD("xri://@!foo", new TrustType(), true);
            assertFalse("Should get a failure code for too many XRDs", oDesc.getStatusCode().equals(Status.SUCCESS));
        }
        catch (Exception oEx)
        {
            fail("Got exception while trying to resolve via proxy  " + oEx);
        }
        */

        // should work as (null response)
        try
        {
            XRD oDesc = oResolver.resolveAuthToXRD("xri://@!foo!nonexistent", new TrustType(), true);
            assertTrue(
                "Should not have obtained XRD from proxy",
                oDesc == null);
        }
        catch (Exception e)
        {
          if (e instanceof PartialResolutionException) {
            PartialResolutionException pe = (PartialResolutionException)e;
            String stat = null;
            try {
              stat = pe.getPartialXRDS().getDescriptorAt(0).getStatusCode();
            }
            catch (Exception e1) { assertTrue("got exception: " + e1.getMessage(), false); }
           
            assertTrue("First XRD should fail", stat.equals(Status.AUTH_RES_NOT_FOUND));
          }
View Full Code Here

    try {
      resultXRDS = selectServiceFromXRD(finalXRD, qxri, trustType, sepType, sepMediaType, followRefs, state);
    }
    catch (PartialResolutionException e) {
      xrds.replaceFinalXRD(e.getPartialXRDS());
      throw new PartialResolutionException(xrds);
    }
 
    xrds.replaceFinalXRD(resultXRDS);
    return xrds;
  }
View Full Code Here

TOP

Related Classes of org.openxri.resolve.exception.PartialResolutionException

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.