@Override public HttpResponse handle(HttpRequest httpRequest) { if (httpRequest.getPath().getValue().endsWith("/callback")) { return httpResponse; } else { return notFoundResponse(); } } }
@Override public void run() { KeyAndCertificateFactory.addSubjectAlternativeName(request.getPath().getValue()); } });
if (request != null) { boolean methodMatches = Strings.isNullOrEmpty(request.getMethod().getValue()) || matches(context, methodMatcher, request.getMethod()); boolean pathMatches = Strings.isNullOrEmpty(request.getPath().getValue()) || matches(context, pathMatcher, request.getPath()); boolean queryStringParametersMatches = matches(context, queryStringParameterMatcher, request.getQueryStringParameters()); boolean bodyMatches = bodyMatches(context, request);
public void renderDashboard(final ChannelHandlerContext ctx, final HttpRequest request) throws Exception { HttpResponse response = notFoundResponse(); if (request.getMethod().getValue().equals("GET")) { String path = StringUtils.substringAfter(request.getPath().getValue(), PATH_PREFIX + "/dashboard"); if (path.isEmpty() || path.equals("/")) { path = "/index.html";
output.append(".withMethod(\"").append(request.getMethod().getValue()).append("\")"); if (!Strings.isNullOrEmpty(request.getPath().getValue())) { appendNewLineAndIndent((numberOfSpacesToIndent + 1) * INDENT_SIZE, output); output.append(".withPath(\"").append(request.getPath().getValue()).append("\")");
boolean isSsl = httpRequest.isSecure() != null && httpRequest.isSecure(); int port = (isSsl ? getServerSecurePort() : getServerPort()); httpRequest.withPath(addContextToPath(httpRequest.getPath().getValue())); httpRequest.withHeader(HOST.toString(), "localhost:" + port); boolean isDebug = java.lang.management.ManagementFactory.getRuntimeMXBean().getInputArguments().toString().indexOf("-agentlib:jdwp") > 0;
HttpResponse httpResponse = response() .withStatusCode(request.getPath().equalsIgnoreCase("/not_found") ? NOT_FOUND.code() : OK.code()) .withHeaders(request.getHeaderList());
if (request.getPath().getValue().equals("/_mockserver_callback_websocket")) {
public HttpRequestDTO(HttpRequest httpRequest, Boolean not) { super(not); if (httpRequest != null) { method = httpRequest.getMethod(); path = httpRequest.getPath(); headers = httpRequest.getHeaders(); cookies = httpRequest.getCookies(); queryStringParameters = httpRequest.getQueryStringParameters(); body = BodyDTO.createDTO(httpRequest.getBody()); keepAlive = httpRequest.isKeepAlive(); secure = httpRequest.isSecure(); } }
public String getURI(HttpRequest httpRequest) { QueryStringEncoder queryStringEncoder = new QueryStringEncoder(httpRequest.getPath().getValue()); for (Parameter parameter : httpRequest.getQueryStringParameterList()) { for (NottableString value : parameter.getValues()) { queryStringEncoder.addParam(parameter.getName().getValue(), value.getValue()); } } return queryStringEncoder.toString(); }
public HttpRequestTemplateObject(HttpRequest httpRequest) { if (httpRequest != null) { method = httpRequest.getMethod().getValue(); path = httpRequest.getPath().getValue(); for (Header header : httpRequest.getHeaderList()) { headers.put(header.getName().getValue(), Lists.transform(header.getValues(), new Function<NottableString, String>() { public String apply(NottableString input) { return input.getValue(); } })); } for (Cookie cookie : httpRequest.getCookieList()) { cookies.put(cookie.getName().getValue(), cookie.getValue().getValue()); } for (Parameter parameter : httpRequest.getQueryStringParameterList()) { queryStringParameters.put(parameter.getName().getValue(), Lists.transform(parameter.getValues(), new Function<NottableString, String>() { public String apply(NottableString input) { return input.getValue(); } })); } body = BodyDTO.createDTO(httpRequest.getBody()); keepAlive = httpRequest.isKeepAlive(); secure = httpRequest.isSecure(); } }
@Override public void writeResponse(HttpRequest request, HttpResponse response, boolean apiResponse) { if (response == null) { response = notFoundResponse(); } if (enableCORSForAllResponses()) { addCORSHeaders.addCORSHeaders(request, response); } else if (apiResponse && enableCORSForAPI()) { addCORSHeaders.addCORSHeaders(request, response); } if (apiResponse) { response.withHeader("version", org.mockserver.Version.getVersion()); final String path = request.getPath().getValue(); if (!path.startsWith(PATH_PREFIX)) { response.withHeader("deprecated", "\"" + path + "\" is deprecated use \"" + PATH_PREFIX + path + "\" instead"); } } addConnectionHeader(request, response); writeAndCloseSocket(ctx, request, response); }
@Override public void writeResponse(HttpRequest request, HttpResponse response, boolean apiResponse) { if (response == null) { response = notFoundResponse(); } if (enableCORSForAllResponses()) { addCORSHeaders.addCORSHeaders(request, response); } else if (apiResponse && enableCORSForAPI()) { addCORSHeaders.addCORSHeaders(request, response); } if (apiResponse) { response.withHeader("version", org.mockserver.Version.getVersion()); final String path = request.getPath().getValue(); if (!path.startsWith(PATH_PREFIX)) { response.withHeader("deprecated", "\"" + path + "\" is deprecated use \"" + PATH_PREFIX + path + "\" instead"); } } addConnectionHeader(request, response); mockServerResponseToHttpServletResponseEncoder.mapMockServerResponseToHttpServletResponse(response, httpServletResponse); }
public HttpRequest update(HttpRequest replaceRequest) { if (!Strings.isNullOrEmpty(replaceRequest.getMethod().getValue())) { withMethod(replaceRequest.getMethod()); } if (!Strings.isNullOrEmpty(replaceRequest.getPath().getValue())) { withPath(replaceRequest.getPath()); } for (Header header : replaceRequest.getHeaderList()) { getHeaders().replaceEntry(header); } for (Cookie cookie : replaceRequest.getCookieList()) { withCookie(cookie); } for (Parameter parameter : replaceRequest.getQueryStringParameterList()) { getQueryStringParameters().replaceEntry(parameter); } if (replaceRequest.getBody() != null) { withBody(replaceRequest.getBody()); } if (replaceRequest.isSecure() != null) { withSecure(replaceRequest.isSecure()); } if (replaceRequest.isKeepAlive() != null) { withKeepAlive(replaceRequest.isKeepAlive()); } return this; } }
public HttpRequestMatcher(HttpRequest httpRequest, MockServerLogger mockServerLogger) { this.httpRequest = httpRequest; this.mockServerLogger = mockServerLogger; if (httpRequest != null) { withMethod(httpRequest.getMethod()); withPath(httpRequest.getPath()); withQueryStringParameters(httpRequest.getQueryStringParameters()); withBody(httpRequest.getBody()); withHeaders(httpRequest.getHeaders()); withCookies(httpRequest.getCookies()); withKeepAlive(httpRequest.isKeepAlive()); withSsl(httpRequest.isSecure()); } }
public HttpRequestMatcher(Expectation expectation, MockServerLogger mockServerLogger) { this.expectation = expectation; this.httpRequest = expectation.getHttpRequest(); this.mockServerLogger = mockServerLogger; if (httpRequest != null) { withMethod(httpRequest.getMethod()); withPath(httpRequest.getPath()); withQueryStringParameters(httpRequest.getQueryStringParameters()); withBody(httpRequest.getBody()); withHeaders(httpRequest.getHeaders()); withCookies(httpRequest.getCookies()); withKeepAlive(httpRequest.isKeepAlive()); withSsl(httpRequest.isSecure()); } }
); assertEquals(StaticTestExpectationResponseCallback.httpRequests.get(0).getBody().getValue(), "an_example_body_http"); assertEquals(StaticTestExpectationResponseCallback.httpRequests.get(0).getPath().getValue(), calculatePath("callback")); assertEquals(StaticTestExpectationResponseCallback.httpRequests.get(1).getPath().getValue(), calculatePath("callback"));
@Override public void run() { KeyAndCertificateFactory.addSubjectAlternativeName(request.getPath().getValue()); } });