Package org.openxri.xml

Examples of org.openxri.xml.XRDS


   */
  private XrdRepresentations fetchXrd(URI uri) throws FetchException {

    FetchRequest request = FetchRequest.createGetRequest(uri);

    XRDS xrds;
    byte[] documentBytes;
    String signature;

    try {
      FetchResponse response = httpFetcher.fetch(request);

      documentBytes = response.getContentAsBytes();
      signature = response.getFirstHeader("Signature"); // could be null

      Document document =
          XmlUtil.getDocument(new ByteArrayInputStream(documentBytes));

      xrds = new XRDS(document.getDocumentElement(), false);

    } catch (ParserConfigurationException e) {
      throw new FetchException(e);
    } catch (SAXException e) {
      throw new FetchException(e);
    } catch (IOException e) {
      throw new FetchException(e);
    } catch (URISyntaxException e) {
      throw new FetchException(e);
    } catch (ParseException e) {
      throw new FetchException(e);
    }

    return new XrdRepresentations(xrds.getFinalXRD(), uri.toASCIIString(),
        documentBytes, signature);
  }
View Full Code Here


 
 
  protected XRDS processRefs(XRD parent, ResolverFlags flags, ResolverState state)
    throws PartialResolutionException
  {
    XRDS xrdsOut = new XRDS();
    //// get all the Refs in the parent XRD
    List refs = parent.getPrioritizedRefs();
    Iterator it = refs.iterator();
   
    //// try each one in turn
    while (it.hasNext()) {
      Ref ref = (Ref)it.next();

      checkMaxRefs(xrdsOut, ref.getValue(), state);

      XRI refXRI;
      try {
        refXRI = parseAbsoluteQXRIOrError(ref.getValue());
      }
      catch (PartialResolutionException e) {
        xrdsOut.add(e.getPartialXRDS());
        continue;
      }
     
      // record that we are following a ref
      state.pushFollowingRef(refXRI);
     
      try {
        XRDS tmpXRDS = resolveAuthority(refXRI, flags, state);
        xrdsOut.add(tmpXRDS);
        break;
      }
      catch (PartialResolutionException e) {
        xrdsOut.add(e.getPartialXRDS());
View Full Code Here

          // construct URI
          String constructedURI = constructURI(uri, r.getAppend(), qxri);
          uri = new URI(constructedURI);
        }
      } catch (URISyntaxException e) {
        XRDS tmpXRDS = new XRDS();
        XRD err = createErrorXRD(r.getValue(), Status.INVALID_REDIRECT, "Invalid Redirect URI");
        tmpXRDS.add(err);
        xrdsOut.add(tmpXRDS);
        continue;
      }
     
      try {
        XRDS tmpXRDS = fetchRedirectXRDS(uri, parent, qxri, flags, state);
        xrdsOut.add(tmpXRDS);
       
        XRD finalXRD = tmpXRDS.getFinalXRD();
        tmpXRDS = new XRDS();
        List services = selectServiceFromXRD(tmpXRDS, finalXRD, qxri, sepType, sepMediaType, flags, state);
        xrdsOut.addAll(tmpXRDS);
        return services; // we're done!
      } catch (XRIResolutionException e) {
        XRDS tmpXRDS = new XRDS();
        XRD err = createErrorXRD(uri.toString(), Status.REDIRECT_ERROR, "Error fetching XRDS: " + e.getMessage());
        tmpXRDS.add(err);
        xrdsOut.add(tmpXRDS);
       
        // fall through to continue to the next
      }
    }
View Full Code Here

     
      // record that we are following a ref
      state.pushFollowingRef(refXRI);
     
      try {
        XRDS tmpXRDS = resolveSEPToXRDS(refXRI, sepType, sepMediaType, flags, state);
        xrdsOut.add(tmpXRDS);
        return tmpXRDS.getFinalXRD().getSelectedServices().getList();
      }
      catch (PartialResolutionException e) {
        xrdsOut.add(e.getPartialXRDS());
        // fall through to continue to the next
      }
