Package org.openxri.resolve.exception

Examples of org.openxri.resolve.exception.PartialResolutionException


        XRD authXRD = getAuthority(rootAuth);
        if (authXRD == null) {
          // unknown root
          XRD err = createErrorXRD(qxri.toURINormalForm(), Status.UNKNOWN_ROOT, "Authority '" + rootAuth + "' is not configured");
          xrdsOut.add(err);
          throw new PartialResolutionException(xrdsOut);
        }
       
        XRISegment unresolved = ((XRIAuthority)ap).getXRISegment();
        try {
          XRDS newXRDS = resolveAuthSegment(authXRD, unresolved, trustType, followRefs, state);
          xrdsOut.addAll(newXRDS);
            return xrdsOut;
        }
        catch (PartialResolutionException e) {
          xrdsOut.addAll(e.getPartialXRDS());
          throw new PartialResolutionException(xrdsOut);
        }
      }
      else if (ap instanceof IRIAuthority) {
        try {
          XRDS newXRDS = resolveIRIAuth((IRIAuthority)ap, trustType, followRefs, state);
          xrdsOut.addAll(newXRDS);
          return xrdsOut;
        }
        catch (PartialResolutionException e) {
          xrdsOut.addAll(e.getPartialXRDS());
          throw new PartialResolutionException(xrdsOut);
        }
      }
      else
        throw new RuntimeException("Unknown authority");
    }
