Esempio n. 1
0
 public HTTPSession setConnectionTimeout(int timeout) {
   if (timeout <= 0) throw new IllegalArgumentException("setConnectionTImeout");
   localsettings.setParameter(Prop.CONN_TIMEOUT, timeout);
   localsettings.setParameter(Prop.CONN_REQ_TIMEOUT, timeout);
   this.cachevalid = false;
   return this;
 }
Esempio n. 2
0
 protected RequestConfig configureRequest(RequestConfig.Builder rcb, Settings settings)
     throws HTTPException {
   // Configure the RequestConfig
   for (Prop key : settings.getKeys()) {
     Object value = settings.getParameter(key);
     boolean tf = (value instanceof Boolean ? (Boolean) value : false);
     if (key == Prop.ALLOW_CIRCULAR_REDIRECTS) {
       rcb.setCircularRedirectsAllowed(tf);
     } else if (key == Prop.HANDLE_REDIRECTS) {
       rcb.setRedirectsEnabled(tf);
       rcb.setRelativeRedirectsAllowed(tf);
     } else if (key == Prop.MAX_REDIRECTS) {
       rcb.setMaxRedirects((Integer) value);
     } else if (key == Prop.SO_TIMEOUT) {
       rcb.setSocketTimeout((Integer) value);
     } else if (key == Prop.CONN_TIMEOUT) {
       rcb.setConnectTimeout((Integer) value);
     } else if (key == Prop.CONN_REQ_TIMEOUT) {
       rcb.setConnectionRequestTimeout((Integer) value);
     } else if (key == Prop.MAX_THREADS) {
       connmgr.setMaxTotal((Integer) value);
       connmgr.setDefaultMaxPerRoute((Integer) value);
     } /* else ignore */
   }
   RequestConfig cfg = rcb.build();
   return cfg;
 }
Esempio n. 3
0
 public static synchronized void setGlobalCompression(String compressors) {
   if (globalsettings.getParameter(Prop.COMPRESSION) != null) removeGlobalCompression();
   String compresslist = checkCompressors(compressors);
   if (HTTPUtil.nullify(compresslist) == null)
     throw new IllegalArgumentException("Bad compressors: " + compressors);
   globalsettings.setParameter(Prop.COMPRESSION, compresslist);
   HttpResponseInterceptor hrsi;
   if (compresslist.contains("gzip")) {
     hrsi = new GZIPResponseInterceptor();
     rspintercepts.add(hrsi);
   }
   if (compresslist.contains("deflate")) {
     hrsi = new DeflateResponseInterceptor();
     rspintercepts.add(hrsi);
   }
 }
Esempio n. 4
0
 protected void configClient(HttpClientBuilder cb, Settings settings) throws HTTPException {
   cb.useSystemProperties();
   String agent = (String) settings.get(Prop.USER_AGENT);
   if (agent != null) cb.setUserAgent(agent);
   setInterceptors(cb);
   cb.setContentDecoderRegistry(contentDecoderMap);
 }
Esempio n. 5
0
 /**
  * Set the max number of redirects to follow
  *
  * @param n
  */
 public HTTPSession setMaxRedirects(int n) {
   if (n < 0) // validate
   throw new IllegalArgumentException("setMaxRedirects");
   localsettings.setParameter(Prop.MAX_REDIRECTS, n);
   this.cachevalid = false;
   return this;
 }
Esempio n. 6
0
 public static void removeGlobalCompression() {
   if (globalsettings.removeParameter(Prop.COMPRESSION) != null) {
     for (int i = rspintercepts.size() - 1; i >= 0; i--) { // walk backwards
       HttpResponseInterceptor hrsi = rspintercepts.get(i);
       if (hrsi instanceof GZIPResponseInterceptor || hrsi instanceof DeflateResponseInterceptor)
         rspintercepts.remove(i);
     }
   }
 }
Esempio n. 7
0
 // Provide defaults for a settings map
 protected static void setDefaults(Settings props) {
   if (false) { // turn off for now
     props.setParameter(Prop.HANDLE_AUTHENTICATION, Boolean.TRUE);
   }
   props.setParameter(Prop.HANDLE_REDIRECTS, Boolean.TRUE);
   props.setParameter(Prop.ALLOW_CIRCULAR_REDIRECTS, Boolean.TRUE);
   props.setParameter(Prop.MAX_REDIRECTS, (Integer) DFALTREDIRECTS);
   props.setParameter(Prop.SO_TIMEOUT, (Integer) DFALTSOTIMEOUT);
   props.setParameter(Prop.CONN_TIMEOUT, (Integer) DFALTCONNTIMEOUT);
   props.setParameter(Prop.CONN_REQ_TIMEOUT, (Integer) DFALTCONNREQTIMEOUT);
   props.setParameter(Prop.USER_AGENT, DFALTUSERAGENT);
 }
