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; }
@Override public String toString() { return "OAuthAuthorization{" + "consumerKey='" + consumerKey + '\'' + ", consumerSecret='" + Moefou4JInternalStringUtil.maskString(consumerSecret) + "'" + ", oauthToken=" + oauthToken + '}'; }
/** * 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)); } } }