Package org.openxri.xml

Examples of org.openxri.xml.XRD


     
      qxri = "@xrid*test*live.unit.tests*0001-simple";
      xri = XRI.fromIRINormalForm(qxri);
      xrds = resolver.resolveAuthToXRDS(xri, flags, new ResolverState());
      assertTrue("Expected 4 XRDs", xrds.getNumChildren() == 4);
      XRD xrd3 = xrds.getDescriptorAt(3);
      assertTrue("subseg[3] should be *0001-simple", xrd3.getQuery().equals("*0001-simple"));
      assertTrue("subseg[3] should be CID verified", xrd3.getStatus().getCID().equals(Status.CID_VERIFIED));
      assertTrue("subseg[3] should be CEID verified", xrd3.getStatus().getCEID().equals(Status.CID_VERIFIED));
    }
    catch (Exception e) {
      fail("Not expecting an exception here: " + e);
      e.printStackTrace();
    }
View Full Code Here


    log.debug("XRI: " + xri);

    String resolveXri = (xri.startsWith("=") || xri.startsWith("@")) ? xri : "=" + xri;
    resolveXri = resolveXri.replace("-", "*");
    XRD xrd = null;

    // resolve the XRI

    log.debug("Resolving " + resolveXri);

    try {

      xrd = resolver.resolveSEPToXRD(new XRI(resolveXri), serviceString, null, resolverFlags, new ResolverState());
    } catch (PartialResolutionException ex) {

      log.error("Problem while resolving " + resolveXri + ": " + ex.getMessage(), ex);
      sendResponse(response, HttpServletResponse.SC_NOT_FOUND);
      return;
    }

    if (xrd == null || (! Status.SUCCESS.equals(xrd.getStatusCode()))) {

      log.error("No XRD or bad status code for " + resolveXri + ": " + (xrd != null ? xrd.getStatusCode() : null));
      sendResponse(response, HttpServletResponse.SC_NOT_FOUND);
      return;
    }

    // construct the JSON

    StringBuffer buffer = new StringBuffer();
    buffer.append("{\n");
    buffer.append("  \"locations\": [ ");

    String canonical;

    if (xrd.getCanonicalID() != null) {

      canonical = xrd.getCanonicalID().getValue();
    } else {

      canonical = resolveXri;
    }

    List<String> jsonLocations = new ArrayList<String>();

    for (int i=0; i<xrd.getSelectedServices().getList().size(); i++) {

      Service service = (Service) xrd.getSelectedServices().getList().get(i);

      if (service == null) continue;

      for (int ii=0; ii<service.getNumURIs(); ii++) {

View Full Code Here

    }
  }

 
  public static XRD createAuthRoot(String uri) {
    XRD xrd = new XRD();

    // construct an authority resolution service
    Service srv = new Service();
    TrustType tt = new TrustType(); // default trust type
    String authMediaType = Tags.CONTENT_TYPE_XRDS + ";"
        + tt.getParameterPair();
    srv.addMediaType(authMediaType, null, Boolean.FALSE);
    srv.addType(Tags.SERVICE_AUTH_RES);
    srv.addURI(uri);

    // add it to the XRD
    xrd.addService(srv);

    return xrd;
  }
View Full Code Here

  {
    // instantiate a Resolver object
    Resolver resolver = new Resolver();

    // configure roots
    XRD eqRoot = createAuthRoot("http://equal.xri.net/");
    eqRoot.setCanonicalID(new CanonicalID("="));
    Status eqRootStatus = new Status(Status.SUCCESS);
    eqRootStatus.setCID(Status.CID_VERIFIED);
    eqRoot.setStatus(eqRootStatus);
    resolver.setAuthority("=", eqRoot);

    XRD atRoot = createAuthRoot("http://at.xri.net/");
    atRoot.setCanonicalID(new CanonicalID("@"));
    Status atRootStatus = new Status(Status.SUCCESS);
    atRootStatus.setCID(Status.CID_VERIFIED);
    atRoot.setStatus(atRootStatus);
    resolver.setAuthority("@", atRoot);

    return resolver;
  }
