Пример #1
0
  private HttpURLConnection getConnection(final String url_string) throws IOException {

    final HttpURLConnection con;
    final Proxy proxy;
    if (isProxyConfigured()) {
      if (CONF.getHttpProxyUser() != null && !CONF.getHttpProxyUser().equals("")) {
        if (logger.isDebugEnabled()) {
          logger.debug("Proxy AuthUser: "******"Proxy AuthPassword: "******"Opening proxied connection("
                + CONF.getHttpProxyHost()
                + ":"
                + CONF.getHttpProxyPort()
                + ")");
      }
    } else {
      proxy = Proxy.NO_PROXY;
    }

    final URL url = new URL(url_string);
    con = (HttpURLConnection) url.openConnection(proxy);
    if (CONF.getHttpConnectionTimeout() > 0) {
      con.setConnectTimeout(CONF.getHttpConnectionTimeout());
    }
    if (CONF.getHttpReadTimeout() > 0) {
      con.setReadTimeout(CONF.getHttpReadTimeout());
    }
    con.setInstanceFollowRedirects(false);
    if (con instanceof HttpsURLConnection && CONF.isSSLErrorIgnored()) {
      ((HttpsURLConnection) con).setHostnameVerifier(ALLOW_ALL_HOSTNAME_VERIFIER);
      if (IGNORE_ERROR_SSL_FACTORY != null) {
        ((HttpsURLConnection) con).setSSLSocketFactory(IGNORE_ERROR_SSL_FACTORY);
      }
    }
    return con;
  }
Пример #2
0
 private void parseGetParameters(final String url, final List<HttpParameter> signatureBaseParams) {
   final int queryStart = url.indexOf("?");
   if (-1 != queryStart) {
     final String[] queryStrs =
         Moefou4JInternalStringUtil.split(url.substring(queryStart + 1), "&");
     try {
       for (final String query : queryStrs) {
         final String[] split = Moefou4JInternalStringUtil.split(query, "=");
         if (split.length == 2) {
           signatureBaseParams.add(
               new HttpParameter(
                   URLDecoder.decode(split[0], "UTF-8"), URLDecoder.decode(split[1], "UTF-8")));
         } else {
           signatureBaseParams.add(new HttpParameter(URLDecoder.decode(split[0], "UTF-8"), ""));
         }
       }
     } catch (final UnsupportedEncodingException ignore) {
     }
   }
 }
Пример #3
0
 @Override
 public String toString() {
   return "OAuthAuthorization{"
       + "consumerKey='"
       + consumerKey
       + '\''
       + ", consumerSecret='"
       + Moefou4JInternalStringUtil.maskString(consumerSecret)
       + "'"
       + ", oauthToken="
       + oauthToken
       + '}';
 }
Пример #4
0
  /**
   * sets HTTP headers
   *
   * @param req The request
   * @param connection HttpURLConnection
   */
  private void setHeaders(final HttpRequest req, final HttpURLConnection connection) {
    if (logger.isDebugEnabled()) {
      logger.debug("Request: ");
      logger.debug(req.getMethod().name() + " ", req.getURL());
    }

    String authorizationHeader;
    if (req.getAuthorization() != null
        && (authorizationHeader = req.getAuthorization().getAuthorizationHeader(req)) != null) {
      if (logger.isDebugEnabled()) {
        logger.debug("Authorization: ", Moefou4JInternalStringUtil.maskString(authorizationHeader));
      }
      connection.addRequestProperty("Authorization", authorizationHeader);
    }
    final Map<String, String> req_headers = req.getRequestHeaders();
    if (req_headers != null) {
      for (final String key : req_headers.keySet()) {
        connection.addRequestProperty(key, req.getRequestHeaders().get(key));
        logger.debug(key + ": " + req.getRequestHeaders().get(key));
      }
    }
  }