public void process()

in streams-contrib/streams-provider-twitter/src/main/java/org/apache/streams/twitter/api/TwitterOAuthRequestInterceptor.java [76:151]


  public void process(HttpRequest httpRequest, HttpContext httpContext) throws HttpException, IOException {

    String oauth_nonce = generateNonce();

    String oauth_timestamp = generateTimestamp();

    Map<String,String> oauthParamMap = new HashMap<>();
    oauthParamMap.put("oauth_consumer_key", oAuthConfiguration.getConsumerKey());
    oauthParamMap.put("oauth_nonce", oauth_nonce);
    oauthParamMap.put("oauth_signature_method", security.oauth_signature_method_param);
    oauthParamMap.put("oauth_timestamp", oauth_timestamp);
    oauthParamMap.put("oauth_token", oAuthConfiguration.getAccessToken());
    oauthParamMap.put("oauth_version", security.oauth_version);
    assert(oauthParamMap.containsValue(null) == false);

    String request_host = ((HttpRequestWrapper)httpRequest).getTarget().toString().replace(":443","");
    String request_path = httpRequest.getRequestLine().getUri();

    Map<String,String> allParamsMap = new HashMap<>(oauthParamMap);

    if( request_path.contains("?")) {
      request_path = request_path.substring(0, httpRequest.getRequestLine().getUri().indexOf('?'));
      String request_param_line = httpRequest.getRequestLine().getUri().substring(httpRequest.getRequestLine().getUri().indexOf('?')+1);
      String[] request_params = URLDecoder.decode(request_param_line).split("&");

      for( String request_param : request_params ) {
        String key = request_param.substring(0, request_param.indexOf('='));
        String value = request_param.substring(request_param.indexOf('=')+1, request_param.length());
        allParamsMap.put(key, value);
      }
    }

    if( ((HttpRequestWrapper) httpRequest).getOriginal() instanceof HttpPost) {
      HttpEntity entity = ((HttpEntityEnclosingRequest)((HttpRequestWrapper) httpRequest).getOriginal()).getEntity();
      if( entity != null ) {
        String body = EntityUtils.toString(entity);
        String[] body_params = body.split(",");
        for (String body_param : body_params) {
          body_param = URLDecoder.decode(body_param);
          String key = body_param.substring(0, body_param.indexOf('='));
          String value = body_param.substring(body_param.indexOf('=') + 1, body_param.length());
          allParamsMap.put(key, value);
        }
      }
    }

    allParamsMap = security.encodeMap(allParamsMap);

//    if( httpRequest instanceof HttpEntityEnclosingRequest ) {
//      HttpEntity entity = ((HttpEntityEnclosingRequest) httpRequest).getEntity();
//      if( entity != null ) {
//        httpRequest.setHeader("Content-Length", Integer.toString(EntityUtils.toString(entity).length()));
//      }
//    }

    String signature_parameter_string = security.generateSignatureParameterString(allParamsMap);

    String signature_base_string = security.generateSignatureBaseString(((HttpRequestWrapper) httpRequest).getMethod(), request_host+request_path, signature_parameter_string);

    String signing_key = security.encode(oAuthConfiguration.getConsumerSecret()) + "&" + security.encode(oAuthConfiguration.getAccessTokenSecret());

    String oauth_signature;
    try {
      oauth_signature = security.computeAndEncodeSignature(signature_base_string, signing_key, security.oauth_signature_method);
    } catch (GeneralSecurityException e) {
      LOGGER.warn("GeneralSecurityException", e);
      return;
    }

    oauthParamMap.put("oauth_signature",oauth_signature);

    String authorization_header_string = security.generateAuthorizationHeaderString(oauthParamMap);

    httpRequest.setHeader("Authorization", authorization_header_string);

  }