public String getQueryString(String contentEncoding) {
    // Check if the sampler has a specified content encoding
    if (JOrphanUtils.isBlank(contentEncoding)) {
      // We use the encoding which should be used according to the HTTP spec, which is UTF-8
      contentEncoding = EncoderCache.URL_ARGUMENT_ENCODING;
    }
    StringBuilder buf = new StringBuilder();
    PropertyIterator iter = getQueryStringParameters().iterator();
    boolean first = true;
    while (iter.hasNext()) {
      HTTPArgument item = null;
      Object objectValue = iter.next().getObjectValue();
      try {
        item = (HTTPArgument) objectValue;
      } catch (ClassCastException e) {
        item = new HTTPArgument((Argument) objectValue);
      }
      final String encodedName = item.getEncodedName();
      if (encodedName.length() == 0) {
        continue; // Skip parameters with a blank name (allows use of optional variables in
                  // parameter lists)
      }
      if (!first) {
        buf.append(QRY_SEP);
      } else {
        first = false;
      }
      buf.append(encodedName);
      if (item.getMetaData() == null) {
        buf.append(ARG_VAL_SEP);
      } else {
        buf.append(item.getMetaData());
      }

      // Encode the parameter value in the specified content encoding
      try {
        buf.append(item.getEncodedValue(contentEncoding));
      } catch (UnsupportedEncodingException e) {
        log.warn(
            "Unable to encode parameter in encoding "
                + contentEncoding
                + ", parameter value not included in query string");
      }
    }
    return buf.toString();
  }
Example #2
0
 /**
  * @param value String value to test
  * @return true if value is null or empty trimmed
  */
 protected static boolean isNullOrEmptyTrimmed(String value) {
   return JOrphanUtils.isBlank(value);
 }
Example #3
0
 /**
  * Is a dynamic proxy defined?
  *
  * @param proxyHost the host to check
  * @param proxyPort the port to check
  * @return {@code true} iff both ProxyPort and ProxyHost are defined.
  */
 protected boolean isDynamicProxy(String proxyHost, int proxyPort) {
   return (!JOrphanUtils.isBlank(proxyHost) && proxyPort > 0);
 }