Exemplo n.º 1
0
 @Override
 public void handle(Request request, Response response) {
   final StringBuilder sb = new StringBuilder();
   final RouteList routers = router.getRoutes();
   final String prefix =
       request.getOriginalRef().getPath().endsWith("/")
           ? ""
           : request.getOriginalRef().getPath() + "/";
   final boolean detailed =
       request.getOriginalRef().getQueryAsForm().getNames().contains("describe");
   sb.append("<div>");
   if (detailed) {
     String href = request.getOriginalRef().getPath();
     sb.append("<a href='" + href + "'>[Less Detail]</a>");
   } else {
     sb.append("<a href='?describe'>[More Detail]</a>");
   }
   sb.append("<ul>");
   for (int i = 0; i < routers.size(); i++) {
     Route r = routers.get(i);
     if (!detailed && r.getTemplate().getVariableNames().size() > 0) {
       continue;
     }
     String pattern = r.getTemplate().getPattern();
     if (pattern.length() > 0) {
       pattern = pattern.substring(1);
       if (pattern.length() > 0) {
         sb.append("<li>");
         sb.append("<a href='" + prefix + pattern + "'>" + pattern + "</a>");
         if (detailed) {
           Restlet next = r.getNext();
           Class dest = null;
           if (next instanceof Finder) {
             dest = ((Finder) next).getTargetClass();
           } else if (next instanceof Guard) {
             Guard g = (Guard) next;
             if (g.getNext() instanceof Finder) {
               dest = ((Finder) g.getNext()).getTargetClass();
             } else {
               dest = g.getNext().getClass();
             }
           }
           if (dest != null) {
             sb.append("<span> [").append(dest.getName()).append(" ]</span>");
           }
           try {
             String description = findDescription(dest);
             if (description != null) {
               sb.append("<div>").append(description).append("</div>");
             }
           } catch (Exception ex) {
             getLogger().log(Level.SEVERE, "Error getting description", ex);
           }
         }
         sb.append("</li>");
       }
     }
   }
   sb.append("</ul>");
   sb.append(
       "PSCP API, Version " + Version.getVersion() + ", Created " + Version.getVersionDate());
   sb.append("</div>");
   response.setEntity(sb.toString(), MediaType.TEXT_HTML);
 }
  /**
   * Centralized way to create ResourceStoreRequests, since we have to fill in various things in
   * Request context, like authenticated username, etc.
   *
   * @param isLocal
   * @return
   */
  protected ArtifactStoreRequest getResourceStoreRequest(
      Request request,
      boolean localOnly,
      String repositoryId,
      String g,
      String a,
      String v,
      String p,
      String c,
      String e)
      throws ResourceException {
    if (StringUtils.isBlank(p) && StringUtils.isBlank(e)) {
      // if packaging and extension is both blank, it is a bad request
      throw new ResourceException(
          Status.CLIENT_ERROR_BAD_REQUEST,
          "Deployment tried with both 'packaging' and/or 'extension' being empty! One of these values is mandatory!");
    }

    MavenRepository mavenRepository = getMavenRepository(repositoryId);

    // if extension is not given, fall-back to packaging and apply mapper
    if (StringUtils.isBlank(e)) {
      e = mavenRepository.getArtifactPackagingMapper().getExtensionForPackaging(p);
    }

    // clean up the classifier
    if (StringUtils.isBlank(c)) {
      c = null;
    }

    Gav gav = null;

    try {
      gav =
          new Gav(
              g,
              a,
              v,
              c,
              e,
              null,
              null,
              null,
              VersionUtils.isSnapshot(v),
              false,
              null,
              false,
              null);
    } catch (IllegalArtifactCoordinateException ex) {
      throw new ResourceException(
          Status.CLIENT_ERROR_BAD_REQUEST, "Illegal artifact coordinate.", ex);
    }

    ArtifactStoreRequest result = new ArtifactStoreRequest(mavenRepository, gav, localOnly);

    if (getLogger().isDebugEnabled()) {
      getLogger().debug("Created ArtifactStoreRequest request for " + result.getRequestPath());
    }

    // stuff in the originating remote address
    result
        .getRequestContext()
        .put(AccessManager.REQUEST_REMOTE_ADDRESS, getValidRemoteIPAddress(request));

    // stuff in the user id if we have it in request
    if (request.getChallengeResponse() != null
        && request.getChallengeResponse().getIdentifier() != null) {
      result
          .getRequestContext()
          .put(AccessManager.REQUEST_USER, request.getChallengeResponse().getIdentifier());
    }

    // this is HTTPS, get the cert and stuff it too for later
    if (request.isConfidential()) {
      result.getRequestContext().put(AccessManager.REQUEST_CONFIDENTIAL, Boolean.TRUE);

      List<?> certs = (List<?>) request.getAttributes().get("org.restlet.https.clientCertificates");

      if (certs != null) {
        result.getRequestContext().put(AccessManager.REQUEST_CERTIFICATES, certs);
      }
    }

    // put the incoming URLs
    result.setRequestAppRootUrl(getContextRoot(request).toString());
    result.setRequestUrl(request.getOriginalRef().toString());

    return result;
  }