Esempio n. 8
0
  public void deinit(Appendable out, boolean force) throws Exception {
    Settings settings = new Settings(platform.getConfigFile());

    if (!force) {
      Justif justify = new Justif(80, 40);
      StringBuilder sb = new StringBuilder();
      Formatter f = new Formatter(sb);

      try {
        String list = listFiles(platform.getGlobal());
        if (list != null) {
          f.format("In global default environment:%n");
          f.format(list);
        }

        list = listFiles(platform.getLocal());
        if (list != null) {
          f.format("In local default environment:%n");
          f.format(list);
        }

        if (settings.containsKey(JPM_CACHE_GLOBAL)) {
          list = listFiles(IO.getFile(settings.get(JPM_CACHE_GLOBAL)));
          if (list != null) {
            f.format("In global configured environment:%n");
            f.format(list);
          }
        }

        if (settings.containsKey(JPM_CACHE_LOCAL)) {
          list = listFiles(IO.getFile(settings.get(JPM_CACHE_LOCAL)));
          if (list != null) {
            f.format("In local configured environment:%n");
            f.format(list);
          }
        }

        list = listSupportFiles();
        if (list != null) {
          f.format("jpm support files:%n");
          f.format(list);
        }

        f.format("%n%n");

        f.format(
            "All files listed above will be deleted if deinit is run with the force flag set"
                + " (\"jpm deinit -f\" or \"jpm deinit --force\"%n%n");
        f.flush();

        justify.wrap(sb);
        out.append(sb.toString());
      } finally {
        f.close();
      }
    } else { // i.e. if(force)
      int count = 0;
      File[] caches = {platform.getGlobal(), platform.getLocal(), null, null};
      if (settings.containsKey(JPM_CACHE_LOCAL)) {
        caches[2] = IO.getFile(settings.get(JPM_CACHE_LOCAL));
      }
      if (settings.containsKey(JPM_CACHE_GLOBAL)) {
        caches[3] = IO.getFile(settings.get(JPM_CACHE_GLOBAL));
      }
      ArrayList<File> toDelete = new ArrayList<File>();

      for (File cache : caches) {
        if (cache == null || !cache.exists()) {
          continue;
        }
        listFiles(cache, toDelete);
        if (toDelete.size() > count) {
          count = toDelete.size();
          if (!cache.canWrite()) {
            reporter.error(PERMISSION_ERROR + " (" + cache + ")");
            return;
          }
          toDelete.add(cache);
        }
      }
      listSupportFiles(toDelete);

      for (File f : toDelete) {
        if (f.exists() && !f.canWrite()) {
          reporter.error(PERMISSION_ERROR + " (" + f + ")");
        }
      }
      if (reporter.getErrors().size() > 0) {
        return;
      }

      for (File f : toDelete) {
        if (f.exists()) {
          IO.deleteWithException(f);
        }
      }
    }
  }
Esempio n. 9
0
 public static synchronized void setGlobalUserAgent(String userAgent) {
   globalsettings.setParameter(Prop.USER_AGENT, userAgent);
 }
Esempio n. 10
0
 public Object getSetting(String key) {
   return localsettings.get(key);
 }
Esempio n. 11
0
 /**
  * Should we use sessionid's?
  *
  * @param tf
  */
 public HTTPSession setUseSessions(boolean tf) {
   localsettings.setParameter(Prop.USESESSIONS, (Boolean) tf);
   this.cachevalid = false;
   return this;
 }
Esempio n. 12
0
 /** Enable/disable redirection following Default is yes. */
 public HTTPSession setFollowRedirects(boolean tf) {
   localsettings.setParameter(Prop.HANDLE_REDIRECTS, (Boolean) tf);
   this.cachevalid = false;
   return this;
 }
Esempio n. 13
0
 public static synchronized String getGlobalUserAgent() {
   return (String) globalsettings.getParameter(Prop.USER_AGENT);
 }
Esempio n. 14
0
 public HTTPSession setUserAgent(String agent) {
   if (agent == null || agent.length() == 0) throw new IllegalArgumentException("null argument");
   localsettings.setParameter(Prop.USER_AGENT, agent);
   this.cachevalid = false;
   return this;
 }
Esempio n. 15
0
 public static synchronized Object getGlobalSetting(String key) {
   return globalsettings.get(key);
 }
Esempio n. 16
0
 /**
  * Set the max number of redirects to follow
  *
  * @param n
  */
 public static synchronized void setGlobalMaxRedirects(int n) {
   if (n < 0) // validate
   throw new IllegalArgumentException("setMaxRedirects");
   globalsettings.setParameter(Prop.MAX_REDIRECTS, n);
 }
Esempio n. 17
0
 /** Enable/disable redirection following Default is yes. */
 public static synchronized void setGlobalFollowRedirects(boolean tf) {
   globalsettings.setParameter(Prop.HANDLE_REDIRECTS, (Boolean) tf);
 }
Esempio n. 18
0
 public static synchronized void setGlobalSoTimeout(int timeout) {
   if (timeout >= 0) globalsettings.setParameter(Prop.SO_TIMEOUT, (Integer) timeout);
 }
Esempio n. 19
0
 public static synchronized void setGlobalConnectionTimeout(int timeout) {
   if (timeout >= 0) {
     globalsettings.setParameter(Prop.CONN_TIMEOUT, (Integer) timeout);
     globalsettings.setParameter(Prop.CONN_REQ_TIMEOUT, (Integer) timeout);
   }
 }