本文整理了Java中org.mockserver.model.HttpResponse.notFoundResponse()
方法的一些代码示例,展示了HttpResponse.notFoundResponse()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpResponse.notFoundResponse()
方法的具体详情如下:
包路径:org.mockserver.model.HttpResponse
类名称:HttpResponse
方法名:notFoundResponse
[英]Static builder to create a not found response.
[中]创建未找到响应的静态生成器。
代码示例来源:origin: jamesdbloom/mockserver
HttpForwardActionResult notFoundFuture(HttpRequest httpRequest) {
SettableFuture<HttpResponse> notFoundFuture = SettableFuture.create();
notFoundFuture.set(notFoundResponse());
return new HttpForwardActionResult(httpRequest, notFoundFuture);
}
}
代码示例来源:origin: jamesdbloom/mockserver
@Override
public HttpResponse handle(HttpRequest httpRequest) {
if (httpRequest.getPath().getValue().endsWith("/callback")) {
return httpResponse;
} else {
return notFoundResponse();
}
}
}
代码示例来源:origin: jamesdbloom/mockserver
private HttpResponse invokeCallbackMethod(HttpClassCallback httpClassCallback, HttpRequest httpRequest) {
if (httpRequest != null) {
ExpectationResponseCallback expectationResponseCallback = instantiateCallback(httpClassCallback);
if (expectationResponseCallback != null) {
try {
return expectationResponseCallback.handle(httpRequest);
} catch (Throwable throwable) {
mockServerLogger.error(httpClassCallback.getCallbackClass() + " throw exception while executing handle callback method", throwable);
return notFoundResponse();
}
} else {
return notFoundResponse();
}
} else {
return notFoundResponse();
}
}
}
代码示例来源:origin: jamesdbloom/mockserver
private void returnNotFound(ResponseWriter responseWriter, HttpRequest request) {
HttpResponse response = notFoundResponse();
if (request.getHeaders().containsEntry("x-forwarded-by", "MockServer")) {
response.withHeader("x-forwarded-by", "MockServer");
mockServerLogger.trace(request, "no expectation for:{}returning response:{}", request, notFoundResponse());
} else {
httpStateHandler.log(new RequestLogEntry(request));
mockServerLogger.info(EXPECTATION_NOT_MATCHED, request, "no expectation for:{}returning response:{}", request, notFoundResponse());
}
responseWriter.writeResponse(request, response, false);
}
}
代码示例来源:origin: jamesdbloom/mockserver
public HttpResponse handle(HttpTemplate httpTemplate, HttpRequest httpRequest) {
HttpResponse httpResponse = notFoundResponse();
TemplateEngine templateEngine = null;
switch (httpTemplate.getTemplateType()) {
case VELOCITY:
templateEngine = velocityTemplateEngine;
break;
case JAVASCRIPT:
templateEngine = javaScriptTemplateEngine;
break;
default:
throw new RuntimeException("Unknown no template engine available for " + httpTemplate.getTemplateType());
}
if (templateEngine != null) {
HttpResponse templatedResponse = templateEngine.executeTemplate(httpTemplate.getTemplate(), httpRequest, HttpResponseDTO.class);
if (templatedResponse != null) {
return templatedResponse;
}
}
return httpResponse;
}
代码示例来源:origin: jamesdbloom/mockserver
);
assertEquals(
notFoundResponse(),
makeRequest(
request().withPath(calculatePath("not_found")),
代码示例来源:origin: jamesdbloom/mockserver
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");
代码示例来源:origin: jamesdbloom/mockserver
public void run() {
try {
HttpResponse response = responseFuture.getHttpResponse().get();
if (response == null) {
response = notFoundResponse();
}
if (response.containsHeader("x-forwarded-by", "MockServer")) {
httpStateHandler.log(new RequestLogEntry(request));
mockServerLogger.info(EXPECTATION_NOT_MATCHED, request, "no expectation for:{}returning response:{}", request, notFoundResponse());
} else {
httpStateHandler.log(new RequestResponseLogEntry(request, response));
mockServerLogger.info(FORWARDED_REQUEST, request, "returning response:{}for forwarded request" + NEW_LINE + NEW_LINE + " in json:{}" + NEW_LINE + NEW_LINE + " in curl:{}", response, request, httpRequestToCurlSerializer.toCurl(request, remoteAddress));
}
responseWriter.writeResponse(request, response, false);
} catch (SocketCommunicationException sce) {
returnNotFound(responseWriter, request);
} catch (Exception ex) {
if (exploratoryHttpProxy && (ex.getCause() instanceof ConnectException || ex.getCause() instanceof SocketConnectionException)) {
mockServerLogger.trace("Failed to connect to proxied socket due to exploratory HTTP proxy for: {}falling back to no proxy: {}", request, ex.getCause());
returnNotFound(responseWriter, request);
} else {
mockServerLogger.error(request, ex, ex.getMessage());
}
}
}
}, synchronous);
代码示例来源:origin: jamesdbloom/mockserver
@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);
}
代码示例来源:origin: jamesdbloom/mockserver
@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);
}
代码示例来源:origin: jamesdbloom/mockserver
);
assertEquals(
notFoundResponse(),
makeRequest(
request().withPath(calculatePath("not_found")),
代码示例来源:origin: jamesdbloom/mockserver
notFoundResponse(),
makeRequest(
request()
notFoundResponse(),
makeRequest(
request()
代码示例来源:origin: jamesdbloom/mockserver
notFoundResponse(),
makeRequest(
request()
notFoundResponse(),
makeRequest(
request()
代码示例来源:origin: jamesdbloom/mockserver
@Test
public void shouldVerifySequenceOfRequestsReceivedIncludingThoseNotMatchingAnException() {
// when
mockServerClient.when(request().withPath(calculatePath("some_path.*")), exactly(4)).respond(response().withBody("some_body"));
// then
assertEquals(
response("some_body"),
makeRequest(
request().withPath(calculatePath("some_path_one")),
headersToIgnore)
);
assertEquals(
notFoundResponse(),
makeRequest(
request().withPath(calculatePath("not_found")),
headersToIgnore)
);
assertEquals(
response("some_body"),
makeRequest(
request().withPath(calculatePath("some_path_three")),
headersToIgnore)
);
mockServerClient.verify(request(calculatePath("some_path_one")), request(calculatePath("some_path_three")));
mockServerClient.verify(request(calculatePath("some_path_one")), request(calculatePath("not_found")));
mockServerClient.verify(request(calculatePath("some_path_one")), request(calculatePath("not_found")), request(calculatePath("some_path_three")));
mockServerClient.verify(request(calculatePath("some_path_one")), request(calculatePath("not_found")), request(calculatePath("some_path_three")));
}
代码示例来源:origin: jamesdbloom/mockserver
);
assertEquals(
notFoundResponse(),
makeRequest(
request().withPath(calculatePath("not_found")),
代码示例来源:origin: jamesdbloom/mockserver
);
assertEquals(
notFoundResponse(),
makeRequest(
request().withPath(calculatePath("not_found")),
代码示例来源:origin: org.mock-server/mockserver-core
HttpForwardActionResult notFoundFuture(HttpRequest httpRequest) {
SettableFuture<HttpResponse> notFoundFuture = SettableFuture.create();
notFoundFuture.set(notFoundResponse());
return new HttpForwardActionResult(httpRequest, notFoundFuture);
}
}
代码示例来源:origin: org.mock-server/mockserver-core
private HttpResponse invokeCallbackMethod(HttpClassCallback httpClassCallback, HttpRequest httpRequest) {
if (httpRequest != null) {
ExpectationResponseCallback expectationResponseCallback = instantiateCallback(httpClassCallback);
if (expectationResponseCallback != null) {
return expectationResponseCallback.handle(httpRequest);
} else {
return notFoundResponse();
}
} else {
return notFoundResponse();
}
}
}
代码示例来源:origin: org.mock-server/mockserver-core
private void returnNotFound(ResponseWriter responseWriter, HttpRequest request) {
HttpResponse response = notFoundResponse();
if (request.getHeaders().containsEntry("x-forwarded-by", "MockServer")) {
response.withHeader("x-forwarded-by", "MockServer");
} else {
httpStateHandler.log(new RequestLogEntry(request));
mockServerLogger.info(EXPECTATION_NOT_MATCHED, request, "no expectation for:{}returning response:{}", request, notFoundResponse());
}
responseWriter.writeResponse(request, response, false);
}
}
代码示例来源:origin: RoboZonky/robozonky
@Test
void checkNonExistentUrl() {
server.when(HttpRequest.request()).respond(HttpResponse.notFoundResponse());
final UpdateMonitor v = new UpdateMonitor(serverUrl, "com.github.robozonky", "robozonky-nonexistent");
v.run();
assertThat(v.get()).isEmpty();
}
内容来源于网络,如有侵权,请联系作者删除!