View Full Code Here


      XRDS xrdsOut = new XRDS();
     
      if (trustType.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 = trustType.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.toString(), uri, trustType, 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

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

        InputStream in = null;
        try {
            // try to get the data from it
            in = getDataFromURI(qxri.toURINormalForm(), newURI, trustType, state);
            XRDS xrds = readXRDS(in);
            XRD finalXRD = xrds.getFinalXRD();

            String code = finalXRD.getStatusCode();
            if ((followRefs && !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

   
    if (refs.size() < 1) {
      XRD err = createErrorXRD(segment.getSubSegmentAt(0).toURINormalForm(),
        Status.AUTH_RES_ERROR, "Requested service endpoint not found");
      xrdsOut.add(err);
      throw new PartialResolutionException(xrdsOut);
    }
    else if (!followRefs) {
      // there are Refs in the current XRDS but we were told not to follow any
      XRD err = createErrorXRD(segment.getSubSegmentAt(0).toURINormalForm(),
        Status.REF_NOT_FOLLOWED, "References not followed");
      xrdsOut.add(err);
      throw new PartialResolutionException(xrdsOut);
    }

    if (maxFollowRefs >= 0 && state.getNumRefsFollowed() >= maxFollowRefs) {
      XRD err = createErrorXRD(segment.getSubSegmentAt(0).toURINormalForm(),
        Status.LIMIT_EXCEEDED, "Maximum number of references exceeded");
      xrdsOut.add(err);
      throw new PartialResolutionException(xrdsOut);
    }
   

    ///// attempt each ref in turn
    for (int i = 0; i < refs.size(); i++) {
      Ref r = (Ref)refs.get(i);
      XRI refXRI = null;
      try {
        refXRI = parseAbsoluteQXRIOrError(r.getValue());
      }
      catch (PartialResolutionException e) {
        log.warn("resolveAuthSegment - Invalid ref encountered: " + e.getMessage());
        continue;
      }

      state.pushFollowingRef(refXRI);
     
      // at this point we will not try another ref; if this fails we will bail out
      XRDS xrds = null;
      try {
        xrds = resolveAuthTop(refXRI, trustType, followRefs, state);
          xrdsOut.add(xrds);
      }
      catch (PartialResolutionException e) {
        // add the resulting XRDS from the exception to ours and re-throw
        xrdsOut.add(e.getPartialXRDS());
        throw new PartialResolutionException(xrdsOut);
      }

      try {
          XRDS xrds2 = processAuthRefs(servicesOut, xrds.getFinalXRD(), segment, trustType, followRefs, state);
          if (xrds2.getNumChildren() > 0)
            xrds.addAll(xrds2);
          return xrdsOut;
      }
      catch (PartialResolutionException e) {
        // add the resulting XRDS from the exception to ours and re-throw
        xrdsOut.addAll(e.getPartialXRDS());
        throw new PartialResolutionException(xrdsOut);
      }
    }
   
    ///// should have followed one of the Refs by now, maybe all bogus Refs
    XRD err = createErrorXRD(segment.getSubSegmentAt(0).toURINormalForm(),
        Status.AUTH_RES_ERROR, "Requested service endpoint not found");
    xrdsOut.add(err);
    throw new PartialResolutionException(xrdsOut);
    }
View Full Code Here

          xrdsOut.add(finalXRD);
        }
        else {
          finalXRD.setStatus(new Status(Status.LIMIT_EXCEEDED, "Maximum of authority resolution requests exceeded"));
        }
        throw new PartialResolutionException(xrdsOut);       
      }
     
      ///// Try each URI in each selected service in turn
      Exception savedException = null;
      Iterator srvIterator = selectedServices.iterator();
      while (srvIterator.hasNext()) {
        Service srv = (Service)srvIterator.next();
       
        Iterator uriIterator = srv.getPrioritizedURIs().iterator();
          ///// try each selected service URI in turn (skip only if nothing was read)
          while (uriIterator.hasNext()) {
            SEPUri sepURI = (SEPUri)uriIterator.next();
            URI uri = sepURI.getURI();
           
            log.trace("resolveAuthSegment - trying URI='" + uri + "'");

            // skip non-HTTPS URIs if HTTPS was requested
            if (trustType.isHTTPS() && !uri.getScheme().equals(HTTPS)) {
              log.trace("resolveAuthSegment - skipping non HTTPS URI");
              continue;
            }
           
            URI newURI;
                try
                {
                    newURI = constructAuthResURI(uri.toString(), segment.toURINormalForm(true));               
                    log.trace("resolveAuthSegment - newURI = " + newURI);
                }
                catch (java.net.URISyntaxException oEx)
                {
                    // oops! invalid authority URI
                  savedException = new InvalidAuthorityURIException(
                        "Could not create URI to access based on " + uri +
                        ".  Trying to resolve " + segment, oEx);
                  continue; // try next URI
                }

                XRDS newXRDS = null;
                // now that we've constructed the new URI, try to return the stream from it
                try {
                  InputStream in = getDataFromURI(segment.toString(), newURI, trustType, state);
                    newXRDS = readXRDS(in);
                    log.debug("Got XRDS = " + newXRDS.toString());
                }
                catch (Exception e) {
                  log.trace("resolveAuthSegment - bad URI");
                  savedException = e;
                  continue;
                }
               
                // set ourselves up for the next multi-pass
                for (int d = 0; d < newXRDS.getNumChildren() && d < segment.getNumSubSegments(); d++)
                {
                    XRD xrd = newXRDS.getDescriptorAt(d);
                   
                    // status is not success
                    Status stat = xrd.getStatus();
                    if (stat == null) {
                      xrd = createErrorXRD(segment.getSubSegmentAt(d).toString(),
                        Status.UNEXPECTED_XRD, "Status code was missing in original XRD");
                    }
                   
                    // check the basic properties of the descriptor
                    boolean bValid = xrd.isValid();
                    if (!bValid) {
                      xrd = createErrorXRD(segment.getSubSegmentAt(d).toString(),
                        Status.UNEXPECTED_XRD, "Invalid XRD (stale?) received");
                    }

                    /*
                    // if we need to do trusted resolution checking
                    if (trustType.isSAML())
                    {
                        // Each descriptor must be validated independently as well as
                        // against the one that preceded (described) it in the
                        // descriptor chain.
                      // TODO: there could be more than one Authority Resolution Service
                      //       in the final XRD
                        bValid =
                            isTrustedDescriptor(
                                oAuth.getSubSegmentAt(iSubSeg), xrd,
                                oChain.getFinalXRIDescriptor().getFirstServiceByType(Tags.SERVICE_AUTH_RES));

                        // bail if the descriptor is not valid
                        if (!bValid)
                          throw new XRIResolutionException("Signature verification failed");

                    }
                    */

                    xrdsOut.add(xrd);
                   
                    if (!xrd.getStatus().getCode().equals(Status.SUCCESS)) {
                      throw new PartialResolutionException(xrdsOut);
                    }
                }

                if (newXRDS.getNumChildren() >= segment.getNumSubSegments()) {
                  // we're done!
                  return xrdsOut;
                }
               
                // not done yet, recursively resolve
               
                XRISegment remainder = segment.getRemainder(newXRDS.getNumChildren());
                XRDS remainderXRDS = null;
               
                try {
                  remainderXRDS = resolveAuthSegment(newXRDS.getDescriptorAt(newXRDS.getNumChildren()-1), remainder, trustType, followRefs, state);
                }
                catch (PartialResolutionException e) {
                  xrdsOut.addAll(e.getPartialXRDS());
                  throw new PartialResolutionException(xrdsOut);
                }

              xrdsOut.addAll(remainderXRDS);
                return xrdsOut;
          }

      }

     
      if (savedException != null) {
        savedException.printStackTrace();
        if (savedException instanceof XRIResolutionException) {
          ((XRIResolutionException)savedException).printUnderlyingStackTrace();
        }
       
        XRD err = createErrorXRD(segment.getSubSegmentAt(0).toString(), Status.AUTH_RES_ERROR, savedException.getMessage());
        xrdsOut.add(err);
        throw new PartialResolutionException(xrdsOut);
      }

      return xrdsOut;
    }
