예제 #1
0
 /**
  * Called primarily from HTTPMethod to do the bulk of the execution. Assumes HTTPMethod has
  * inserted its headers into request.
  *
  * @param method
  * @param methoduri
  * @param rb
  * @return Request+Response pair
  * @throws HTTPException
  */
 ExecState execute(HTTPMethod method, URI methoduri, RequestBuilder rb) throws HTTPException {
   this.execution = new ExecState();
   this.requestURI = methoduri;
   AuthScope methodscope = HTTPAuthUtil.uriToAuthScope(methoduri);
   AuthScope target = HTTPAuthUtil.authscopeUpgrade(this.scope, methodscope);
   synchronized (this) { // keep coverity happy
     // Merge Settings;
     Settings merged = HTTPUtil.merge(globalsettings, localsettings);
     if (!this.cachevalid) {
       RequestConfig.Builder rcb = RequestConfig.custom();
       this.cachedconfig = configureRequest(rcb, merged);
       HttpClientBuilder cb = HttpClients.custom();
       configClient(cb, merged);
       setAuthenticationAndProxy(cb);
       this.cachedclient = cb.build();
       rb.setConfig(this.cachedconfig);
       this.cachevalid = true;
     }
   }
   this.execution.request = (HttpRequestBase) rb.build();
   try {
     HttpHost targethost = HTTPAuthUtil.authscopeToHost(target);
     this.execution.response =
         cachedclient.execute(targethost, this.execution.request, this.sessioncontext);
   } catch (IOException ioe) {
     throw new HTTPException(ioe);
   }
   return this.execution;
 }
예제 #2
0
 static String getCanonicalURL(String legalurl) {
   if (legalurl == null) return null;
   int index = legalurl.indexOf('?');
   if (index >= 0) legalurl = legalurl.substring(0, index);
   // remove any trailing extension
   // index = legalurl.lastIndexOf('.');
   // if(index >= 0) legalurl = legalurl.substring(0,index);
   return HTTPUtil.canonicalpath(legalurl);
 }
예제 #3
0
 public static synchronized void setGlobalProxy(String proxyurl) {
   if (proxyurl == null) throw new IllegalArgumentException("Bad proxy URL: " + proxyurl);
   URI uri;
   try {
     uri = HTTPUtil.parseToURI(proxyurl);
   } catch (URISyntaxException e) {
     throw new IllegalArgumentException("Bad proxy URL: " + proxyurl);
   }
   if (uri.getScheme().equals("http"))
     httpproxy = new HttpHost(uri.getHost(), uri.getPort(), "http");
   else if (uri.getScheme().equals("https"))
     httpsproxy = new HttpHost(uri.getHost(), uri.getPort(), "https");
   String upw = uri.getUserInfo();
   if (upw != null) {
     String[] pieces = upw.split("[:]");
     if (pieces.length != 2
         || HTTPUtil.nullify(pieces[0]) == null
         || HTTPUtil.nullify(pieces[1]) == null)
       throw new IllegalArgumentException("Bad userinfo: " + proxyurl);
     proxyuser = pieces[0];
     proxypwd = pieces[1];
   }
 }
예제 #4
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);
   }
 }