Example #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;
 }
Example #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;
 }
Example #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);
   }
 }
Example #4
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;
 }
Example #5
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);
 }
Example #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);
     }
   }
 }
Example #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);
 }
Example #8
0
 public Object getSetting(String key) {
   return localsettings.get(key);
 }
Example #9
0
 /**
  * Should we use sessionid's?
  *
  * @param tf
  */
 public HTTPSession setUseSessions(boolean tf) {
   localsettings.setParameter(Prop.USESESSIONS, (Boolean) tf);
   this.cachevalid = false;
   return this;
 }
Example #10
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;
 }
Example #11
0
 public static synchronized void setGlobalUserAgent(String userAgent) {
   globalsettings.setParameter(Prop.USER_AGENT, userAgent);
 }
Example #12
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;
 }
Example #13
0
 public static synchronized Object getGlobalSetting(String key) {
   return globalsettings.get(key);
 }
Example #14
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);
 }
Example #15
0
 /** Enable/disable redirection following Default is yes. */
 public static synchronized void setGlobalFollowRedirects(boolean tf) {
   globalsettings.setParameter(Prop.HANDLE_REDIRECTS, (Boolean) tf);
 }
Example #16
0
 public static synchronized void setGlobalSoTimeout(int timeout) {
   if (timeout >= 0) globalsettings.setParameter(Prop.SO_TIMEOUT, (Integer) timeout);
 }
Example #17
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);
   }
 }
Example #18
0
 public static synchronized String getGlobalUserAgent() {
   return (String) globalsettings.getParameter(Prop.USER_AGENT);
 }