private static String fetchResponseBody(HttpResponse response) throws IOException {
   String body = null;
   HttpEntity entity = response.getEntity();
   StatusLine status = response.getStatusLine();
   try {
     body = EntityUtils.toString(entity);
   } finally {
     EntityUtils.consume(entity);
   }
   if (body.length() < 2048) LOGGER.debug("[ << ] - {} {}", status, body);
   else LOGGER.debug("[ << ] - {} [body-omitted]", status);
   return body; // the response body
 }
 private static HttpPost prepareRequest(String content, String url) {
   HttpPost POST = new HttpPost(url);
   try {
     if (StringUtils.isNotEmpty(content)) POST.setEntity(new StringEntity(content));
   } catch (Exception e) {
     throw new UnexpectedException(e); // will not happen
   }
   if (content != null && content.length() > 0)
     if (!content.startsWith("<?xml")) LOGGER.debug("[ >> ] - {} -> {}", content, url);
     else LOGGER.debug("[ >> ] - [xml-content] -> {}", url);
   else LOGGER.debug("[ >> ] - [empty-body] -> {}", url);
   return POST; // HTTP request prepared
 }
Beispiel #3
0
  @Override
  public void init(Config config, Logger logger) {
    super.init(config, logger);

    timeout = config.getInt(CONN_TIMEOUT_KEY, CONN_TIMEOUT_DEFAULT);

    parms.put(CONN_TIMEOUT_KEY, timeout);

    endpoint = config.get(ENDPOINT_KEY, ENDPOINT_DEFAULT);
    accessKey = config.get(AUTH_USERNAME_KEY, AUTH_USERNAME_DEFAULT);
    secretKey = config.get(AUTH_PASSWORD_KEY, AUTH_PASSWORD_DEFAULT);

    boolean pathStyleAccess = config.getBoolean(PATH_STYLE_ACCESS_KEY, PATH_STYLE_ACCESS_DEFAULT);

    String proxyHost = config.get(PROXY_HOST_KEY, "");
    String proxyPort = config.get(PROXY_PORT_KEY, "");

    parms.put(ENDPOINT_KEY, endpoint);
    parms.put(AUTH_USERNAME_KEY, accessKey);
    parms.put(AUTH_PASSWORD_KEY, secretKey);
    parms.put(PATH_STYLE_ACCESS_KEY, pathStyleAccess);
    parms.put(PROXY_HOST_KEY, proxyHost);
    parms.put(PROXY_PORT_KEY, proxyPort);

    logger.debug("using storage config: {}", parms);

    ClientConfiguration clientConf = new ClientConfiguration();
    clientConf.setConnectionTimeout(timeout);
    clientConf.setSocketTimeout(timeout);
    clientConf.withUseExpectContinue(false);
    clientConf.withSignerOverride("S3SignerType");
    //        clientConf.setProtocol(Protocol.HTTP);
    if ((!proxyHost.equals("")) && (!proxyPort.equals(""))) {
      clientConf.setProxyHost(proxyHost);
      clientConf.setProxyPort(Integer.parseInt(proxyPort));
    }

    AWSCredentials myCredentials = new BasicAWSCredentials(accessKey, secretKey);
    client = new AmazonS3Client(myCredentials, clientConf);
    client.setEndpoint(endpoint);
    client.setS3ClientOptions(new S3ClientOptions().withPathStyleAccess(pathStyleAccess));

    logger.debug("S3 client has been initialized");
  }
Beispiel #4
0
  @Override
  public void init(Config config, Logger logger) {
    super.init(config, logger);

    url = config.get(AUTH_URL_KEY, config.get(AUTH_URL_KEY_BACK, URL_DEFAULT));

    username = config.get(AUTH_USERNAME_KEY, AUTH_USERNAME_DEFAULT);
    password = config.get(AUTH_PASSWORD_KEY, AUTH_PASSWORD_DEFAULT);
    timeout = config.getInt(CONN_TIMEOUT_KEY, CONN_TIMEOUT_DEFAULT);

    parms.put(AUTH_URL_KEY, url);
    parms.put(AUTH_USERNAME_KEY, username);
    parms.put(AUTH_PASSWORD_KEY, password);
    parms.put(CONN_TIMEOUT_KEY, timeout);

    logger.debug("using auth config: {}", parms);

    HttpClient httpClient = HttpClientUtil.createHttpClient(timeout);
    client = new SwiftAuthClient(httpClient, url, username, password);
    logger.debug("swauth client has been initialized");
  }