Package org.openxri.xml

Examples of org.openxri.xml.XRDS


      Resolver resolver = setupResolver();
      qxri = "@xrid*test*live.unit.tests*0002-ref";
      XRI xri = XRI.fromIRINormalForm(qxri);
     
      ResolverFlags flags = new ResolverFlags();
      XRDS xrds = resolver.resolveAuthToXRDS(xri, flags, new ResolverState());
      assertTrue("There should be 5 child elements", xrds.getNumChildren() == 5);
      assertTrue("The last child should be an XRDS element because it followed a Ref", xrds.isXRDSAt(4));
    }
    catch (PartialResolutionException e) {
      fail("Not expecting PRE. PartialXRDS=" + e.getPartialXRDS());
    }
    catch (Exception e) {
View Full Code Here


    try {
      Resolver resolver = setupResolver();
      XRI xri = XRI.fromIRINormalForm(qxri);
     
      ResolverFlags flags = new ResolverFlags();
      XRDS xrds = resolver.resolveSEPToXRDS(xri, null, null, flags, new ResolverState());
      System.out.println(xrds);
      assertTrue("There should be 8 child elements", xrds.getNumChildren() == 8);
      assertTrue("The first child should be an XRD element", xrds.isXRDAt(0));
      assertTrue("The second child should be an XRD element", xrds.isXRDAt(1));
      assertTrue("The third child should be an XRD element", xrds.isXRDAt(2));
      assertTrue("The fourth child should be an XRD element", xrds.isXRDAt(3));

      assertTrue("The fifth child should be an XRDS element because it followed a Redirect", xrds.isXRDSAt(4));
      XRDS redirXRDS = xrds.getXRDSAt(4);
      assertTrue("Wrong redirect followed in the fifth child", redirXRDS.getRedirect().equals("http://auth.xrid.net/!330/"));
     
      assertTrue("The fifth child should have 2 children", redirXRDS.getNumChildren() == 2);
      assertTrue("The fifth child's first child should be an XRD", redirXRDS.isXRDAt(0));
      assertTrue("The fifth child's second child should be an XRDS", redirXRDS.isXRDSAt(1));
      redirXRDS = redirXRDS.getXRDSAt(1);
      assertTrue("Wrong redirect followed in the fifth child's second child", redirXRDS.getRedirect().equals("http://does.not.exist/"));
      assertFalse("Fifth child should have failed", redirXRDS.getFinalXRD().getStatusCode().equals(Status.SUCCESS));
     
      assertTrue("The sixth child should be an XRDS element because it followed a Redirect", xrds.isXRDSAt(5));
      redirXRDS = xrds.getXRDSAt(5);
      assertTrue("Wrong redirect followed in the sixth child", redirXRDS.getRedirect().equals("http://auth.xrid.net/!333/"));
     

      assertTrue("The seventh child should be an XRDS element because it followed a Redirect", xrds.isXRDSAt(6));
      redirXRDS = xrds.getXRDSAt(6);
      assertTrue("Wrong redirect followed on the seventh child", redirXRDS.getRedirect().equals("http://auth.xrid.net/!331/"));
      assertTrue("Seventh child should have succeeded", redirXRDS.getFinalXRD().getStatusCode().equals(Status.SUCCESS));
     
      assertTrue("The eighth child should be an XRDS element because it followed a Service-level Redirect", xrds.isXRDSAt(7));
      redirXRDS = xrds.getXRDSAt(7);
      assertTrue("Wrong redirect followed on the eighth child", redirXRDS.getRedirect().equals("http://auth.xrid.net/!332/"));
      assertTrue("Eighth child should have succeeded", redirXRDS.getFinalXRD().getStatusCode().equals(Status.SUCCESS));
      assertTrue("Should be one selected Service on eighth child", redirXRDS.getFinalXRD().getSelectedServices().getList().size() == 1);
      Service srv = (Service)redirXRDS.getFinalXRD().getSelectedServices().getList().get(0);
      assertTrue("In correct URI in selected service on eighth child", srv.getURIAt(0).getUriString().equals("http://my.blog.com"));
    }
    catch (Exception e) {
      e.printStackTrace();
      fail("Not expecting exception: " + e);
View Full Code Here

            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

                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

  {
    if (soLog.isDebugEnabled()) soLog.debug("lookupByAuthority(" + parent.getAuthorityId() + "," + segment.toString() + ")");

    // the big goal is to make an XRDS, consisting of one or more XRDs

    XRDS xrds = new XRDS();
    boolean ret;

    // give subclasses a chance to init the XRDS before we begin

    ret = this.initXRDS(
        xrds,
        segment,
        bSigned);

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

    if (ret == true) {
     
      soLog.debug("Subclass handled XRDS completely. Returning it without any more work.");
      return(xrds);
    }

    // generate XRDs for all subsegments in the request

    for (int i=0; i<segment.getNumSubSegments(); i++) {

      String subSegmentName = segment.getSubSegmentAt(i).toString();

      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(
            xrd,
            parent,
            subSegment,
            authority,
            bSigned);

        // let authority handlers finish the XRD, if there are any for this authority

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

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

          authorityHandler.finishXRD(
              xrd,
              parent,
              subSegment,
              authority,
              bSigned);
        }

        // append XRD to the XRDS

        xrds.add(xrd);

        // authority becomes the parent authority for the next subsegment

        parent = authority;
      }
View Full Code Here

      Server openXRIServer = ((OpenXRIAdminApplication) Application.get()).getOpenXRIServer();

      try {

        XRDS xrds = openXRIServer.lookupByNamespace(
            this.rootSubSegment.getName(),
            this.query,
            this.signed.booleanValue());

        if (xrds == null) throw new ServerNotFoundException();
View Full Code Here

      Server openXRIServer = ((OpenXRIAdminApplication) Application.get()).getOpenXRIServer();

      try {

        XRDS xrds = openXRIServer.lookupSelfDescribing(
            this.rootSubSegment.getName(),
            this.signed.booleanValue());

        if (xrds == null) throw new ServerNotFoundException();
       
View Full Code Here

        }

        String content = null;
        try
        {
          XRDS xrds = moResolver.resolveAuthToXRDS(oXRI, new TrustType(), true);
          content = xrds.toString();
        }
        catch (Exception e)
        {
          if (e instanceof PartialResolutionException) {
            content = ((PartialResolutionException)e).getPartialXRDS().toString();
View Full Code Here

      return;
    }

    // let the server do the lookup and create a complete XRD/XRDS descriptor

    XRDS descriptor = null;

    try {

      if (namespace != null) {

        if (soLog.isDebugEnabled()) soLog.debug("Looking up authority by namespace.");

        descriptor = moServer.lookupByNamespace(namespace, segment, bSigned);
      } else if (authorityId != null) {

        if (soLog.isDebugEnabled()) soLog.debug("Looking up authority by ID.");

        descriptor = moServer.lookupById(authorityId, segment, bSigned);
      }
    } catch(ServerException ex) {

      soLog.warn("Problem during resolution.", ex);
      response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
      return;
    }

    // hopefully we got a result

    if (descriptor != null) {

      if (soLog.isDebugEnabled()) soLog.debug("Resolution successful. Sending descriptor.");
      response.setStatus(HttpServletResponse.SC_OK);
      response.setContentType(Tags.CONTENT_TYPE_XRDS);
      response.getWriter().write(descriptor.toString());
      return;
    } else {

      if (soLog.isDebugEnabled()) soLog.debug("Resolution unsuccessful. Sending 404.");
      response.sendError(HttpServletResponse.SC_NOT_FOUND);
View Full Code Here

        try {

          authority = openXRIStore.getSubSegmentAuthority(rootSubSegment);

          XRDS xrds = resolver.resolveAuthority(new XRI(this.namespace), new ResolverFlags(), new ResolverState());
          XRD xrd = (xrds != null) ? xrds.getFinalXRD() : null;
          canonicalID = (xrd != null) ? xrd.getCanonicalID() : null;
        } catch (Exception ex) {

          log.warn("Cannot find corresponding i-number");
          canonicalID = null;
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.