Package org.openxri.xml

Examples of org.openxri.xml.XRDS


  }

    
    protected XRDS readXRDS(InputStream in) throws XRIResolutionException
  {
      XRDS xrds = null;
 
      if (in == null)
      {
          return xrds;
      }
 
      // Read response into DOM structure
      try
      {
          DOMParser domParser = DOMUtils.getDOMParser();
          domParser.parse(new InputSource(in));
          Document doc = domParser.getDocument();
 
          // XRDS
          Element element = doc.getDocumentElement();
 
          log.debug("Successfully read XRI Descriptor into DOM");
 
          // Populate the cache and store the Descriptors from the response
          xrds = new XRDS(element, true);
      }
      catch (IOException e)
      {
          throw new XRIResolutionException("IOException", e);
      }
View Full Code Here


        resolver.setAuthority("!", bangRoot);
        resolver.setProxyURI(URI.create("http://localhost:8080/"));
       
        ResolverState state = new ResolverState();
       
        XRDS xrds = null;
        try {
          // xrds = resolver.resolveAuthToXRDS("=", new TrustType(), true);
        // xrds = resolver.resolveAuthToXRDS("@trung", new TrustType(), true);
        //xrds = resolver.resolveAuthToXRDS("@trung*phone", new TrustType(), true);
        // xrds = resolver.resolveAuthToXRDS("@a*b*c", new TrustType(), true);
View Full Code Here

    boolean signed = checkSigned(request);

    // the goal is to get a complete XRDS document

    XRDS xrds = null;

    // let our URIMapper tell us what to do

    URIMapperResult data = this.uriMapper.parseRequest(new URIMapperRequest(request));

    String namespace = (data == null) ? null : data.getNamespace();
    String query = (data == null) ? null : data.getQuery();

    if (namespace != null && namespace.trim().equals("")) namespace = null;
    if (query != null && query.trim().equals("")) query = null;

    String path = request.getRequestURI().substring(request.getContextPath().length() + 1);

    // use the Server to get an XRDS

    try {

      // got a namespace but no query? that means the client wants a self-describing XRDS

      if (namespace != null && query == null) {

        // ask the Server to give us a self-describing XRDS for the namespace

        log.debug("Looking up self-describing descriptor.");

        xrds = this.server.lookupSelfDescribing(namespace, signed);
      }

      // got a namespace and a query? that means the client wants normal authority resolution

      if (namespace != null && query != null) {

        // ask the Server to give us an XRDS for the namespace and query

        log.debug("Looking up descriptor by namespace and query.");

        xrds = this.server.lookupByNamespace(namespace, query, signed);
      }

      // got neither a namespace nor a query? try getting an XRDS by path

      if (namespace == null && query == null) {

        // ask the Server to give us an XRDS for the path

        log.debug("Looking up descriptor by path.");

        xrds = this.server.lookupByPath(path, signed);
      }
    } catch (Exception ex) {

      log.warn("Internal server problem during resolution.", ex);
      response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, ex.getMessage());
      return;
    }

    // if we were not able to get an XRDS, let the plugin handle the request

    if (xrds == null || xrds.getNumXRD() < 1) {

      if (this.plugin == null) {

        log.warn("No plugin installed.");
        response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Invalid request.");
        return;
      }

      log.debug("Forwarding request to plugin.");

      boolean ret = this.plugin.processCustomRequest(request, response);

      // did the plugin handle the request?

      if (ret == true) {

        log.debug("Plugin successfully handled the request.");
        return;
      } else {

        log.warn("Plugin failed to handle the request.");
        response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Plugin failed to handle the request.");
        return;
      }
    }

    // send out the result

    String body = xrds.serializeDescriptorDOM(false, true);

    log.debug("Resolution successful. Sending descriptor.");
    response.setStatus(HttpServletResponse.SC_OK);
   
    if (xrds.getFinalXRD().getSAMLAssertion() != null)
      response.setContentType(Tags.CONTENT_TYPE_XRDS + ";saml=true;charset=UTF-8");
    else
      response.setContentType(Tags.CONTENT_TYPE_XRDS + ";charset=UTF-8");

    response.getOutputStream().write(body.getBytes("UTF-8"));
View Full Code Here

    flags.setNoDefaultM(nodefault_m);
    flags.setNoDefaultP(nodefault_p);
    flags.setNoDefaultT(nodefault_t);

    // resolve
    XRDS xrds = null;
    XRD xrd = null;
    try
    {
      if (sep) {
        if (resMediaType == null) {
          // see section 7.6 for special redirect rule
          //          ArrayList<?> uris = this.resolver.resolveSEPToURIList(oXRI.toString(), trustType, serviceType, serviceMediaType, refs);
          ArrayList<?> uris = this.resolver.resolveSEPToURIList(oXRI, serviceType, serviceMediaType, flags, state);
          if (uris == null || uris.size() == 0) {
            sendError(request, response, qxri, 241, "SEP_NOT_FOUND(code=241): no url found", null);
            return;
          }
          String s = (String) uris.get(0);
          if (onResolutionSuccess(qxri, state, s, request, response)) {
            log.trace("processProxyRequest - onResolutionSuccess returned true, assuming request is fully handled, returning");
            return;
          }
          log.trace("Sending redirect to '" + s + "'");
          if (this.config.getSetting("RedirectCode").equals("301"))
            send301(response, s);
          else if (this.config.getSetting("RedirectCode").equals("303"))
            send303(response, s);
          else
            response.sendRedirect(s);
        }
        else if (resMediaType.isType(MimeType.URI_LIST)) {
          //          String  text = this.resolver.resolveSEPToTextURIList(oXRI.toString(), trustType, serviceType, serviceMediaType, refs);
          String text = this.resolver.resolveSEPToTextURIList(oXRI, serviceType, serviceMediaType, flags, state);
          if (onResolutionSuccess(qxri, state, text, request, response)) {
            log.trace("processProxyRequest - onResolutionSuccess returned true, assuming request is fully handled, returning");
            return;
          }
          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 = this.resolver.resolveSEPToXRDS(oXRI, trustType, serviceType, serviceMediaType, refs);
          xrds = this.resolver.resolveSEPToXRDS(oXRI, serviceType, serviceMediaType, flags, state);
          if (onResolutionSuccess(qxri, state, xrds, request, response)) {
            log.trace("processProxyRequest - onResolutionSuccess returned true, assuming request is fully handled, returning");
            return;
          }
          sendResponse(response, debug, resMediaType.getType(), xrds.toString(), trustType);
        }
        else if (resMediaType.isType(MimeType.XRD_XML)) {
          //          xrd = this.resolver.resolveSEPToXRD(oXRI, trustType, serviceType, serviceMediaType, refs);
          xrd = this.resolver.resolveSEPToXRD(oXRI, serviceType, serviceMediaType, flags, state);
          if (onResolutionSuccess(qxri, state, xrd, request, response)) {
            log.trace("processProxyRequest - onResolutionSuccess returned true, assuming request is fully handled, returning");
            return;
          }
          sendResponse(response, debug, 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 = this.resolver.resolveAuthToXRDS(oXRI, trustType, refs);
          xrds = this.resolver.resolveAuthToXRDS(oXRI, flags, state);
          if (onResolutionSuccess(qxri, state, xrds, request, response)) {
            log.trace("processProxyRequest - onResolutionSuccess returned true, assuming request is fully handled, returning");
            return;
          }
          sendResponse(response, debug, resMediaType.getType(), xrds.toString(), trustType);
          return;
        }
        else if (resMediaType.isType(MimeType.XRD_XML)) {
          //          xrd = this.resolver.resolveAuthToXRD(oXRI, trustType, refs);
          xrd = this.resolver.resolveAuthToXRD(oXRI, flags, state);
View Full Code Here

      TrustType trustType)
  throws IOException
  {
    log.trace("sendPartialResponse(debug=" + isDebug + ", partialXRDS=" + pre.getPartialXRDS().toString());

    XRDS partialXRDS = pre.getPartialXRDS();
    if (this.bareXRINotFoundRedirect != null) {
      if (resMediaType == null & partialXRDS.getFinalXRD().getStatusCode().equals(Status.QUERY_NOT_FOUND)) {
        response.sendRedirect(this.bareXRINotFoundRedirect + URLEncoder.encode(qxri, "UTF-8"));
        return;
      }
    }
    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) {
      sendError(request, response, qxri, Integer.parseInt(xrd.getStatus().getCode()), errMsg, pre);
    }
    else {
      if (this.onPartialResolutionSuccess(qxri, request, response, Integer.parseInt(xrd.getStatus().getCode()), errMsg, pre)) {
        log.trace("sendPartialResponse - onPartialResolutionSuccess returned true, assuming request is fully handled, returning");
        return;
      }
      if (resMediaType.isType(MimeType.URI_LIST)) {
        sendResponse(response, HTTP_ERROR_CONTENT_TYPE, "# " + errMsg, trustType);
      }
      else if (resMediaType.isType(MimeType.XRDS_XML)) {
        sendResponse(response, isDebug, resMediaType.getType(), partialXRDS.toString(), trustType);
      }
      else if (resMediaType.isType(MimeType.XRD_XML)) {
        sendResponse(response, isDebug, resMediaType.getType(), xrd.toString(), trustType);
      }
      else {
View Full Code Here

    boolean signed = checkSigned(request);

    // the goal is to get a complete XRDS document

    XRDS xrds = null;

    // let our URIMapper tell us what to do

    URIMapperResult data = this.uriMapper.parseRequest(new URIMapperRequest(request));

    String namespace = (data == null) ? null : data.getNamespace();
    String query = (data == null) ? null : data.getQuery();

    if (namespace != null && namespace.trim().equals("")) namespace = null;
    if (query != null && query.trim().equals("")) query = null;

    String path = request.getRequestURI().substring(request.getContextPath().length() + 1);

    // use the Server to get an XRDS

    try {

      // got a namespace but no query? that means the client wants a self-describing XRDS

      if (namespace != null && query == null) {

        // ask the Server to give us a self-describing XRDS for the namespace

        log.debug("Looking up self-describing descriptor.");

        xrds = this.server.lookupSelfDescribing(namespace, signed);
      }

      // got a namespace and a query? that means the client wants normal authority resolution

      if (namespace != null && query != null) {

        // ask the Server to give us an XRDS for the namespace and query

        log.debug("Looking up descriptor by namespace and query.");

        xrds = this.server.lookupByNamespace(namespace, query, signed);
      }

      // got neither a namespace nor a query? try getting an XRDS by path

      if (namespace == null && query == null) {

        // ask the Server to give us an XRDS for the path

        log.debug("Looking up descriptor by path.");

        xrds = this.server.lookupByPath(path, signed);
      }
    } catch (Exception ex) {

      log.warn("Internal server problem during resolution.", ex);
      response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, ex.getMessage());
      return;
    }

    // if we were not able to get an XRDS, let the plugin handle the request

    if (xrds == null || xrds.getNumXRD() < 1) {

      if (this.plugin == null) {

        log.warn("No plugin installed.");
        response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Invalid request.");
        return;
      }

      log.debug("Forwarding request to plugin.");

      boolean ret = this.plugin.processCustomRequest(request, response);

      // did the plugin handle the request?

      if (ret == true) {

        log.debug("Plugin successfully handled the request.");
        return;
      } else {

        log.warn("Plugin failed to handle the request.");
        response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Plugin failed to handle the request.");
        return;
      }
    }

    // send out the result

    String body = xrds.toString();

    log.debug("Resolution successful. Sending descriptor.");
    response.setStatus(HttpServletResponse.SC_OK);
    response.setContentType(Tags.CONTENT_TYPE_XRDS + "; charset=UTF-8");
    response.getOutputStream().write(body.getBytes("UTF-8"));
View Full Code Here

        }
      }
    }

    // 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);
View Full Code Here

        TrustType trustType = new TrustType(TrustType.TRUST_NONE);
        boolean followRefs = true;
       
        // note: See also Resolver.resolve
        // resolver.setLookaheadMode(true);
        XRDS xrds = resolver.resolveAuthToXRDS(msTargetXRI, trustType, followRefs);
//        ResolveInfo oResolveInfo = resolver.resolveAuth(msTargetXRI, trustType, followRefs);
       
        // The non-verbose format is as follows:
        //
        // xri://@community*member*family 
View Full Code Here

      throw ex;
    }

    // the big goal is to make an XRDS, consisting of one XRD

    XRDS xrds = new XRDS();
    boolean ret;

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

    ret = this.initXRDS(
        xrds,
        namespace,
        signed);

    // if a subclass returned true, it doesn't want us to do any more work

    if (ret == true) {

      log.debug("Subclass handled XRDS completely. Returning it without any more work.");
      return(xrds);
    }

    // generate an XRD for the namespace

    for (int i=0; i<1; i++) {

      try {

        // create a fresh XRD

        XRD xrd = new XRD();

        // give subclasses a chance to init the XRD

        ret = this.initXRD(
            xrd,
            namespaceAuthority,
            namespace,
            signed);

        // if a subclass returned true, it doesn't want us to do any more work

        if (ret == true) {

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

        // check if the authority overrides the LOOKUP pipeline. if not, use the default.

        PipelineRegistry pipelineRegistry = (this.serverConfig == null) ? null : this.serverConfig.getPipelineRegistry();
        Pipeline lookupPipeline = null;

        if (this.store instanceof StoreAttributable) {

          StoreAttributable storeAttributable = (StoreAttributable) this.store;

          String pipelineName = storeAttributable.getAuthorityAttributes(namespaceAuthority).get(Pipeline.ATTRIBUTE_OVERRIDE_LOOKUP_PIPELINE);
          if (pipelineRegistry != null && pipelineName != null) lookupPipeline = pipelineRegistry.getPipelineByName(pipelineName);
        }

        if (pipelineRegistry != null && lookupPipeline == null) lookupPipeline = pipelineRegistry.getDefaultLookupPipeline();

        // execute LOOKUP pipeline

        xrd = lookupPipeline.execute(
            this.store,
            xrd,
            null,
            null,
            namespace,
            namespaceAuthority,
            false);

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

        if (xrd != null) {

          this.finishXRD(
              xrd,
              namespaceAuthority,
              null,
              null,
              signed);
        }

        // if we were not able to get a XRD, return a "not found" XRD

        if (xrd == null) {

          xrds.add(makeNotFoundXrd(namespace));
          break;
        }

        // append XRD to the XRDS

        xrds.add(xrd);
      } catch (Exception ex) {

        log.error("", ex);
        xrds.add(makeExceptionXrd(namespace, ex));
        break;
      }
    }

    // let subclasses finish the XRDS before we send it out
View Full Code Here

      throw ex2;
    }

    // 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,
        query,
        signed);

    // if a subclass returned true, it doesn't want us to do any more work

    if (ret == true) {

      log.debug("Subclass handled XRDS completely. Returning it without any more work.");
      return(xrds);
    }

    // generate XRDs for all subsegments in the request

    String utf8Query;

    try {

      utf8Query = IRIUtils.IRItoXRI(IRIUtils.URItoIRI(query));
    } catch (Exception ex) {

      ServerException ex2 = new ServerInternalException("Unsupported encoding in query: " + ex.getMessage(), ex);
      log.warn("", ex2);
      throw ex2;
    }

    XRISegment segment = new XRISegment(utf8Query);

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

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

      try {

        // create a fresh XRD

        XRD xrd = new XRD();

        // using the parent authority and subsegment name, find the subsegment and the authority we are describing now
        // we must be prepared to have null values here, since not all pipeline configurations
        // may use objects from the store

        SubSegment subSegment = null;
        Authority authority = null;

        if (parentAuthority != null) subSegment = this.store.findSubSegment(parentAuthority, subSegmentName);
        if (subSegment != null) authority = this.store.getSubSegmentAuthority(subSegment);

        // give subclasses a chance to init the XRD

        ret = this.initXRD(
            xrd,
            parentAuthority,
            subSegmentName,
            signed);

        // if a subclass returned true, it doesn't want us to do any more work

        if (ret == true) {

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

        // check if the parent authority overrides the LOOKUP pipeline. if not, use the default.

        PipelineRegistry pipelineRegistry = (this.serverConfig == null) ? null : this.serverConfig.getPipelineRegistry();
        Pipeline lookupPipeline = null;

        if (this.store instanceof StoreAttributable) {

          StoreAttributable storeAttributable = (StoreAttributable) this.store;

          String pipelineName = storeAttributable.getAuthorityAttributes(parentAuthority).get(Pipeline.ATTRIBUTE_OVERRIDE_LOOKUP_PIPELINE);
          if (pipelineRegistry != null && pipelineName != null) lookupPipeline = pipelineRegistry.getPipelineByName(pipelineName);
        }

        if (pipelineRegistry != null && lookupPipeline == null) lookupPipeline = pipelineRegistry.getDefaultLookupPipeline();

        // execute LOOKUP pipeline

        xrd = lookupPipeline.execute(
            this.store,
            xrd,
            segment,
            parentAuthority,
            subSegmentName,
            authority,
            false);

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

        if (xrd != null) {

          this.finishXRD(
            xrd,
            parentAuthority,
            subSegment,
            authority,
            signed);
        }

        // if we were not able to get a XRD, that's ok if we found at least one before
        // (we are not necessarily authoritative for the whole query)

        if (xrd == null) {

          if (i > 0) {

            break;
          } else {

            xrds.add(makeNotFoundXrd(subSegmentName));
            break;
          }
        }

        // authority becomes the parent authority for the next subsegment

        parentAuthority = authority;
        if (subSegment != null) setParentQueryName(subSegment.getName());

        // append XRD to the XRDS

        xrds.add(xrd);
      } catch (Exception ex) {

        log.error("", ex);
        xrds.add(makeExceptionXrd(subSegmentName, ex));
        break;
      }
    }

    // let subclasses finish the XRDS before we send it out
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.