HttpRequest
Code IndexAdd Codota to your IDE (free)

Best code snippets using org.mockserver.model.HttpRequest(Showing top 15 results out of 315)

origin: jamesdbloom/mockserver

public void forwardRequestInHTTP() {
  new MockServerClient("localhost", 1080)
    .when(
      request()
        .withPath("/some/path")
    )
    .forward(
      forward()
        .withHost("mock-server.com")
        .withPort(80)
    );
}
origin: jamesdbloom/mockserver

private void setHeaders(HttpRequest httpRequest, FullHttpRequest fullHttpResponse) {
  Headers headers = new Headers();
  HttpHeaders httpHeaders = fullHttpResponse.headers();
  for (String headerName : httpHeaders.names()) {
    headers.withEntry(new Header(headerName, httpHeaders.getAll(headerName)));
  }
  httpRequest.withHeaders(headers);
}
origin: jamesdbloom/mockserver

public void verifyRequests() {
  new MockServerClient("localhost", 1080)
    .verify(
      request()
        .withPath("/some/path"),
      VerificationTimes.atLeast(2)
    );
}
origin: jamesdbloom/mockserver

public void retrieveRecordedLogMessages() {
  String[] logMessages = new ProxyClient("localhost", 1080)
    .retrieveLogMessagesArray(
      request()
        .withPath("/some/path")
        .withMethod("POST")
    );
}
origin: jamesdbloom/mockserver

  private String getCookieHeader(HttpRequest request) {
    List<Cookie> cookies = new ArrayList<Cookie>();
    for (org.mockserver.model.Cookie cookie : request.getCookieList()) {
      cookies.add(new DefaultCookie(cookie.getName().getValue(), cookie.getValue().getValue()));
    }
    if (cookies.size() > 0) {
      return " -H '" + COOKIE + ": " + ClientCookieEncoder.LAX.encode(cookies) + "'";
    } else {
      return "";
    }
  }
}
origin: jamesdbloom/mockserver

private String getHostAndPort(HttpRequest request, InetSocketAddress remoteAddress) {
  String host = request.getFirstHeader("Host");
  if (Strings.isNullOrEmpty(host)) {
    host = remoteAddress.getHostName() + ":" + remoteAddress.getPort();
  }
  return host;
}
origin: jamesdbloom/mockserver

private void setQueryString(HttpRequest httpRequest, HttpServletRequest httpServletRequest) {
  Parameters parameters = new Parameters();
  if (StringUtils.isNotEmpty(httpServletRequest.getQueryString())) {
    parameters.withEntries(new QueryStringDecoder("?" + httpServletRequest.getQueryString()).parameters());
  }
  httpRequest.withQueryStringParameters(parameters);
}
origin: jamesdbloom/mockserver

public void retrieveAllRecordedRequests() {
  HttpRequest[] recordedRequests = new MockServerClient("localhost", 1080)
    .retrieveRecordedRequests(
      request()
    );
}
origin: jamesdbloom/mockserver

/**
 * Clear expectations, logs or both that match the http
 *
 * @param httpRequest the http request that is matched against when deciding whether to clear each expectation if null all expectations are cleared
 * @param type        the type to clear, EXPECTATION, LOG or BOTH
 */
public T clear(HttpRequest httpRequest, ClearType type) {
  sendRequest(request().withMethod("PUT").withPath(calculatePath("clear")).withQueryStringParameter("type", type.name().toLowerCase()).withBody(httpRequest != null ? httpRequestSerializer.serialize(httpRequest) : "", Charsets.UTF_8));
  return clientClass.cast(this);
}
origin: jamesdbloom/mockserver

public void matchRequestByBodyInUTF16() {
  new MockServerClient("localhost", 1080)
    .when(
      request()
        .withBody(exact("我说中国话", Charsets.UTF_16))
    )
    .respond(
      response()
        .withBody("some_response_body")
    );
}
origin: jamesdbloom/mockserver

void sendExpectation(Expectation expectation) {
  HttpResponse httpResponse = sendRequest(request().withMethod("PUT").withPath(calculatePath("expectation")).withBody(expectation != null ? expectationSerializer.serialize(expectation) : "", Charsets.UTF_8));
  if (httpResponse != null && httpResponse.getStatusCode() != 201) {
    throw new ClientException(formatErrorMessage(NEW_LINE + "error:%s" + NEW_LINE + "while submitted expectation:%s", httpResponse.getBody(), expectation));
  }
}
origin: jamesdbloom/mockserver