View Full Code Here

        // do reference processing
        ArrayList refs = xrd.getPrioritizedRefs();
        if (refs.size() == 0) {
          Status s = new Status(Status.SEP_NOT_FOUND, "Requested service endpoint not found.");
          xrdsOut.getFinalXRD().setStatus(s);
          throw new PartialResolutionException(xrdsOut);
        }
       
        if (maxFollowRefs >= 0 && state.getNumRefsFollowed() >= maxFollowRefs) {
          Status s = new Status(Status.LIMIT_EXCEEDED, "Maximum number of references exceeded");
          xrdsOut.getFinalXRD().setStatus(s);
          throw new PartialResolutionException(xrdsOut);         
        }

        // we have some references, let's process it
        for (int i = 0; i < refs.size(); i++) {
          Ref r = (Ref)refs.get(i);
          XRI refXRI = null;
          try {
            refXRI = new XRI(r.getValue());
          }
          catch (XRIParseException e) {
            log.warn("resolveAuthSegment - Invalid ref encountered: " + e.getMessage());
           
            // bail out if this is the last segment
            if (i == refs.size()) {
                Status s = new Status(Status.SEP_NOT_FOUND, "Invalid ref encountered: " + e.getMessage());
                xrdsOut.getFinalXRD().setStatus(s);
                throw new PartialResolutionException(xrdsOut);
            }
            else // try next one
              continue;
          }

          state.pushFollowingRef(refXRI);
         
          XRDS refXRDS = null;
          try {
            refXRDS = resolveAuthTop(refXRI, trustType, followRefs, state);
          }
          catch (PartialResolutionException e) {
            xrdsOut.addAll(e.getPartialXRDS());
            throw new PartialResolutionException(xrdsOut);
          }
         
          xrdsOut.add(refXRDS);

          // ref processing completed
          // recursively select service
          XRDS resultXRDS = null;
          try {
              resultXRDS = selectServiceFromXRD(refXRDS.getFinalXRD(), qxri, trustType, sepType, sepMediaType, followRefs, state);
          }
          catch (PartialResolutionException e) {
            xrdsOut.replaceFinalXRD(e.getPartialXRDS());
            throw new PartialResolutionException(xrdsOut);
          }
         
          xrdsOut.addAll(resultXRDS);
          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);
      }
  }
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

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.