Merge branch '5.1.x'
This commit is contained in:
commit
30e1257dda
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -161,6 +161,15 @@ public class ExchangeResult {
|
|||
return this.response.getStatusCode();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the HTTP status code (potentially non-standard and not resolvable
|
||||
* through the {@link HttpStatus} enum) as an integer.
|
||||
* @since 5.1.10
|
||||
*/
|
||||
public int getRawStatusCode() {
|
||||
return this.response.getRawStatusCode();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the response headers received from the server.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -55,7 +55,7 @@ public class StatusAssertions {
|
|||
* Assert the response status as an integer.
|
||||
*/
|
||||
public WebTestClient.ResponseSpec isEqualTo(int status) {
|
||||
int actual = this.exchangeResult.getStatus().value();
|
||||
int actual = this.exchangeResult.getRawStatusCode();
|
||||
this.exchangeResult.assertWithDiagnostics(() -> AssertionErrors.assertEquals("Status", status, actual));
|
||||
return this.responseSpec;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -55,6 +55,11 @@ public class StatusAssertionTests {
|
|||
assertions.isEqualTo(408));
|
||||
}
|
||||
|
||||
@Test // gh-23630
|
||||
public void isEqualToWithCustomStatus() {
|
||||
statusAssertions(600).isEqualTo(600);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void reasonEquals() {
|
||||
StatusAssertions assertions = statusAssertions(HttpStatus.CONFLICT);
|
||||
|
|
@ -143,6 +148,10 @@ public class StatusAssertionTests {
|
|||
|
||||
|
||||
private StatusAssertions statusAssertions(HttpStatus status) {
|
||||
return statusAssertions(status.value());
|
||||
}
|
||||
|
||||
private StatusAssertions statusAssertions(int status) {
|
||||
MockClientHttpRequest request = new MockClientHttpRequest(HttpMethod.GET, URI.create("/"));
|
||||
MockClientHttpResponse response = new MockClientHttpResponse(status);
|
||||
|
||||
|
|
|
|||
|
|
@ -268,6 +268,11 @@ public class HttpWebHandlerAdapter extends WebHandlerDecorator implements HttpHa
|
|||
String logPrefix = exchange.getLogPrefix();
|
||||
|
||||
if (isDisconnectedClientError(ex)) {
|
||||
// Request handling error (e.g. remote call), if we manage to set the status..
|
||||
if (response.setStatusCode(HttpStatus.INTERNAL_SERVER_ERROR)) {
|
||||
logger.error(logPrefix + "500 Server Error for " + formatRequest(request), ex);
|
||||
return Mono.empty();
|
||||
}
|
||||
if (lostClientLogger.isTraceEnabled()) {
|
||||
lostClientLogger.trace(logPrefix + "Client went away", ex);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -95,7 +95,6 @@ public class JettyRequestUpgradeStrategy implements RequestUpgradeStrategy, Life
|
|||
synchronized (this.lifecycleMonitor) {
|
||||
ServletContext servletContext = this.servletContext;
|
||||
if (!isRunning() && servletContext != null) {
|
||||
this.running = true;
|
||||
try {
|
||||
this.factory = (this.webSocketPolicy != null ?
|
||||
new WebSocketServerFactory(servletContext, this.webSocketPolicy) :
|
||||
|
|
@ -109,6 +108,7 @@ public class JettyRequestUpgradeStrategy implements RequestUpgradeStrategy, Life
|
|||
return container.getAdapter();
|
||||
});
|
||||
this.factory.start();
|
||||
this.running = true;
|
||||
}
|
||||
catch (Throwable ex) {
|
||||
throw new IllegalStateException("Unable to start WebSocketServerFactory", ex);
|
||||
|
|
@ -121,10 +121,10 @@ public class JettyRequestUpgradeStrategy implements RequestUpgradeStrategy, Life
|
|||
public void stop() {
|
||||
synchronized (this.lifecycleMonitor) {
|
||||
if (isRunning()) {
|
||||
this.running = false;
|
||||
if (this.factory != null) {
|
||||
try {
|
||||
this.factory.stop();
|
||||
this.running = false;
|
||||
}
|
||||
catch (Throwable ex) {
|
||||
throw new IllegalStateException("Failed to stop WebSocketServerFactory", ex);
|
||||
|
|
@ -203,11 +203,11 @@ public class JettyRequestUpgradeStrategy implements RequestUpgradeStrategy, Life
|
|||
}
|
||||
|
||||
private void startLazily(HttpServletRequest request) {
|
||||
if (this.servletContext != null) {
|
||||
if (isRunning()) {
|
||||
return;
|
||||
}
|
||||
synchronized (this.lifecycleMonitor) {
|
||||
if (this.servletContext == null) {
|
||||
if (!isRunning()) {
|
||||
this.servletContext = request.getServletContext();
|
||||
start();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -370,6 +370,9 @@ public class SubProtocolWebSocketHandler
|
|||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Terminating '" + session + "'", ex);
|
||||
}
|
||||
else if (logger.isWarnEnabled()) {
|
||||
logger.debug("Terminating '" + session + "': " + ex.getMessage());
|
||||
}
|
||||
this.stats.incrementLimitExceededCount();
|
||||
clearSession(session, ex.getStatus()); // clear first, session may be unresponsive
|
||||
session.close(ex.getStatus());
|
||||
|
|
|
|||
Loading…
Reference in New Issue