public InetSocketAddress socketAddressFromHostHeader() {
  if (!Strings.isNullOrEmpty(getFirstHeader(HOST.toString()))) {
    boolean isSsl = isSecure() != null && isSecure();
    String[] hostHeaderParts = getFirstHeader(HOST.toString()).split(":");
    return new InetSocketAddress(hostHeaderParts[0], hostHeaderParts.length > 1 ? Integer.parseInt(hostHeaderParts[1]) : isSsl ? 443 : 80);
  } else {
    throw new IllegalArgumentException("Host header must be provided to determine remote socket address, the request does not include the \"Host\" header:" + NEW_LINE + this);
  }
}
origin: jamesdbloom/mockserver

public void reset() {
  mockServerMatcher.reset();
  mockServerLog.reset();
  mockServerLogger.info(request(), "resetting all expectations and request logs" + NEW_LINE);
}
origin: jamesdbloom/mockserver

public void retrieveRecordedLogMessages() {
  String[] logMessages = new MockServerClient("localhost", 1080)
    .retrieveLogMessagesArray(
      request()
        .withPath("/some/path")
        .withMethod("POST")
    );
}
origin: jamesdbloom/mockserver

public void clear() {
  new ProxyClient("localhost", 1080).clear(
    request()
      .withPath("/some/path")
      .withMethod("POST")
  );
}
org.mockserver.modelHttpRequest

Most used methods

  • getPath
  • request
  • matches
  • withBody
    The body to match on as binary data such as a pdf or image
  • withHeader
    Adds one header to match on or to not match on using the NottableString, each NottableString can eit
  • withMethod
    The HTTP method all method except a specific value using the "not" operator, for example this allows
  • withPath
    The path to not match on for example not("/some_mocked_path") with match any path not equal to "/som
  • getMethod
  • withCookies
    The cookies to match on as a varags Cookie objects where the values or keys of each cookie can be ei
  • withHeaders
    The headers to match on as a varags of Header objects where the values or keys of each header can be
  • withQueryStringParameters
    The query string parameters to match on as a varags Parameter objects where the values or keys of ea
  • getBody
  • withQueryStringParameters,
  • getBody,
  • getBodyAsString,
  • getFirstHeader,
  • isKeepAlive,
  • isSecure,
  • withCookie,
  • withQueryStringParameter,
  • withSecure,
  • <init>

Popular classes and methods

  • setRequestProperty (URLConnection)
    Sets the value of the specified request header field. The value will only be used by the current URL
  • getResourceAsStream (ClassLoader)
    Returns a stream for the resource with the specified name. See #getResource(String) for a descriptio
  • setScale (BigDecimal)
    Returns a new BigDecimal instance with the specified scale. If the new scale is greater than the old
  • HttpURLConnection (java.net)
    An URLConnection for HTTP (RFC 2616 [http://tools.ietf.org/html/rfc2616]) used to send and receive d
  • Proxy (java.net)
    This class represents a proxy setting, typically a type (http, socks) and a socket address. A Proxy
  • SimpleDateFormat (java.text)
    Formats and parses dates in a locale-sensitive manner. Formatting turns a Date into a String, and pa
  • ConcurrentHashMap (java.util.concurrent)
    A plug-in replacement for JDK1.5 java.util.concurrent.ConcurrentHashMap. This version is based on *
  • Semaphore (java.util.concurrent)
    A counting semaphore. Conceptually, a semaphore maintains a set of permits. Each #acquire blocks if
  • ReentrantLock (java.util.concurrent.locks)
    A reentrant mutual exclusion Lock with the same basic behavior and semantics as the implicit monitor
  • Join (org.hibernate.mapping)

For IntelliJ IDEA and
Android Studio

  • Codota IntelliJ IDEA pluginCodota Android Studio pluginCode IndexSign in
  • EnterpriseFAQAboutContact Us
  • Terms of usePrivacy policyCodeboxFind Usages
Add Codota to your IDE (free)