Exemple #1
0
  @Override
  public boolean shouldCall(Request request) {
    boolean should;

    if (null != selectParams) {
      for (Map.Entry<String, String> select : selectParams.entrySet()) {
        if (!select.getValue().equals(request.param(select.getKey()))) {
          should = false;
        }
      }
    }

    if (null != selectHeaders) {
      for (Map.Entry<String, String> header : selectHeaders.entrySet()) {
        if (!header.getValue().equals(request.header(header.getKey()))) {
          should = false;
        }
      }
    }

    // (JFA) Might be a good idea to pass the value of should as a request attribute
    // so an action can see if what was the value before getting invoked and take a decision based
    // on it.
    should = action.shouldCall(request);

    return should;
  }
  private String getEntityBodyFromRequest(Request<String> request) throws IOException {
    String contentTypeHeader = request.header("Content-Type");
    Charset charset = BrowserMobHttpUtil.deriveCharsetFromContentTypeHeader(contentTypeHeader);
    ByteArrayOutputStream entityBodyBytes = new ByteArrayOutputStream();
    request.readTo(entityBodyBytes);

    return new String(entityBodyBytes.toByteArray(), charset);
  }
  private String getEntityBodyFromRequest(Request<String> request) throws IOException {
    String contentTypeHeader = request.header("Content-Type");
    Charset charset = null;
    try {
      charset = BrowserMobHttpUtil.readCharsetInContentTypeHeader(contentTypeHeader);
    } catch (UnsupportedCharsetException e) {
      java.nio.charset.UnsupportedCharsetException cause = e.getUnsupportedCharsetExceptionCause();
      LOG.error(
          "Character set declared in Content-Type header is not supported. Content-Type header: {}",
          contentTypeHeader,
          cause);

      throw cause;
    }

    if (charset == null) {
      charset = BrowserMobHttpUtil.DEFAULT_HTTP_CHARSET;
    }

    ByteArrayOutputStream entityBodyBytes = new ByteArrayOutputStream();
    request.readTo(entityBodyBytes);

    return new String(entityBodyBytes.toByteArray(), charset);
  }