Example #1
0
  /** Returns an HttpEntity containing all request parameters */
  public HttpEntity getEntity() {

    if (bodyEntity != null) {
      return bodyEntity;
    }

    HttpEntity result = null;

    if (fileParams != null && !fileParams.isEmpty()) {

      MultipartEntity multipartEntity =
          new MultipartEntity(HttpMultipartMode.STRICT, boundary, Charset.forName(charset));

      if (bodyParams != null && !bodyParams.isEmpty()) {
        for (NameValuePair param : bodyParams) {
          try {
            multipartEntity.addPart(param.getName(), new StringBody(param.getValue()));
          } catch (UnsupportedEncodingException e) {
            LogUtils.e(e.getMessage(), e);
          }
        }
      }

      for (ConcurrentHashMap.Entry<String, ContentBody> entry : fileParams.entrySet()) {
        multipartEntity.addPart(entry.getKey(), entry.getValue());
      }

      result = multipartEntity;
    } else if (bodyParams != null && !bodyParams.isEmpty()) {
      result = new BodyParamsEntity(bodyParams, charset);
    }

    return result;
  }