@Override
 public void setStatus(int status) {
   this.status = status;
   if (HttpUtils.isSuccessfulResponseCode(status) && state == State.UNSET) {
     state = State.SUCCESS;
   }
 }
Ejemplo n.º 2
0
 /**
  * Get the absolute bookmarkable path of a page
  *
  * @param pageClass Page
  * @param pageParameters Optional page parameters
  * @return Bookmarkable path
  */
 public static String absoluteMountPathForPage(
     Class<? extends Page> pageClass, PageParameters pageParameters) {
   HttpServletRequest req = getHttpServletRequest();
   RequestCycle requestCycle = RequestCycle.get();
   Url url = requestCycle.mapUrlFor(pageClass, pageParameters);
   String renderedUrl = url.toString();
   renderedUrl = Strings.isEmpty(renderedUrl) ? "." : renderedUrl;
   return RequestUtils.toAbsolutePath(
       HttpUtils.getWebappContextUrl(req),
       requestCycle.getOriginalResponse().encodeURL(renderedUrl));
 }
 @Override
 public void renderPage() {
   String lastPage = CookieUtils.getCookie(RememberPageBehavior.COOKIE_NAME);
   if (StringUtils.isEmpty(lastPage)) {
     setResponsePage(BrowseRepoPage.class);
   } else {
     String serverUrl = HttpUtils.getServerUrl(WicketUtils.getHttpServletRequest());
     try {
       WicketUtils.getWebResponse().sendRedirect(serverUrl + lastPage);
     } catch (ComponentNotFoundException e) {
       setResponsePage(BrowseRepoPage.class);
     }
   }
 }
 /**
  * Performs local properties update
  *
  * @param resource
  * @return success/failure
  */
 private boolean doPull(RepoResource resource) {
   log.debug("Downloading properties for artifact {}", resource);
   String repoKey = StringUtils.replaceLast(resource.getRepoPath().getRepoKey(), "-cache", "");
   HttpRepo repo = (HttpRepo) repositoryService.remoteRepositoryByKey(repoKey);
   // If file doesn't exist then do mot update properties since it will be updated during file
   // download
   if (!repositoryService.exists(resource.getRepoPath())) {
     return false;
   }
   // If properties not expire the return false, no need to get properties drom the remote repo
   if (repo == null
       || resourceIsExpirable(resource, repo)
       || !isPropertiesExpired(resource, repo)) {
     return false;
   }
   String remotePath = repo.getUrl() + "/" + resource.getRepoPath().getPath() + ":properties";
   HttpGet getMethod = new HttpGet(HttpUtils.encodeQuery(remotePath));
   try {
     CloseableHttpResponse getResponse = repo.executeMethod(getMethod);
     boolean ok = HttpStatus.SC_OK == getResponse.getStatusLine().getStatusCode();
     boolean notFound = HttpStatus.SC_NOT_FOUND == getResponse.getStatusLine().getStatusCode();
     if (ok || notFound) {
       InputStream stream = getResponse.getEntity().getContent();
       Properties properties = (Properties) InfoFactoryHolder.get().createProperties();
       if (ok && stream != null) {
         RepoRequests.logToContext("Received remote property content");
         Properties remoteProperties =
             (Properties) InfoFactoryHolder.get().getFileSystemXStream().fromXML(stream);
         for (String remotePropertyKey : remoteProperties.keySet()) {
           Set<String> values = remoteProperties.get(remotePropertyKey);
           RepoRequests.logToContext(
               "Found remote property key '{}' with values '%s'", remotePropertyKey, values);
           if (!remotePropertyKey.startsWith(ReplicationAddon.PROP_REPLICATION_PREFIX)) {
             properties.putAll(remotePropertyKey, values);
           }
         }
       }
       updateRemoteProperties(resource, properties);
     }
     repositoryService.unexpireIfExists(
         repo.getLocalCacheRepo(), resource.getRepoPath().getPath());
   } catch (IOException e) {
     log.debug("Cannot update remote properties", e);
     return false;
   }
   return true;
 }
 @Override
 public void execute(ArtifactoryRestRequest request, RestResponse response) {
   GradleSettingModel gradleSettingModel = (GradleSettingModel) request.getImodel();
   boolean downloadScript = Boolean.valueOf(request.getQueryParamByKey("downloadScript"));
   boolean downloadGradleProps = Boolean.valueOf(request.getQueryParamByKey("gradleProps"));
   String servletContextUrl = HttpUtils.getServletContextUrl(request.getServletRequest());
   // generate maven settings
   String gradleSnippet = generateSettings(servletContextUrl, gradleSettingModel, response);
   if (downloadGradleProps) {
     downLoadGradleProps(response, servletContextUrl);
     return;
   }
   if (downloadScript) {
     downloadGradleBuildFile(response, gradleSnippet);
     return;
   } else {
     // update maven setting model
     GradleSettingModel mavenSnippetModel = new GradleSettingModel(gradleSnippet);
     mavenSnippetModel.clearProps();
     response.iModel(mavenSnippetModel);
   }
 }