Ejemplo n.º 1
0
  @Override
  public long setTargetVersion(PublishingTargetItem target, long newVersion, String site) {
    long resoponseVersion = -1;
    if (target.getVersionUrl() != null && !target.getVersionUrl().isEmpty()) {
      LOGGER.debug("Set deployment agent version for target {0}", target.getName());
      URL versionUrl = null;
      try {
        versionUrl = new URL(target.getVersionUrl());
      } catch (MalformedURLException e) {
        LOGGER.error("Invalid set version URL for target [%s]", target.getName());
        return resoponseVersion;
      }
      PostMethod postMethod = null;
      HttpClient client = null;
      try {
        postMethod = new PostMethod(target.getVersionUrl());
        postMethod.addParameter(TARGET_REQUEST_PARAMETER, target.getTarget());
        postMethod.addParameter(VERSION_REQUEST_PARAMETER, String.valueOf(newVersion));
        String siteId = target.getSiteId();
        if (StringUtils.isEmpty(siteId)) {
          siteId = site;
        }
        postMethod.addParameter(SITE_REQUEST_PARAMETER, site);
        client = new HttpClient();
        int status = client.executeMethod(postMethod);
        if (status == HttpStatus.SC_OK) {
          String responseText = postMethod.getResponseBodyAsString();
          if (responseText != null && !responseText.isEmpty()) {
            resoponseVersion = Long.parseLong(responseText);
          } else {
            resoponseVersion = 0;
          }
        }

      } catch (Exception e) {
        LOGGER.error(
            "Target {0} responded with error while setting target version. Set version failed for url {1}",
            target.getName(), target.getVersionUrl());

      } finally {
        if (client != null) {
          HttpConnectionManager mgr = client.getHttpConnectionManager();
          if (mgr instanceof SimpleHttpConnectionManager) {
            ((SimpleHttpConnectionManager) mgr).shutdown();
          }
        }
        if (postMethod != null) {
          postMethod.releaseConnection();
        }
        postMethod = null;
        client = null;
      }
    }
    return resoponseVersion;
  }
Ejemplo n.º 2
0
  @Override
  public long getTargetVersion(PublishingTargetItem target, String site) {
    long version = -1;
    if (target.getVersionUrl() != null && !target.getVersionUrl().isEmpty()) {
      LOGGER.debug(String.format("Get deployment agent version for target ", target.getName()));
      URL versionUrl = null;
      try {
        versionUrl = new URL(target.getVersionUrl());
      } catch (MalformedURLException e) {
        LOGGER.error(String.format("Invalid get version URL for target [%s]", target.getName()), e);
      }
      GetMethod getMethod = null;
      HttpClient client = null;
      try {
        getMethod = new GetMethod(target.getVersionUrl());
        String siteId = target.getSiteId();
        if (StringUtils.isEmpty(siteId)) {
          siteId = site;
        }
        getMethod.setQueryString(
            new NameValuePair[] {
              new NameValuePair(TARGET_REQUEST_PARAMETER, target.getTarget()),
              new NameValuePair(SITE_REQUEST_PARAMETER, siteId)
            });
        client = new HttpClient();
        int status = client.executeMethod(getMethod);
        if (status == HttpStatus.SC_OK) {
          String responseText = getMethod.getResponseBodyAsString();
          if (responseText != null && !responseText.isEmpty()) {
            version = Long.parseLong(responseText.trim());
          } else {
            version = 0;
          }
        }

      } catch (Exception e) {
        // LOGGER.error(String.format("Target (%s) responded with error while checking target
        // version. Get version failed for url %s", target.getName(), target.getVersionUrl()));

      } finally {
        if (client != null) {
          HttpConnectionManager mgr = client.getHttpConnectionManager();
          if (mgr instanceof SimpleHttpConnectionManager) {
            ((SimpleHttpConnectionManager) mgr).shutdown();
          }
        }
        if (getMethod != null) {
          getMethod.releaseConnection();
        }
        getMethod = null;
        client = null;
      }
    }
    return version;
  }