Examples of XRD


Examples of org.openxri.xml.XRD

        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

Examples of org.openxri.xml.XRD

            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

Examples of org.openxri.xml.XRD

        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

Examples of org.openxri.xml.XRD

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

Examples of org.openxri.xml.XRD

      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

Examples of org.openxri.xml.XRD

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

        Document xridDoc = domParser.getDocument();

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

    } // loadXRID()
View Full Code Here

Examples of org.openxri.xml.XRD

      final Store openXRIStore = ((OpenXRIAdminApplication) this.getApplication()).getOpenXRIStore();
      final Resolver resolver = ((OpenXRIAdminApplication) this.getApplication()).getResolver();

      try {

        SubSegment rootSubSegment = openXRIStore.createRootSubSegment(this.namespace, new XRD());

        CanonicalID canonicalID;
        Authority authority;

        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;
          authority = null;
        }

        if (canonicalID != null && authority != null && ! canonicalID.getValue().equals(this.namespace)) {

          XRD xrd = authority.getXrd();
          xrd.setCanonicalID(new CanonicalID(canonicalID.getValue()));

          ((StoreEditable) openXRIStore).setXrd(authority, xrd);
          openXRIStore.registerSubsegment(null, canonicalID.getValue(), authority);
        }
      } catch (StoreException ex) {
View Full Code Here

Examples of org.openxri.xml.XRD

      }
    }

    // set the request preferences on the resolver before querying.
    XRDS xrds = null;
    XRD xrd = null;
    try
    {
      if (sep) {
        if (resMediaType == null) {
          // see section 7.6 for special redirect rule
          ArrayList uris = resolver.resolveSEPToURIList(oXRI.toString(), trustType, serviceType, serviceMediaType, refs);
          if (uris == null || uris.size() == 0) {
            sendResponse(response, HTTP_ERROR_CONTENT_TYPE, "SEP_NOT_FOUND(code=241): no url found", null);
            return;
          }
          String s = (String) uris.get(0);

          log.trace("Sending redirect to '" + s + "'");

          response.sendRedirect(s);
        }
        else if (resMediaType.isType(MimeType.URI_LIST)) {
          String  text = resolver.resolveSEPToTextURIList(oXRI.toString(), trustType, serviceType, serviceMediaType, refs);
          if (text.length() <= 0)
            sendResponse(response, HTTP_ERROR_CONTENT_TYPE, "SEP_NOT_FOUND(code=241): no url found", null);
          else
            sendResponse(response, resMediaType.getType(), text, null);
        }
        else if (resMediaType.isType(MimeType.XRDS_XML)) {
          xrds = resolver.resolveSEPToXRDS(oXRI, trustType, serviceType, serviceMediaType, refs);
          sendResponse(response, isDumbBrowser, resMediaType.getType(), xrds.toString(), trustType);
        }
        else if (resMediaType.isType(MimeType.XRD_XML)) {
          xrd = resolver.resolveSEPToXRD(oXRI, trustType, serviceType, serviceMediaType, refs);
          sendResponse(response, isDumbBrowser, resMediaType.getType(), xrd.toResultString(), trustType);
        }
        else {
          // else - we should have taken care of it in checkSupportedMediaTypes
          log.error("processProxyRequest - should not reach here (sep=true)");
        }
      }
      else {
        //// authority resolution only
        if(resMediaType == null) {
          resMediaType = new MimeType(MimeType.XRDS_XML);
        }

        if (resMediaType.isType(MimeType.XRDS_XML)) {
          xrds = resolver.resolveAuthToXRDS(oXRI, trustType, refs);
          sendResponse(response, isDumbBrowser, resMediaType.getType(), xrds.toString(), trustType);
          return;
        }
        else if (resMediaType.isType(MimeType.XRD_XML)) {
          xrd = resolver.resolveAuthToXRD(oXRI, trustType, refs);
          sendResponse(response, isDumbBrowser, resMediaType.getType(), xrd.toString(), trustType);
        }
        else if (resMediaType.isType(MimeType.URI_LIST)) {
          // ignore (must do SEP when text/uri-list is specified)
          log.warn("text/uri-list given but does not want to do service selection");
          // TODO: do we return an error?
View Full Code Here

Examples of org.openxri.xml.XRD

  throws IOException
  {
    log.trace("sendPartialResponse(dumbBrowser=" + isDumbBrowser + ", partialXRDS=" + partialXRDS.toString());

    response.setStatus(HttpServletResponse.SC_OK);
    XRD xrd = partialXRDS.getFinalXRD();
    String errMsg = "";
    if (xrd != null) {
      Status stat = xrd.getStatus();
      errMsg = "Error code: " + stat.getCode() + " - " + stat.getText();
    }

    if (resMediaType == null) {
      sendResponse(response, HTTP_ERROR_CONTENT_TYPE, errMsg, null);
    }
    else if (resMediaType.isType(MimeType.URI_LIST)) {
      errMsg = "# " + errMsg;
      sendResponse(response, HTTP_ERROR_CONTENT_TYPE, errMsg, trustType);
    }
    else if (resMediaType.isType(MimeType.XRDS_XML)) {
      sendResponse(response, isDumbBrowser, resMediaType.getType(), partialXRDS.toString(), trustType);
    }
    else if (resMediaType.isType(MimeType.XRD_XML)) {
      sendResponse(response, isDumbBrowser, resMediaType.getType(), xrd.toString(), trustType);
    }
    else {
      // else - we should have taken care of it in checkSupportedMediaTypes
      log.error("processProxyRequest - should not reach here (exception)");
    }
View Full Code Here

Examples of org.openxri.xml.XRD

        // resolve valid but non-existing xri
        //
        try
        {
            String sXRI = "xri://@gates*com";
            XRD oDesc =
                oResolver.resolveAuthToXRD(new XRI(sXRI), new TrustType(), false);
            assertTrue("Thought " + sXRI + " did not exist.", oDesc == null);
        }
        catch (PartialResolutionException e) {
          // ok
        }
        catch (Exception E)
        {
            E.printStackTrace();
            assertTrue("Unexpected " + E, false);
        }

        //
        // resolve existing xri
        //
        try
        {
            String sXRI = "xri://@foo";
            XRD oDesc =
                oResolver.resolveAuthToXRD(new XRI(sXRI), new TrustType(), false);
            assertTrue("Thought " + sXRI + " exists.", oDesc != null);
            assertTrue("Invalid XRD Query", oDesc.getQuery().equals("*foo"));
        }
        catch (Exception E)
        {
            E.printStackTrace();
            assertTrue("Unexpected " + E, false);
        }

        //
        // resolve nonexistent segment
        //
        try
        {
            String sXRI = "xri://@foo*bar";
            XRD oDesc =
                oResolver.resolveAuthToXRD(new XRI(sXRI), new TrustType(), false);
            assertTrue("Expected PartialResolutionException but not thrown", false);
        }
        catch (PartialResolutionException e) {
          // ok
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.