Package org.openxri.resolve.exception

Examples of org.openxri.resolve.exception.PartialResolutionException


        break;
      }
      catch (PartialResolutionException e) {
        xrdsOut.add(e.getPartialXRDS());
        if (!it.hasNext()) // last ref, throw the exception (otherwise, continue)
          throw new PartialResolutionException(xrdsOut);
      }
    }
    return xrdsOut;
  }
View Full Code Here


    xrd.setSelectedServices(selectedSvcs);
    if (selectedSvcs.size() == 0) {
      Status s = xrd.getStatus();
      s.setCode(Status.SEP_NOT_FOUND);
      s.setText("Requested service endpoint not found");
      throw new PartialResolutionException(xrdsOut);
    }

    // check if first Service has Redirect of Ref
    Service srv = (Service)selectedSvcs.get(0);
    if (srv.getNumRedirects() > 0) {
View Full Code Here

        xrdsOut.add(tmpXRDS);
       
        // fall through to continue to the next
      }
    }
    throw new PartialResolutionException(xrdsOut);
  }
View Full Code Here

      catch (PartialResolutionException e) {
        xrdsOut.add(e.getPartialXRDS());
        // fall through to continue to the next
      }
    }
    throw new PartialResolutionException(xrdsOut);
  }
View Full Code Here

     
      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,
              "Ref not followed");
          }
          log.info("fetchRedirectXRDS - XRD at URI(" + uri + ") contains Ref(s), following..");
          tmpXRDS = processRefs(xrd, flags, state);
          xrdsOut.addAll(tmpXRDS);
        }
      }
      catch (PartialResolutionException e) {
        xrdsOut.addAll(e.getPartialXRDS());
        throw new PartialResolutionException(xrdsOut);
      }

      return xrdsOut;
  }
View Full Code Here

    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

        }
        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

        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);
    } 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

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.