View Full Code Here

 
 
  protected XRDS fetchRedirectXRDS(URI uri, XRD parent, XRI qxri, ResolverFlags flags, ResolverState state)
    throws PartialResolutionException
  {
      XRDS xrdsOut = new XRDS();
      String query = qxri.toURINormalForm();
      xrdsOut.setRedirect(uri.toString());
     
      XRDS tmpXRDS = null;
      try {
        log.info("fetchRedirectXRDS - fetching from URI(" + uri + ")");
        InputStream in = getDataFromURI(uri, query, flags, state);
       
        log.info("fetchRedirectXRDS - reading content from URI(" + uri + ")");
        tmpXRDS = readXRDS(in);

        log.debug("fetchRedirectXRDS - got XRDS = " + tmpXRDS.toString());
      } catch (IOException e) {
        log.error("fetchRedirectXRDS - got IOException from URI " + uri);
        throw makeResolutionException(xrdsOut, query, Status.NETWORK_ERROR, "Networking error encountered");
      } catch (Exception e) {
        log.error("fetchRedirectXRDS - unexpected error: " + e);
        e.printStackTrace();
        throw makeResolutionException(xrdsOut, query, Status.AUTH_RES_ERROR, e.getMessage());
      }

      //// sanity checks
     
      // there should be exactly one child element
      if (tmpXRDS.getNumChildren() != 1 || !tmpXRDS.isXRDAt(0)) {
        throw makeResolutionException(xrdsOut, query, Status.INVALID_XRDS, "Invalid XRDS document: single XRD element expected");
      }
     
      if (!tmpXRDS.isXRDAt(0))
        throw makeResolutionException(xrdsOut, query, Status.INVALID_XRDS, "Authority XRDS document should not contain XRDS element");

      XRD xrd = tmpXRDS.getDescriptorAt(0);
      xrdsOut.add(xrd);


      ServerStatus sstat = xrd.getServerStatus();
      Status stat;
View Full Code Here

      return xrdsOut;
  }
 

  protected XRDS readXRDS(InputStream in) throws XRIResolutionException {
    XRDS xrds = null;

    if (in == null) {
      return xrds;
    }

    // Read response into DOM structure
    try {
      log.debug("readXRDS - parsing input stream");
      DOMParser domParser = DOMUtils.getDOMParser();
      domParser.parse(new InputSource(in));
      Document doc = domParser.getDocument();
      Element element = doc.getDocumentElement();
      log.debug("readXRDS - successfully read XML document into DOM");
      xrds = new XRDS(element, true);
      log.debug("readXRDS - successfully parsed XRDS document");
    } catch (IOException e) {
      throw new XRIResolutionException("I/O error while reading XRDS document: " + e, e);
    } catch (SAXException e) {
      throw new XRIResolutionException("Invalid XRDS document: " + e, e);
View Full Code Here

      ResolverState state) throws PartialResolutionException {
    log.trace("resolveAuthToXRDS(s'" + qxri + "', flags: " + flags + ")");
    if (proxyURI != null)
      return resolveViaProxy(qxri, null, null, false, flags, state);

    XRDS xrds = resolveAuthority(qxri, flags, state);
    if (flags.isUric()) {
      constructURIinXRD(xrds.getFinalXRD(), qxri);
    }
    return xrds;
  }
View Full Code Here

  public XRD resolveAuthToXRD(XRI qxri, ResolverFlags flags,
      ResolverState state) throws PartialResolutionException {
    log.trace("resolveAuthToXRD(s'" + qxri + "', flags: " + flags + ")");

    if (proxyURI != null) {
      XRDS xrds = resolveViaProxy(qxri, null, null, false, flags, state);
      return xrds.getFinalXRD();
    }

    XRDS xrds = resolveAuthority(qxri, flags, state);
    XRD finalXRD = xrds.getFinalXRD();
    if (flags.isUric()) {
      constructURIinXRD(finalXRD, qxri);
    }
    return finalXRD;
  }
View Full Code Here

        + ", sepMediaType=" + sepMediaType + ", flags:" + flags + ")");

    if (proxyURI != null)
      return resolveViaProxy(qxri, sepType, sepMediaType, true, flags, state);

    XRDS xrds = resolveAuthority(qxri, flags, state);
    XRD finalXRD = xrds.getFinalXRD();

    selectServiceFromXRD(xrds, finalXRD, qxri, sepType, sepMediaType, flags, state);
    if (flags.isUric()) {
      constructURIinXRD(xrds.getFinalXRD(), qxri);     
    }
    return xrds;
  }
View Full Code Here

      ResolverFlags flags, ResolverState state)
      throws PartialResolutionException {
    log.trace("resolveSEPToXRD('" + qxri + "', sepType=" + sepType
        + ", sepMediaType=" + sepMediaType + ", flags: " + flags + ")");

    XRDS xrds = resolveSEPToXRDS(qxri, sepType, sepMediaType, flags, state);
    return xrds.getFinalXRD();
  }
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.