コード例 #1
0
    private void setHeaders(HttpRequest httprequest, HttpURLConnection httpurlconnection)
    {
        if (logger.isDebugEnabled())
        {
            logger.debug("Request: ");
            logger.debug((new StringBuilder()).append(httprequest.getMethod().name()).append(" ").toString(), httprequest.getURL());
        }
        if (httprequest.getAuthorization() != null)
        {
            String s = httprequest.getAuthorization().getAuthorizationHeader(httprequest);
            if (s != null)
            {
                if (logger.isDebugEnabled())
                {
                    logger.debug("Authorization: ", z_T4JInternalStringUtil.maskString(s));
                }
                httpurlconnection.addRequestProperty("Authorization", s);
            }
        }
        if (httprequest.getRequestHeaders() != null)
        {
            String s1;
            for (Iterator iterator = httprequest.getRequestHeaders().keySet().iterator(); iterator.hasNext(); logger.debug((new StringBuilder()).append(s1).append(": ").append((String)httprequest.getRequestHeaders().get(s1)).toString()))
            {
                s1 = (String)iterator.next();
                httpurlconnection.addRequestProperty(s1, (String)httprequest.getRequestHeaders().get(s1));
            }

        }
    }
コード例 #2
0
 protected HttpURLConnection getConnection(String s)
 {
     if (isProxyConfigured())
     {
         if (CONF.getHttpProxyUser() != null && !CONF.getHttpProxyUser().equals(""))
         {
             if (logger.isDebugEnabled())
             {
                 logger.debug((new StringBuilder("Proxy AuthUser: "******"Proxy AuthPassword: "******"Opening proxied connection(")).append(CONF.getHttpProxyHost()).append(":").append(CONF.getHttpProxyPort()).append(")").toString());
         }
         s = (HttpURLConnection)(new URL(s)).openConnection(proxy);
     } else
     {
         s = (HttpURLConnection)(new URL(s)).openConnection();
     }
     if (CONF.getHttpConnectionTimeout() > 0)
     {
         s.setConnectTimeout(CONF.getHttpConnectionTimeout());
     }
     if (CONF.getHttpReadTimeout() > 0)
     {
         s.setReadTimeout(CONF.getHttpReadTimeout());
     }
     s.setInstanceFollowRedirects(false);
     return s;
 }
コード例 #3
0
  /* package */ String generateAuthorizationHeader(
      final String method,
      final String sign_url,
      HttpParameter[] params,
      final String nonce,
      final String timestamp,
      final OAuthToken otoken) {
    if (null == params) {
      params = new HttpParameter[0];
    }
    final List<HttpParameter> oauthHeaderParams = new ArrayList<HttpParameter>(5);
    oauthHeaderParams.add(new HttpParameter("oauth_consumer_key", consumerKey));
    oauthHeaderParams.add(OAUTH_SIGNATURE_METHOD);
    oauthHeaderParams.add(new HttpParameter("oauth_timestamp", timestamp));
    oauthHeaderParams.add(new HttpParameter("oauth_nonce", nonce));
    oauthHeaderParams.add(new HttpParameter("oauth_version", "1.0"));
    if (otoken != null) {
      oauthHeaderParams.add(new HttpParameter("oauth_token", otoken.getToken()));
    }
    final List<HttpParameter> signatureBaseParams =
        new ArrayList<HttpParameter>(oauthHeaderParams.size() + params.length);
    signatureBaseParams.addAll(oauthHeaderParams);
    if (!HttpParameter.containsFile(params)) {
      signatureBaseParams.addAll(toParamList(params));
    }
    parseGetParameters(sign_url, signatureBaseParams);
    final StringBuffer base =
        new StringBuffer(method)
            .append("&")
            .append(HttpParameter.encode(constructRequestURL(sign_url)))
            .append("&");
    base.append(HttpParameter.encode(normalizeRequestParameters(signatureBaseParams)));
    final String oauthBaseString = base.toString();
    logger.debug("OAuth base string: ", oauthBaseString);
    final String signature = generateSignature(oauthBaseString, otoken);
    logger.debug("OAuth signature: ", signature);

    oauthHeaderParams.add(new HttpParameter("oauth_signature", signature));

    // http://oauth.net/core/1.0/#rfc.section.9.1.1
    if (realm != null) {
      oauthHeaderParams.add(new HttpParameter("realm", realm));
    }
    return "OAuth " + encodeParameters(oauthHeaderParams, ",", true);
  }
コード例 #4
0
 ((HttpURLConnection) (obj4)).setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
 obj1 = HttpParameter.encodeParameters(httprequest.getParameters());
 logger.debug("Post Params: ", ((String) (obj1)));
 abyte0 = ((String) (obj1)).getBytes("UTF-8");
 ((HttpURLConnection) (obj4)).setRequestProperty("Content-Length", Integer.toString(abyte0.length));
 ((HttpURLConnection) (obj4)).setDoOutput(true);
 obj2 = ((HttpURLConnection) (obj4)).getOutputStream();
 obj1 = obj2;
 ((OutputStream) (obj2)).write(abyte0);
   goto _L26
コード例 #5
0
  public String upload() throws TwitterException {
    preUpload();
    if (this.postParameter == null) {
      throw new AssertionError("Incomplete implementation. postParameter is not set.");
    }
    if (this.uploadUrl == null) {
      throw new AssertionError("Incomplete implementation. uploadUrl is not set.");
    }

    httpResponse = client.post(uploadUrl, postParameter, headers);

    String mediaUrl = postUpload();
    logger.debug("uploaded url [" + mediaUrl + "]");

    return mediaUrl;
  }
コード例 #6
0
ファイル: Logger.java プロジェクト: bgoyanna/twitter4j
 public void debug(String message, String message2) {
   if (DEBUG) {
     debug(message + message2);
   }
 }