View Full Code Here

        oResolver.setMaxFollowRedirects(0);

        // should not work - not enough descriptors
        try
        {
            XRD oDesc = oResolver.resolveAuthToXRD("xri://@!foo!bar!baz", new TrustType(), true);
            assertFalse("Should get a PartialResolutionException", oDesc.getStatusCode().equals(Status.SUCCESS));
        }
        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));
          }
          else {
            fail("Got exception while trying to resolve via proxy " + e);
          }
        }

        // should work
        try
        {
            XRD oDesc = oResolver.resolveAuthToXRD("xri://@!foo!bar", new TrustType(), false);
            assertTrue(
                "Failed to obtain XRD from proxy", oDesc != null);
        }
        catch (Exception oEx)
        {
View Full Code Here

            throws XRIResolutionException
        {
            // if we got the nonexistent "command" return a not found
            if (uri.getPath().indexOf("!nonexistent") >= 0)
            {
                XRD xrd = new XRD();
                xrd.setQuery("!nonexistent");
                xrd.setStatus(new Status(Status.AUTH_RES_NOT_FOUND));
                XRDS xrds = new XRDS();
                xrds.add(xrd);
                return new ByteArrayInputStream(xrds.toString().getBytes());
            }

            XRDS oDescs = new XRDS();

            // just the same response always
            XRD oFoo = new XRD();
            oFoo.setQuery("!foo");
            oFoo.setStatus(new Status(Status.SUCCESS));
            oDescs.add(oFoo);

            XRD oBar = new XRD();
            oBar.setQuery("!bar");
            oBar.setStatus(new Status(Status.SUCCESS));
            oDescs.add(oBar);

            if (uri.getPath().indexOf("!baz") > 0) {
              XRD baz = new XRD();
              baz.setQuery("!baz");
              baz.setStatus(new Status(Status.AUTH_RES_NOT_FOUND, "Not found"));
                oDescs.add(baz);
            }
            return new ByteArrayInputStream(oDescs.toString().getBytes());

        } // getDataFromURI()
View Full Code Here

        Resolver oResolver = new IRIResolver();
      ResolverState state = new ResolverState();
        oResolver.setMaxFollowRedirects(0);
        try
        {
            XRD oDesc = oResolver.resolveAuthToXRD(
                "xri://www.epok.net/!foo!bar", new TrustType(), true, state);
            assertTrue(
                "Failed to obtain XRD for IRI Authority",
                oDesc != null);
            assertTrue(
                "Failed to obtain correct XRD for IRI Authority",
                oDesc.getRefAt(0).getValue().equals(
                    "xri://@foo"));
        }
        catch (Exception oEx)
        {
          oEx.printStackTrace();
          if (oEx instanceof PartialResolutionException) {
            System.err.println("Partial = " + ((PartialResolutionException)oEx).getPartialXRDS());
          }
          System.err.println("Resolver state = " + state);
            fail("Got exception while trying to resolve IRI " + oEx);
        }

        try
        {
            XRD oDesc = oResolver.resolveAuthToXRD(
                "xri://www.epok.net/!foo!bar", new TrustType(TrustType.TRUST_SAML), true);
            assertTrue(
                "Failed to get exception for trusted IRI Authority resolution",
                false);
        }
View Full Code Here

        {
            // the path better be empty
            if ((oURI.getPath() != null) && (oURI.getPath().length() > 0))
                return null;

            XRD oDesc = new XRD();
            XRI oExternal = new XRI("xri://@foo");
            oDesc.addRef(new Ref(oExternal.toString()));
            XRDS oDescs = new XRDS();
            oDescs.add(oDesc);
           
      state.pushResolved(oURI.toString(), flags.toString(), oDesc.toString(), oURI);

            return new ByteArrayInputStream(oDescs.toString().getBytes());

        }
View Full Code Here

      try {

        // create a new XRD

        XRD xrd = new XRD();

        // give subclasses a chance to init the XRD

        ret = this.initXRD(
            xrd,
            parent,
            subSegmentName,
            bSigned);

        // if a subclass returned true, it doesnt want us to do any more work

        if (ret == true) {

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

        // give authority handlers a chance to init it, if there are any for the current parent authority

        List authorityHandlers = new ArrayList();

        if (moAuthorityHandlers.get(parent.getAuthorityId()) != null)
          authorityHandlers.addAll((List) moAuthorityHandlers.get(parent.getAuthorityId()));

        for (Iterator ii = authorityHandlers.iterator(); ii.hasNext(); ) {

          if (ret == true) break;

          AuthorityHandler authorityHandler = (AuthorityHandler) ii.next();

          ret = authorityHandler.initXRD(
              xrd,
              parent,
              subSegmentName,
              bSigned);
        }

        // if an authority handler returned true, it doesnt want us to do any more work

        if (ret == true) {

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

        // using the parent authority and subsegment name, find the authority we are describing now

        SubSegment subSegment = moStore.findSubSegment(parent, subSegmentName);
        if (subSegment == null) {

          soLog.warn("Cannot find subsegment: " + subSegmentName);
          return(null);
        }

        Authority authority = moStore.getSubSegmentAuthority(subSegment);

        // look up Refs and Services from the store, as well as LocalIDs if the store supports it

        Ref[] refs = moStore.getAuthorityRefs(authority);
        Service[] services = moStore.getAuthorityServices(authority);
        LocalID[] localIds;

        if (moStore instanceof StoreBetterLookup) {

          localIds = ((StoreBetterLookup) moStore).getSubSegmentLocalIds(subSegment);
        } else {

          localIds = new LocalID[0];
        }

        // fill it with information we got from the store

        for (int ii=0; ii<refs.length; ii++) xrd.addRef(refs[ii]);
        for (int ii=0; ii<services.length; ii++) xrd.addService(services[ii]);
        for (int ii=0; ii<localIds.length; ii++) xrd.addLocalID(localIds[ii]);

        // do we want a local authority resolution service for this authority?
        // this piece of information comes from the store, but we actually create
        // the service, since this requires knowledge of the server configuration

        if (authority.getLocalAuthService().equals(Boolean.TRUE)) {

          URI[] uris;

          try {

            uris = new URI[2];
            uris[0] = fillURI(authority.getAuthorityId(), "http");
            uris[1] = fillURI(authority.getAuthorityId(), "https");
          } catch(URISyntaxException ex) {

            throw new ServerException("Invalid URI for authority resolution service.", ex);
          }

          xrd.addService(new AuthorityResolutionService(uris, authority.getAuthorityId()));
        }

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

        this.finishXRD(
View Full Code Here

        domParser.parse(new InputSource(new FileInputStream(xridFile)));

        Document xridDoc = domParser.getDocument();

        return new XRD(xridDoc.getDocumentElement(), true);

    } // loadXRID()
View Full Code Here

TOP

Related Classes of org.openxri.xml.XRD

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.